
Recherche avancée
Médias (91)
-
MediaSPIP Simple : futur thème graphique par défaut ?
26 septembre 2013, par
Mis à jour : Octobre 2013
Langue : français
Type : Video
-
avec chosen
13 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
-
sans chosen
13 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
-
config chosen
13 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
-
SPIP - plugins - embed code - Exemple
2 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
-
GetID3 - Bloc informations de fichiers
9 avril 2013, par
Mis à jour : Mai 2013
Langue : français
Type : Image
Autres articles (10)
-
Encoding and processing into web-friendly formats
13 avril 2011, parMediaSPIP automatically converts uploaded files to internet-compatible formats.
Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
All uploaded files are stored online in their original format, so you can (...) -
Contribute to documentation
13 avril 2011Documentation is vital to the development of improved technical capabilities.
MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
To contribute, register to the project users’ mailing (...) -
Other interesting software
13 avril 2011, parWe don’t claim to be the only ones doing what we do ... and especially not to assert claims to be the best either ... What we do, we just try to do it well and getting better ...
The following list represents softwares that tend to be more or less as MediaSPIP or that MediaSPIP tries more or less to do the same, whatever ...
We don’t know them, we didn’t try them, but you can take a peek.
Videopress
Website : http://videopress.com/
License : GNU/GPL v2
Source code : (...)
Sur d’autres sites (3322)
-
Anomalie #4198 : Le W3C ne valide pas les atttribut width et height qui ne sont pas des entiers.
21 mai 2019, par b bOk vu, je pense qu’on doit pouvoir fixer ça dans
_image_tag_changer_taille()
avec le patch suivant :- <span class="CodeRay"><span class="line comment">diff --git a/ecrire/inc/filtres_images_lib_mini.php b/ecrire/inc/filtres_images_lib_mini.php</span>
- <span class="line comment">index d93acc1..37e5c72 100644</span>
- <span class="line head"><span class="head">--- </span><span class="filename">a/ecrire/inc/filtres_images_lib_mini.php</span></span>
- <span class="line head"><span class="head">+++ </span><span class="filename">b/ecrire/inc/filtres_images_lib_mini.php</span></span>
- <span class="change"><span class="change">@@</span> -861,8 +861,8 <span class="change">@@</span></span> <span class="keyword">function</span> <span class="function">_image_tag_changer_taille</span>(<span class="local-variable">$tag</span>, <span class="local-variable">$width</span>, <span class="local-variable">$height</span>, <span class="local-variable">$style</span> = <span class="predefined-constant">false</span>) {
- <span class="comment">// ca accelere le rendu du navigateur</span>
- <span class="comment">// ca permet aux navigateurs de reserver la bonne taille </span>
- <span class="comment">// quand on a desactive l'affichage des images.</span>
- <span class="line delete"><span class="delete">-</span> <span class="local-variable">$tag</span> = inserer_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">width</span><span class="delimiter">'</span></span>, <span class="eyecatcher"><span class="local-variable">$width</span></span>);</span>
- <span class="line delete"><span class="delete">-</span> <span class="local-variable">$tag</span> = inserer_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">height</span><span class="delimiter">'</span></span>, <span class="eyecatcher"><span class="local-variable">$height</span></span>);</span>
- <span class="line insert"><span class="insert">+</span> <span class="local-variable">$tag</span> = inserer_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">width</span><span class="delimiter">'</span></span>, <span class="eyecatcher"><span class="predefined">round</span>(<span class="local-variable">$width</span>)</span>);</span>
- <span class="line insert"><span class="insert">+</span> <span class="local-variable">$tag</span> = inserer_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">height</span><span class="delimiter">'</span></span>, <span class="eyecatcher"><span class="predefined">round</span>(<span class="local-variable">$height</span>)</span>);</span>
- <span class="comment">// attributs deprecies. Transformer en CSS</span>
- <span class="keyword">if</span> (<span class="local-variable">$espace</span> = extraire_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">hspace</span><span class="delimiter">'</span></span>)) {
- </span>
Attendons d’autres avis avant de l’appliquer.
-
PHP FFmpeg video aspect ratio problem [SOLVED]
29 août 2011, par Herr Kaleuni compiled the new version of FFMPEG and the padding commands have been deprecated.
As i try to get familiar with the new -vf pad= commands, i want to ask, how can i
convert a video without changing it's aspect ratio.I've checked numerous solutions from stackoverflow, nothing seemed to work.
Can someone, please post a working PHP example or cmd line. I would be VERY happy.Please note that the videos in question, could be 4:3 and also be 16:9
Let's say, i convert a 16:9 video to 640x480 format. It will need some bars at
the top and at the bottom. That is what i want to do.Thanks
EDIT :
I solved the problem on my own. The FFmpeg documentation is a little bit weird so
you have to experiment yourself a little bit.
The padding formula is like :$pad_horizontal = $target_width + $pad_left + $pad_right;
$pad_vertical = $target_height;
// blah
$command .= " -vf pad=$pad_horizontal:$pad_vertical:". $pad_left .":". $pad_top .":black";Pay special attention at the $pad_vertical part since the paddings there are better
not added so that the padding calculation of ffmpeg is not broken.Here is the full source code to the demo
<?
/***********************************************************************************
get_dimensions()
Takes in a set of video dimensions - original and target - and returns the optimal conversion
dimensions. It will always return the smaller of the original or target dimensions.
For example: original dimensions of 320x240 and target dimensions of 640x480.
The result will be 320x240 because converting to 640x480 would be a waste of disk
space, processing, and bandwidth (assuming these videos are to be downloaded).
@param $original_width: The actual width of the original video file which is to be converted.
@param $original_height: The actual height of the original video file which is to be converted.
@param $target_width: The width of the video file which we will be converting to.
@param $target_height: The height of the video file which we will be converting to.
@param $force_aspect: Boolean value of whether or not to force conversion to the target's
aspect ratio using padding (so the video isn't stretched). If false, the
conversion dimensions will retain the aspect ratio of the original.
Optional parameter. Defaults to true.
@return: An array containing the size and padding information to be used for conversion.
Format:
Array
(
[width] => int
[height] => int
[padtop] => int // top padding (if applicable)
[padbottom] => int // bottom padding (if applicable)
[padleft] => int // left padding (if applicable)
[padright] => int // right padding (if applicable)
)
***********************************************************************************/
function get_dimensions($original_width,$original_height,$target_width,$target_height,$force_aspect)
{
if(!isset($force_aspect))
{
$force_aspect = true;
}
// Array to be returned by this function
$target = array();
$target['padleft'] = 0;
$target['padright'] = 0;
$target['padbottom'] = 0;
$target['padtop'] = 0;
// Target aspect ratio (width / height)
$aspect = $target_width / $target_height;
// Target reciprocal aspect ratio (height / width)
$raspect = $target_height / $target_width;
if($original_width/$original_height !== $aspect)
{
// Aspect ratio is different
if($original_width/$original_height > $aspect)
{
// Width is the greater of the two dimensions relative to the target dimensions
if($original_width < $target_width)
{
// Original video is smaller. Scale down dimensions for conversion
$target_width = $original_width;
$target_height = round($raspect * $target_width);
}
// Calculate height from width
$original_height = round($original_height / $original_width * $target_width);
$original_width = $target_width;
if($force_aspect)
{
// Pad top and bottom
$dif = round(($target_height - $original_height) / 2);
$target['padtop'] = $dif;
$target['padbottom'] = $dif;
}
}
else
{
// Height is the greater of the two dimensions relative to the target dimensions
if($original_height < $target_height)
{
// Original video is smaller. Scale down dimensions for conversion
$target_height = $original_height;
$target_width = round($aspect * $target_height);
}
//Calculate width from height
$original_width = round($original_width / $original_height * $target_height);
$original_height = $target_height;
if($force_aspect)
{
// Pad left and right
$dif = round(($target_width - $original_width) / 2);
$target['padleft'] = $dif;
$target['padright'] = $dif;
}
}
}
else
{
// The aspect ratio is the same
if($original_width !== $target_width)
{
if($original_width < $target_width)
{
// The original video is smaller. Use its resolution for conversion
$target_width = $original_width;
$target_height = $original_height;
}
else
{
// The original video is larger, Use the target dimensions for conversion
$original_width = $target_width;
$original_height = $target_height;
}
}
}
if($force_aspect)
{
// Use the target_ vars because they contain dimensions relative to the target aspect ratio
$target['width'] = $target_width;
$target['height'] = $target_height;
}
else
{
// Use the original_ vars because they contain dimensions relative to the original's aspect ratio
$target['width'] = $original_width;
$target['height'] = $original_height;
}
return $target;
}
function get_vid_dim($file)
{
$command = '/usr/bin/ffmpeg -i ' . escapeshellarg($file) . ' 2>&1';
$dimensions = array();
exec($command,$output,$status);
if (!preg_match('/Stream #(?:[0-9\.]+)(?:.*)\: Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)/',implode("\n",$output),$matches))
{
preg_match('/Could not find codec parameters \(Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)\)/',implode("\n",$output),$matches);
}
if(!empty($matches['width']) && !empty($matches['height']))
{
$dimensions['width'] = $matches['width'];
$dimensions['height'] = $matches['height'];
}
return $dimensions;
}
$command = '/usr/bin/ffmpeg -i ' . $src . ' -ab 96k -b 700k -ar 44100 -f flv -s ' . '640x480 -acodec mp3 '. $video_output_dir . $video_filename . ' 2>&1';
define( 'VIDEO_WIDTH', '640' );
define( 'VIDEO_HEIGHT', '480' );
$src_1 = getcwd() .'/'. 'test_video1.mpeg';
$video_filename1 = 'video1.flv';
$src_2 = getcwd() .'/'. 'test_video2.mp4';
$video_filename2 = 'video2.flv';
$src_3 = getcwd() .'/'. 'test_video3.mp4';
$video_filename3 = 'video3.flv';
convert_video( $src_1, $video_filename1 );
convert_video( $src_2, $video_filename2 );
convert_video( $src_3, $video_filename3 );
function convert_video( $src = '', $video_filename = '' )
{
$video_output_dir = getcwd() .'/';
@unlink ( $video_output_dir . $video_filename );
$original = get_vid_dim($src);
$target = get_dimensions( $original['width'], $original['height'], VIDEO_WIDTH, VIDEO_HEIGHT, TRUE );
echo '<pre>';
print_r( $original );
echo '</pre>';
echo '<pre>';
print_r( $target );
echo '</pre>';
$target_width = $target['width'];
$target_height = $target['height'];
$pad_left = $target['padleft'];
$pad_right = $target['padright'];
$pad_bottom = $target['padbottom'];
$pad_top = $target['padtop'];
$pad_horizontal = $target_width + $pad_left + $pad_right;
$pad_vertical = $target_height; // + $pad_top + $pad_bottom;
$command = '/usr/bin/ffmpeg -i ' . $src;
// $command .= " -s {$target_width}x{$target_height} ";
$command .= " -vf pad=$pad_horizontal:$pad_vertical:". $pad_left .":". $pad_top .":black";
$command .= ' -ab 96k -b 700k -ar 44100';
$command .= ' -f flv ';
$command .= ' -qscale 4';
$command .= ' -ss 30';
$command .= ' -t 5';
$command .= ' -ac 2 -ab 128k -qscale 5 ';
$command .= ' ' . $video_output_dir . $video_filename;
exec( $command, $output, $status );
echo '<pre>';
print_r( $command );
echo '</pre>';
if ( $status == 0 )
{
echo '<br />Convert OK. <br />';
}
else
{
echo '<pre>';
print_r( $output );
echo '</pre>';
}
echo '<br />';
echo '<br />';
}
?>
</height></width></videocodec></height></width></videocodec>Thank you and have fun :)
-
Python cv2 script that scans a giant image to a video. Why do I need pad two extra lines
27 avril 2022, par MahrarenaI wrote a script that scans a giant image to make a video. Normally I just post my scripts straight to my Code Review account, but this script is ugly, needs to be refactored, implements only horizontal scrolling and most importantly I just fixed a bug but I don't completely understand why it works.


Example :


Original image (Google Drive)


Video Output (Google Drive)


As you can see from the video, everything is working properly except the fact that I don't know how it works.


Full working code



import cv2
import numpy as np
import random
import rpack
from fractions import Fraction
from math import prod

def resize_guide(image_size, target_area):
 aspect_ratio = Fraction(*image_size).limit_denominator()
 horizontal = aspect_ratio.numerator
 vertical = aspect_ratio.denominator
 unit_length = (target_area/(horizontal*vertical))**.5
 return (int(horizontal*unit_length), int(vertical*unit_length))

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
FRAME = np.zeros((1080, 1920, 3), dtype=np.uint8)

def new_frame():
 return np.ndarray.copy(FRAME)

def center(image):
 frame = new_frame()
 h, w = image.shape[:2]
 yoff = round((1080-h)/2)
 xoff = round((1920-w)/2)
 frame[yoff:yoff+h, xoff:xoff+w] = image
 return frame

def image_scanning(file, fps=60, pan_increment=64, horizontal_increment=8):
 image = cv2.imread(file)
 height, width = image.shape[:2]
 assert width*height >= 1920*1080
 video_writer = cv2.VideoWriter(file+'.mp4', fourcc, fps, (1920, 1080))
 fit_height = True
 if height < 1080:
 width = width*1080/height
 image = cv2.resize(image, (width, 1080), interpolation = cv2.INTER_AREA)
 aspect_ratio = width / height
 zooming_needed = False
 if 4/9 <= aspect_ratio <= 16/9:
 new_width = round(width*1080/height)
 fit = cv2.resize(image, (new_width, 1080), interpolation = cv2.INTER_AREA)
 zooming_needed = True
 
 elif 16/9 < aspect_ratio <= 32/9:
 new_height = round(height*1920/width)
 fit = cv2.resize(image, (1920, new_height), interpolation = cv2.INTER_AREA)
 fit_height = False
 zooming_needed = True
 
 centered = center(fit)
 for i in range(fps):
 video_writer.write(centered)
 if fit_height:
 xoff = round((1920 - new_width)/2)
 while xoff:
 if xoff - pan_increment >= 0:
 xoff -= pan_increment
 else:
 xoff = 0
 frame = new_frame()
 frame[0:1080, xoff:xoff+new_width] = fit
 video_writer.write(frame)
 else:
 yoff = round((1080 - new_height)/2)
 while yoff:
 if yoff - pan_increment >= 0:
 yoff -= pan_increment
 else:
 yoff = 0
 frame = new_frame()
 frame[yoff:yoff+new_height, 0:1920] = fit
 video_writer.write(frame)
 
 if zooming_needed:
 if fit_height:
 width_1, height_1 = new_width, 1080
 else:
 width_1, height_1 = 1920, new_height
 new_area = width_1 * height_1
 original_area = width * height
 area_diff = original_area - new_area
 unit_diff = area_diff / fps
 for i in range(1, fps+1):
 zoomed = cv2.resize(image, resize_guide((width_1, height_1), new_area+unit_diff*i), interpolation=cv2.INTER_AREA)
 zheight, zwidth = zoomed.shape[:2]
 zheight = min(zheight, 1080)
 zwidth = min(zwidth, 1920)
 frame = new_frame()
 frame[0:zheight, 0:zwidth] = zoomed[0:zheight, 0:zwidth]
 video_writer.write(frame)
 
 if (width - 1920) % horizontal_increment:
 new_width = ((width - 1920) // horizontal_increment + 1) * horizontal_increment + 1920
 frame = np.zeros([height, new_width, 3], dtype=np.uint8)
 frame[0:height, 0:width] = image
 width = new_width
 image = frame
 
 if height % 1080:
 new_height = (height // 1080 + 2) * 1080
 frame = np.zeros([new_height, width, 3], dtype=np.uint8)
 frame[0:height, 0:width] = image
 height = new_height - 1080
 image = frame
 
 y, x = 0, 0
 for y in range(0, height, 1080):
 for x in range(0, width-1920, horizontal_increment):
 frame = image[y:y+1080, x:x+1920]
 video_writer.write(frame)
 x = width - 1920
 frame = image[y:y+1080, x:x+1920]
 for i in range(round(fps/3)):
 video_writer.write(frame)
 cv2.destroyAllWindows()
 video_writer.release()
 del video_writer



I don't know why I need to pad two extra lines instead of one, meaning if I change this :


if height % 1080:
 new_height = (height // 1080 + 2) * 1080
 frame = np.zeros([new_height, width, 3], dtype=np.uint8)
 frame[0:height, 0:width] = image
 height = new_height - 1080
 image = frame



To this :


if height % 1080:
 new_height = (height // 1080 + 1) * 1080
 frame = np.zeros([new_height, width, 3], dtype=np.uint8)
 frame[0:height, 0:width] = image
 height = new_height
 image = frame



The program raises exceptions :


OpenCV: FFMPEG: tag 0x34363268/'h264' is not supported with codec id 27 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
---------------------------------------------------------------------------
error Traceback (most recent call last)
 in <module>
----> 1 image_scanning("D:/collages/91f53ebcea2a.png")

 in image_scanning(file, fps, pan_increment, horizontal_increment, fast_decrement)
 122 x += horizontal_increment
 123 frame = image[y:y+1080, x:x+1920]
--> 124 video_writer.write(frame)
 125 cv2.destroyAllWindows()
 126 video_writer.release()

error: Unknown C++ exception from OpenCV code
</module>


I guess it was caused by indexing error because the last line would not have enough pixels so padding the height of the image to a multiple of 1080 should work.


But that's not the case, I need to pad two lines, why is that ? I really don't understand why it is working.



No, I really wrote all of it, I understand all the principles, the ideas are all mine, but there is one small problem in implementation. I don't know why I need extra pixels in the bottom to make it work, because if I don't pad the height to a multiple of 1080, I can't get the bottom line, the lowest potion of height % 1080 would be lost.


If I tried to get the lowest part, the program will raise exceptions even if I pad the height to a multiple of 1080, I think it is related to indexing but I don't fully understand it, turns out I need to pad the height and add extra pixels, even 1 pixel would work.


I don't know why it raises exceptions and how add extra pixels got rid of the exception, but I understand everything else perfectly clear, after all I wrote it.


There's a bug in my program, I don't know what caused it, and I want you to help me debugging, and that's the entire point of the question !