Difference between revisions of "Ffmpeg"

From IridiaWiki
Jump to navigationJump to search
 
(2 intermediate revisions by 2 users not shown)
Line 19: Line 19:
   
 
* Low quality video, fast result:
 
* Low quality video, fast result:
ffmpeg -f image2 -r 12.0205 -i frame_%05d.bmp -vcodec libx264 -threads 0 -an -vpre fast video_fast.avi
+
avconv -f image2 -r 12.0205 -i frame_%05d.bmp -vcodec libx264 -threads 0 -an -preset ultrafast video_fast.avi
   
 
* High quality (slow, high quality)::
 
* High quality (slow, high quality)::
ffmpeg -f image2 -r 12.0205 -i frame_%05d.bmp -vcodec libx264 -threads 0 -an -vpre hq -b 2000k video2000k.avi
+
ffmpeg -f image2 -r 12.0205 -i frame_%05d.bmp -vcodec libx264 -threads 0 -an -vpre hq -b:v 2000k video2000k.avi
   
 
* High quality, 2 pass (very slow, even higher quality):
 
* High quality, 2 pass (very slow, even higher quality):
Line 39: Line 39:
 
==== How to embed a streaming movie into your supplementary material webpage ====
 
==== How to embed a streaming movie into your supplementary material webpage ====
   
1. Convert Avi (or any video) to Ogg, MP4 and Webm (the latter was not tested, usually the first two work for most of the browsers):
+
1. Convert Avi (or any video) to Ogg, MP4 and Webm:
   
 
ffmpeg -i video.avi -b 1024k video.ogv
 
ffmpeg -i video.avi -b 1024k video.ogv
 
ffmpeg -i video.avi -b 1024k video.mp4
 
ffmpeg -i video.avi -b 1024k video.mp4
ffmpeg -i video.avi -b 1024k video.webm (NOT TESTED)
+
ffmpeg -i video.avi -b 1024k video.webm
   
 
2. Use the following video tag:
 
2. Use the following video tag:
Line 50: Line 50:
 
<source id="mp4_src" src="video.mp4" type="video/mp4"> </source>
 
<source id="mp4_src" src="video.mp4" type="video/mp4"> </source>
 
<source id="ogg_src" src="video.ogv" type="video/ogg"> </source>
 
<source id="ogg_src" src="video.ogv" type="video/ogg"> </source>
<source id="webm_src" src="video.webm" type="video/webm"> </source> (NOT TESTED)
+
<source id="webm_src" src="video.webm" type="video/webm"> </source>
 
your browser does not support the video tag
 
your browser does not support the video tag
 
</video>
 
</video>

Latest revision as of 16:54, 12 December 2013

These are the steps to convert a set of frames (in the format frame_xxxxx.bmp) to a video.

Some options

  • -f image2 : to start from a set of frames (not a video)
  • -i input : the input value
  • -r xx.xxxx : frames per second (that is, fps given by the camera when recording)
  • -b xxxxk : specify the bitrate (higher = better quality, larger file size)
  • -threads 0 : optimal thread usage
  • -an : no audio
  • -vcodec libx264 : uses the best and newest codec (on ubuntu it's in the libx264-106 packet)
  • -vpre xxxx : codec quality (see here )
  • -vf : video filtes for adding filters (to have a list of available filters type 'ffmpeg -filters'). here below useful filters:
    • "transpose=1" : rotates the video (1 rotates by 90 degrees clockwise; 2 rotates by 90 degrees counterclockwise)
  • -ss: starting time (e.g. -ss 00:00:45.0 it cut the first 45 seconds of the video)
  • -t: time (length) of the video (e.g. -t 00:00:15.0 it takes only 15 seconds of the input video)
  • output.ext : output is the name of the file, ext is the extension. Note that selecting mp4 or avi produces different files (is not just a name!)

Examples

  • Low quality video, fast result:
avconv -f image2 -r 12.0205 -i frame_%05d.bmp -vcodec libx264 -threads 0 -an -preset ultrafast video_fast.avi
  • High quality (slow, high quality)::
ffmpeg -f image2 -r 12.0205 -i frame_%05d.bmp -vcodec libx264 -threads 0 -an -vpre hq -b:v 2000k video2000k.avi
  • High quality, 2 pass (very slow, even higher quality):
    • note that there are actually two commands (hence the &&), the first generates the first pass to get the info necessary for the second pass. The command generates 4 files: video_2pass1.avi (the first pass, useless, can be deleted), video_2pass2.avi (the video itself, to keep) and 2 log files (delete them if you need to create another 2pass video)
ffmpeg -f image2 -r 12.0205 -i frame_%05d.bmp -an -vcodec libx264 -threads 0 -vpre fastfirstpass -b 2000k -pass 1 video_2pass1.avi &&
ffmpeg -f image2 -r 12.0205 -i frame_%05d.bmp -an -vcodec libx264 -threads 0 -vpre hq -b 2000k -pass 2 video_2pass2.avi

A note about doing videos from ARGoS2. The size of the images depends on the size of the window, so make sure that the size of the window is the one you like and also that both sizes are divisible by 2, otherwise x264 might complain.

  • Rotate a video, remove audio and convert to avi
ffmpeg -vf "transpose=2" -an -sameq -i 00000.MTS video.avi
  • Cut a video (from second 15 to second 45)
ffmpeg -ss 00:00:15.0 -t 00:00:30.0 -i inputVideo.avi outputVideo.avi

How to embed a streaming movie into your supplementary material webpage

1. Convert Avi (or any video) to Ogg, MP4 and Webm:

ffmpeg -i video.avi -b 1024k video.ogv
ffmpeg -i video.avi -b 1024k video.mp4
ffmpeg -i video.avi -b 1024k video.webm

2. Use the following video tag:

<video controls="controls" height="480" width="320" >
<source id="mp4_src" src="video.mp4" type="video/mp4"> </source>
<source id="ogg_src" src="video.ogv" type="video/ogg"> </source>
<source id="webm_src" src="video.webm" type="video/webm"> </source>
your browser does not support the video tag
</video>

The browser will try, one by one sequentially, the formats listed in the list of sources, and will adopt the first one that works.

Useful links

--Manubrambi 09:05, 10 October 2011 (UTC)