
Recherche avancée
Autres articles (24)
-
Les formats acceptés
28 janvier 2010, parLes commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
ffmpeg -codecs ffmpeg -formats
Les format videos acceptés en entrée
Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
Les formats vidéos de sortie possibles
Dans un premier temps on (...) -
Supporting all media types
13 avril 2011, parUnlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)
-
Ajouter notes et légendes aux images
7 février 2011, parPour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
Modification lors de l’ajout d’un média
Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...)
Sur d’autres sites (4313)
-
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 :)
-
Naive Sorenson Video 1 Encoder
12 septembre 2010, par Multimedia Mike — General(Yes, the word is “naive” — or rather, “naïve” — not “native”. People always try to correct me when I use the word. Indeed, it should actually be written with 2 dots over the ‘i’ but who has a keyboard that can easily do that ?)
At the most primitive level, programming a video encoder is about writing out a sequence of bits that the corresponding video decoder will understand. It’s sort of like creating a program — represented as a stream of opcodes — that will run on a given microprocessor or virtual machine. In fact, reading a video codec bitstream specification will reveal a lot of terminology along the lines of “transmitting information to the decoder” or “signaling the decoder to do xyz.”
Creating a good encoder that will deliver decent quality at a reasonable bitrate is difficult. Creating a naive encoder that produces a technically compliant bitstream, not so much.
When I wrote an FFmpeg encoder for Sorenson Video 1 (SVQ1), the first step was to just create a minimally compliant bitstream. The coarsest encoding mode that SVQ1 allows is to encode the average (mean) of each 16×16 block of samples. So I created an encoder that just encoded the mean of each block. Apple’s QuickTime Player was able to play the resulting video in all of its blocky glory. The result rather reminds me of the Super Nintendo’s mosaic effect.
Level 5 blocks (mean-only 16×16 encoding) :
Level 3 blocks (mean-only 8×8 encoding) :
It’s one thing for your own decoder (in this case, FFmpeg’s own decoder) to be able to decode the data. The big test is whether the official decoder (in this case, Apple QuickTime Player) can decode the file.
Now that’s a good feeling. After establishing that sort of baseline, it’s possible to adapt more and more features of the codec.
-
Why iFrame is a good idea
15 octobre 2009I’ve seen some hilariously uninformed posts about the new Apple iFrame specification. Let me take a minute to explain what it actually is.
First off, as opposed to what the fellow in the Washington Post writes, it’s not really a new format. iFrame is just a way of using formats that we’ve already know and love. As the name suggests, iFrame is just an i-frame only H.264 specification, using AAC audio. An intraframe version of H.264 eh ? Sounds a lot like AVC-Intra, right ? Exactly. And for exactly the same reasons - edit-ability. Whereas AVC-Intra targets the high end, iFrame targets the low end.
Even when used in intraframe mode, H.264 has some huge advantage over the older intraframe codecs like DV or DVCProHD. For example, significantly better entropy coding, adaptive quantization, and potentially variable bitrates. There are many others. Essentially, it’s what happens when you take DV and spend another 10 years working on making it better. That’s why Panasonic’s AVC-Intra cameras can do DVCProHD quality video at half (or less) the bitrate.
Why does iFrame matter for editing ? Anyone who’s tried to edit video from one of the modern H.264 cameras without first transcoding to an intraframe format has experienced the huge CPU demands and sluggish performance. Behind the scenes it’s even worse. Because interframe H.264 can have very long GOPs, displaying any single frame can rely on dozens or even hundreds of other frames. Because of the complexity of H.264, building these frames is very high-cost. And it’s a variable cost. Decoding the first frame in a GOP is relatively trivial, while decoding the middle B-frame can be hugely expensive.
Programs like iMovie mask that from the user in some cases, but at the expensive of high overhead. But, anyone who’s imported AVC-HD video into Final Cut Pro or iMovie knows that there’s a long "importing" step - behind the scenes, the applications are transcoding your video into an intraframe format, like Apple Intermediate or ProRes. It sort of defeats one of the main purposes of a file-based workflow.
You’ve also probably noticed the amount of time it takes to export a video in an interframe format. Anyone who’s edited HDV in Final Cut Pro has experienced this. With DV, doing an "export to quicktime" is simply a matter of Final Cut Pro rewriting all of the data to disk - it’s essentially a file copy. With HDV, Final Cut Pro has to do a complete reencode of the whole timeline, to fit everything into the new GOP structure. Not only is this time consuming, but it’s essentially a generation loss.
iFrame solves these issues by giving you an intraframe codec, with modern efficiency, which can be decoded by any of the H.264 decoders that we already know and love.
Having this as an optional setting on cameras is a huge step forward for folks interested in editing video. Hopefully some of the manufacturers of AVC-HD cameras will adopt this format as well. I’ll gladly trade a little resolution for instant edit-ability.