Showing posts with label ffmpeg. Show all posts
Showing posts with label ffmpeg. Show all posts

08 December, 2013

Useful FFMpeg Filter






FFMpeg offers more than standard encoding/decoding.  It also allows for running a series of filters, both audio and video, that may prove useful in many a situation.

Let's start with an good quality input video;


$ ffmpeg -y -i video.avi -ss 10 -t 40 -qscale 0 -s 360x240 clip01.mpg















Ok, now that we have a video let's look at a few things we may choose to do with it using our newly discovered filters.

Adjusting Video Speed

Suppose you wish to speed the video up, perhaps to expedite review of a surveillance video or perhaps minimizing the exposure to the latest Sandra Bullock film.

We can double the playback speed by specifying a 0.5 playback coefficient;

$ ffmpeg -y -i clip01.mpg -filter:v "setpts=0.5*PTS" clip02.mpg
















You'll notice however from the previous video that while the video element is playing at double speed, the audio hasn't changed.  We can speed up the audio similarly by adding an appropriate audio filter.



$ ffmpeg -y -i clip01.mpg -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" clip03.mpg


















Attempting to speed up faster than 2x will present a hurdle with speeding up the audio filter, which specifies a coefficient range of [0.5, 2.0].  You can get around that by chaining filters;

$ ffmpeg -i clip01.mpg -filter:v "setpts=0.25*PTS" -filter:a "atempo=2.0,atempo=2.0" clip04.mpg






Cropping Video

Suppose we wish to crop the inner middle of the video.  Given the video is 360x240, we need to grab 180x120 inset by 90,60.

$ ffmpeg -y -i clip01.mpg -filter:v "crop=180:120:90:60" clip05.mpg






Processing Edge Detection

Perhaps less useful, but certainly interesting, you can perform edge detection via a Canny Edge Detection algorithm;
$ ffmpeg -y -i clip01.mpg -filter:v "edgedetect=low=0.1:high=0.4" clip06.mpg







Flipping the Video

You can flip the video left-right or top-down;
$ ffmpeg -y -i clip01.mpg -filter:v "hflip" clip07.mpg















$ ffmpeg -y -i clip01.mpg -filter:v "vflip" clip08.mpg











Creating Video Using Source Filter

Occasionally, you want to generate a video using a test source; in other words, without an input video to start with.
$ ffmpeg -f lavfi -i rgbtestsrc -t 30 -pix_fmt yuv420p clip09.mpg















$ ffmpeg -f lavfi -i testsrc=duration=20:size=1280x720:rate=30 -vcodec mpeg2video clip10.mpg

24 October, 2013

Create Counting Video


On a couple of occasions, I've had the need to create a source video for video processing and testing video processing commands.  A common need is to create a counting video by generating a series of frames and stitching them together at a pre-defined frame rate.

Below is a mechanism for doing so;


$ cat createVideo 
#!/bin/bash

ws=/var/tmp/cache
rm -rf $ws
mkdir -p $ws

for i in `seq 300`; do
  N=$(printf %03d $i)
  convert -size 640x480 -background white -fill black -pointsize 120 -gravity center label:$i $ws/frame-$N.jpg
done

ffmpeg -y -r 2/1 -i $ws/frame-%03d.jpg -r 30/1 $ws/video.avi
mplayer $ws/video.avi


Cheers.

11 October, 2013

FFMpeg Cropping Videos

Recently had a need to crop videos using FFMpeg, thought it worth sharing. Starting with the initial video:

$ ffmpeg -i ExSlyoVTX3I.flv -vf crop=160:120:10:10 -sameq /tmp/out.mp4

The result is a cropped video 160x120 with an offset of 10,10 from the upper left-hand corner.


Cheers.

28 March, 2013

Side-by-Side RTSP Stream Capture

Assuming you have two RTSP MPEG-4 streams and wish to generate a side-by-side mosaic. You can do this by using the video filter overlay method; ffmpeg -y -q:v 0 -i rtsp://192.168.128.85/video -q:v 0 -an -vf "[in] pad=2*iw:ih [left]; movie='rtsp\://192.168.128.86/video' [right]; [left][right] overlay=main_w/2:0 [out]" /tmp/sidebyside.avi

Generate Side-by-Side Video Using FFMpeg




Seems I've been doing things the hard way for quite some time.  Occasionally, I've found it useful to generate mosaic'ish videos.  'til now, I've done so by extracting frames from the video into a series of png or jpg files, using ImageMagick to generate the source images, then reassemble the input frames into a video.  Seems an easier way is to extend one of the source video files into the destination dimensions, then overlay the other video over the extended space.

$ ffmpeg -y -i ./Downloads/big_buck_bunny_1080p_surround.avi -s 640x480 -an -sameq /var/tmp/left.avi
$ ffmpeg -y -i /var/tmp/left.avi -vf "pad=1280:480:0:0:black" -sameq /var/tmp/wide.avi
$ ffmpeg -y -i /var/tmp/wide.avi -vf "movie=/var/tmp/left.avi[mv]; [in][mv] overlay=640:0" -sameq /var/tmp/side.avi



Cheers.

16 March, 2013

FFMpeg Piping to Mplayer

Far too often I find myself playing with ffmpeg, trying to transcode a video and evaluating the results. The typical manner of doing this is taking the input file, generating an output file, then playing with the equivalent of mplayer. The need for the temporary output file is primarily motivated because I wasn't aware how to properly pipe the transcoded video to standard output and pipe it to the display utility (e.g. mplayer). I did however recently figure this out, and decided to post for those of you struggling with the same issue. The following example takes in the popular open-source video, transcoding to mpeg format and uses only the first audio chanel, using same video quality but resizes to 720x480 and pipes the output to mplayer.

ffmpeg -i Videos/big_buck_bunny_1080p_surround.avi -f mpeg -ac 1 -sameq -s 720x480 - | mplayer -
Enjoy.

20 December, 2012

Applying Watermark With FFMpeg

Assuming you have a watermark png file 'watermarklogo.png' and a input file 'screenCap.mpg', you can apply a watermark in the upper right hand corner by running the following command:

$ ffmpeg -i screenCap.mpg -vf "movie=watermarklogo.png [watermark]; [in] [watermark] overlay=main_w-overlay_w-10:10 [out]" /var/tmp/foo.mpg
Cheers.

16 November, 2012

Screen Capture with FFMpeg with Audio

Found it useful to capture the Linux desktop using FFMpeg, most useful with audio. Accomplished it using the following command:

$ ffmpeg -y -f alsa -i pulse -f x11grab -r 25 -s 1366x768 -i :0.0 -qscale 1 -s 1024x768  screenCap.mpg
First dimension specified is the resolution of the desktop, the second dimension is the desired resized video dimension. Cheers.

18 August, 2010

New Phone

Well ladies (and gentlmen),
I've moved into the 21st century and replaced my old cell phone with a smart phone. Really wasn't too much of a question when selecting as my criteria was an Android-based phone. Settled in on the Samsung Galaxy and couldn't be much happier. The only issue I've noticed is the wireless doesn't work for 802.11N and haven't had a chance to get it to connect to our wireless router at home.

Anyway....I figured I'd play with converting videos for the phone, the intent of this post. As always, FFMpeg is our tool:


$ ffmpeg -i ./Tosh-001.mpg -s qcif -vcodec h263 -ac 1 -ar 8000 -r 25 -ab 12.2k -y outputfile.3gp


Mount the phone, copy in the output file, unmount and play through the gallery. Easy-peezy.

04 January, 2010

Mplayer + FFMpeg + /dev/video

I've recently published posts for capturing video from a QuickCam Express using FFMpeg. I also posted how to play live video with MPlayer. That covers storing video or playing live video. Playing or storing video with a camera source seems mutually exclusive.

That said, what if you want to store and play live video simultaneously?

Playing live video while storing the incoming video is do-able using these tools and a first-in-first-out (FIFO).

The trick is to recognize that FFMpeg can support converting a single input file into multiple output files. For instance, you can convert a source video file into two output files as follows:


$ ffmpeg -i source.avi /tmp/output.avi /tmp/output.mpg


This command will take the source file source.avi and generate twin output files /tmp/output.avi and /tmp/output.mpg converting them simultaneously.

Similarly, you can use a video device /dev/video rather than an input video file and generate twin output files by using a similar command:


$ ffmpeg -r 15 -s 352x288 -f video4linux -i /dev/video0 /tmp/output.avi /tmp/output.mpg


While cool and closer, attempting to play the file will eventually reach the file end and terminate. Instead, by using a FIFO as an output file and using this FIFO as the input to Mplayer you've accomplished your goal.


$ mkfifo /tmp/vidPipe
$ ffmpeg -y -f video4linux -r 15 -s 352x288 -i /dev/video0 -f avi -vcodec msmpeg4 /tmp/vidPipe /tmp/output.avi


In another terminal window play the fifo with Mplayer using the following command:

$ mplayer /tmp/vidPipe


I love it when a plan comes together.

10 July, 2009

Convert Color Video To GrayScale

I've recently found it useful to convert color video into grayscale video. I found the following to be effective in doing so.


$ ffmpeg -y -i /tmp/video.avi -s 640x480 -pix_fmt gray -vcodec rawvideo /var/tmp/video.avi


I haven't however found a means to re-encode the grayscale into an alternative codec (sigh).

30 June, 2009

Power of the Pipe

For quite some time I've it's been a mystery to me why many Unix-flavored toolsuites offer a command line interface supporting inputting or outputting to stdin/stdout respectively.

For example, ffmpeg can utilize stdin in leu of a input file by specifying -; similarly it can utilize stdout in leu of an output file using the same - specifier.

I've recently become aware of how useful this option can be. In particular it allows you to bypass creating unnecessary temporary files.

For example, using ffmpeg you can redirect the output to stdout and into mplayer to review the impacts of varying codecs and video quality specifiers.


$ ffmpeg -i /var/tmp/foo.mpg -f asf - | mplayer -cache 8192 -


Similarly, you can make use of the similar feature with ImageMagick like so:

$ convert Lenna.jpg - | display -


In each case, redirecting to stdout and piping to a consuming display utility eliminates the need for creating a temporary file.

26 June, 2009

Drawing Primitives with ImageMagick

ImageMagick offers far more than simple image conversion utilities. It also extends to you the ability to create new images using drawing primitives. I've recently found this useful in creating artificially created videos use to test image processing and tracking techniques. The following script supports creating a series of circular targets in a newly created frame. By creating a series of frames, stitching them together with FFMpeg and you can create a video of moving targets of know positions. Useful for testing algorithms.

Later.


#!/usr/bin/tclsh

proc createFrame { fileName imageL targets } {
array set image $imageL
set tL ""

foreach e $targets {
switch [lindex $e 0] {
circle
{
set x0 [lindex [split [lindex $e 1] ,] 0]
set y0 [lindex [split [lindex $e 1] ,] 1]
set r [lindex $e 2]
set x1 [expr $x0 + $r]
set y1 $y0
set tL [concat $tL "-fill red -draw 'circle $x0,$y0 $x1,$y1'"]
}
}
}

set cmd "/usr/bin/convert -size $image(width)x$image(height) xc:white $tL $fileName"
puts $cmd
exec bash -c $cmd
}

#---main---
set image(width) 640
set image(height) 480
set fileName /tmp/frame00000001.pnm
lappend targets [list circle 320,240 10]
lappend targets [list circle 100,100 10]
createFrame $fileName [array get image] $targets

12 June, 2009

Screen Capture with FFmpeg

Sometimes it's useful to capture the display output as a means of archiving a procedure or to demonstrate a user experience. The following command will capture the display region 1680x1050 at 30fps for 90 seconds and shrink it to a 640x480 video at near raw resolution (fixed quantizer scale of 1).

The important thing is to confirm your ffmpeg format supports x11grab, otherwise you'll get the following error:

Unknown input or output format: x11grab



ffmpeg -y -f x11grab -r 30 -s 1680x1050 -i :0.0 -t 90 -qscale 1 -s 640x480 out.mpg


As you can imagine, capturing 30fps adds significant resource loading, if you so choose you can down-sample the frame rate but you may need to use an alternative encoder for non-compliant frame rates of some codecs.

The MJPEG encoder seems to work well enough for slow frame rates, like 1 Hz.


ffmpeg -y -f x11grab -r 1/1 -s 1680x1050 -i :0.0 -t 90 -qscale 1 -s 640x480 -vcodec mjpeg out.avi

20 May, 2009

FFmpeg Ninja Moves - part 4

Maintaining video quality during conversion can be a primary concern when converting to an alternative format while maintaining the necessary video quality.

By default, the output codec will utilize a default set of encoder quality specifiers. You can override these values by specifying -sameq, -qmin, -qmax or -qscale factors.

The -sameq specifier tells FFMpeg to maintain the same video quality as the source video file.

$ ffmpeg -i /tmp/video.avi -sameq /tmp/video.mpg


The qmin and qmax specifiers constrain the q-factors to a user-specified range. This applies to variable bit rate output streams. Specifying a narrow range will ensure consistent quality. Specifying a highly constrained, high quality factor will give you a good quality output video.

$ ffmpeg -i /tmp/video.avi -qmin 1 -qmax 1 /tmp/video.mpg


Constraining the scale factor to a single numeric can be alternatively done by specifying -qscale as follows.

$ ffmpeg -i /tmp/video.avi -qscale 1 /tmp/video.mpg


Note, the lower the value the higher the video quality.

18 May, 2009

FFmpeg Ninja Moves - part 4

Continuing on our FFMpeg trek, this post will focus on manipulating frame sizes; specifically, cropping, resizing and padding.

Cropping
Selectively cropping out a portion of each frame in the video allows you to focus on particular regions. The input video has 720x480 dimensions, suppose you were only interested in the inner 360x240 frame contents. You can crop the video frames by specifying the left, right, top and bottom crop bands (specified in pixels). As an example, the following command crops the innter 360x240 frame contents.

$ ffmpeg -i /tmp/video.avi -croptop 120 -cropbottom 120 -cropleft 180 -cropright 180 /var/tmp/video.avi

Resizing
If instead of cropping the image you wish to resize it, you can specify a desired frame size WxH. For example, if you wish the output video file dimensions to consist of 360x240 you can specify the -s size specifier as follows:

$ ffmpeg -i /tmp/video.avi -s 360x240 /var/tmp/video.avi

Unlike cropping, all frame contents are retained but the lesser dimensions gives the effect of dropping every other pixel contents.

Padding
If you require expanding the video dimensions you can pad the left, right, top and bottom to attain the desired frame dimensions. To convert the 720x480 video dimensions to 800x600 you can specify

ffmpeg -i /tmp/video.avi -padtop 40 -padbottom 40 -padleft 60 -padright 60 -padcolor FFFFFF /var/tmp/video.avi

I specified a white pad color to allow you to see the pad effects. A keen reader will notice that in order to preserve the aspect ratio the output video is actually 840 x 560.

16 May, 2009

FFmpeg Ninja Moves - part 3

Continuing on, this post will focus on time with respect to video files.

Altering Video Frame Rate
Let's start by playing with the frame rate. Given a 30 frames/sec input file, we can specify a desired alternative frame rate for the output file by specifying the rate specifier.

We can downsample to 5 frames per second by issuing the following command:

$ ffmpeg -i /tmp/video.avi -r 5/1 /var/tmp/video.avi


$ ffmpeg -i /var/tmp/video.avi
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Input #0, avi, from '/var/tmp/video.avi':
Duration: 00:00:57.4, start: 0.000000, bitrate: 297 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x480, 5.00 fps(r)
Stream #0.1: Audio: mp2, 48000 Hz, stereo, 64 kb/s
Must supply at least one output file




Similarly, we can upsample to 60 frames per second by issuing the following:

$ ffmpeg -y -i /tmp/video.avi -r 60/1 /var/tmp/video.avi
$ ffmpeg -i /var/tmp/video.avi
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Input #0, avi, from '/var/tmp/video.avi':
Duration: 00:00:57.3, start: 0.000000, bitrate: 889 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x480, 60.00 fps(r)
Stream #0.1: Audio: mp2, 48000 Hz, stereo, 64 kb/s
Must supply at least one output file


Time-Specified Clip
A common practice concerns extracting a video clip from a video stream. Perhaps you're only interested in the first 2 minutes of the video, perhaps the middle 30 seconds is of interest. In either case, the ability to grab a portion of the video is always valuable. The -ss specifier allows seeking into the input file, the -t duration specifier defines how long a clip you wish; both use seconds as the units.

For example, to seek into the source video 32 seconds and extract the next 2.5 seconds you can specify:

$ ffmpeg -y -i /tmp/video.avi -ss 32 -t 2.5 /var/tmp/video.avi
Repeat
Introducing a repeated video sequence can be a necessary feature to author videos. FFMpeg does not directly support this feature, instead the ability to incorporate multiple video streams allows simultaneous concurrent streams rather than sequential videos. The multiple, simultaneous video streams can be incorporated much like DVD contents allow multiple view angles. FFMpeg however does indirectly allow concatenating videos to give a repeat or sequence of video clips. The trick is to convert your source video files into a concat-able format such as MPEG and simply join them together using the cat utility. For example:


$ ffmpeg -i /tmp/video.avi -sameq /tmp/video.mpg
$ cat /tmp/video.mpg /tmp/video.mpg > /tmp/biggie.mpg

The output file now has 2 iterations of /tmp/video.mpg.

14 May, 2009

FFmpeg Ninja Moves - part 2

In part 1 we showed how to access the help info by specifying the -h command line argument. Paying special attention to the first line shows both the input and output files allow options:


.
.
usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...
Hyper fast Audio and Video encoder
.
.


Note that both the input and output files allow for options. Many typical uses of FFMpeg will not require input options as they can often be implicitly determined from the input file (e.g. frame rate, codec, . . .).

Let's start with 'The Duke', as any warm-blooded American can't help but love this 'one eyed fat-man'.


FFMpeg shows the encoder used is mpeg4, video dimensions of 720x480 and a 30 fps frame rate with mp2 audio. This information is available by specifying an input file with no output file options as follows:

$ ffmpeg -i /tmp/video.avi
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Seems that stream 0 comes from film source: 30000.00 (30000/1) -> 29.97 (30000/1001)
Input #0, avi, from '/tmp/video.avi':
Duration: 00:00:57.3, start: 0.000000, bitrate: 7104 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x480, 29.97 fps(r)
Stream #0.1: Audio: mp2, 48000 Hz, stereo, 64 kb/s
Must supply at least one output file


We can re-encode this video into an alternative codec such as MS-MPEG4. First, since each FFMpeg installation relies on the available codecs we need to examine what video encoders are available to make our selection:

$ ffmpeg -formats | egrep "Codecs:|EV"
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Codecs:
DEV D asv1
DEV D asv2
DEV D dvvideo
DEV D ffv1
DEVSD ffvhuff
DEVSD flv
DEV D h261
DEVSDT h263
EV h263p
DEVSD huffyuv
EV jpegls
EV ljpeg
DEV D mjpeg
DEVSDT mpeg1video
DEVSDT mpeg2video
DEVSDT mpeg4
DEVSD msmpeg4
DEVSD msmpeg4v1
DEVSD msmpeg4v2

DEV pam
DEV pbm
DEV pgm
DEV pgmyuv
DEV png
DEV ppm
DEV rawvideo
DEV D rv10
DEV D rv20
DEV snow
DEV D svq1
DEVSD wmv1
DEVSD wmv2
DEV D zlib


This installation supports MS-MPEG4 versions 1 & 2. We can therefore re-encode the source video into MS-MPEG4 format, a commonly available codec for Windows (boo, hiss) platforms. You can convert the source video into MS-MPEG4v2 format as follows:

$ ffmpeg -i /tmp/video.avi -vcodec msmpeg4v2 -sameq ~/video.avi

$ ffmpeg -i ~/video.avi
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Input #0, avi, from '/home/lipeltgm/video.avi':
Duration: 00:00:57.3, start: 0.000000, bitrate: 6663 kb/s
Stream #0.0: Video: msmpeg4v2, yuv420p, 720x480, 29.97 fps(r)
Stream #0.1: Audio: mp2, 48000 Hz, stereo, 64 kb/s
Must supply at least one output file


By specifying the -vcodec argument, you can force the output file to use the codec you specify. Specifying -vcodec msmpeg4v2 therefore forces the output file to be encoded using MS-MPEG4v2 codec. You should notice that the resultant image is now encoded using msmpeg4v2. You may also notice that the conversion command line specified a -sameq argument which we haven't discussed. Simply put, you may find this argument useful if you wish to retain the source videos quality. The -sameq argument simply applies the 'same quality' as the input video. By not constraining the video quality of the output video the standard defaults will apply which may give you a smaller file size, but a video stream of lesser quality.

In typical use, you'll employ an iterative process of processing an input file, examine the output file results, and re-process the input file until you finally arrive at the desired results. That said, in many cases you'll respecify the same command line, tailoring the options as you see fit. This brings us to the point, FFMpeg will prompt the user for over-write permissions if you specify an output file that already exists. You're prompted for a y/n response when the output file is detected. You can respond 'y' to continue, or if you'd rather not be bothered with the prompts you can specify the -y option which will force overwrite of any existing output file without user prompt.
For example, without specifying the -y argument:


$ ffmpeg -i /tmp/video.avi -vcodec msmpeg4v2 -sameq /var/tmp/video.avi
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Seems that stream 0 comes from film source: 30000.00 (30000/1) -> 29.97 (30000/1001)
Input #0, avi, from '/tmp/video.avi':
Duration: 00:00:57.3, start: 0.000000, bitrate: 7104 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x480, 29.97 fps(r)
Stream #0.1: Audio: mp2, 48000 Hz, stereo, 64 kb/s
File '/var/tmp/video.avi' already exists. Overwrite ? [y/N]

Alternatively, you can force overwrite by:

$ ffmpeg -y -i /tmp/video.avi -vcodec msmpeg4v2 -sameq /var/tmp/video.avi

12 May, 2009

FFmpeg Ninja Moves - part 1

Ffmpeg is the Swiss army knife of video converters. Giving a plethora of video and audio conversion options this utility is the framework for arming you with the tools to do significant audio/video processing. This series of posts will explore many of the commonly used features of the utility.

Let's start with the basics; accessing the license and help manuals are as good a place to start as any.


$ ffmpeg -L
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


Accessing the help info shows the extent of options FFmpeg offers.


$ ffmpeg -h
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...
Hyper fast Audio and Video encoder

Main options:
-L show license
-h show help
-version show version
-formats show available formats, codecs, protocols, ...
-f fmt force format
-img img_fmt force image format
-i filename input file name
-y overwrite output files
-t duration set the recording time
-fs limit_size set the limit file size
-ss time_off set the start time offset
-itsoffset time_off set the input ts offset
-title string set the title
-timestamp time set the timestamp
-author string set the author
-copyright string set the copyright
-comment string set the comment
-v verbose control amount of logging
-target type specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...)
-dframes number set the number of data frames to record
-scodec codec force subtitle codec ('copy' to copy stream)
-newsubtitle add a new subtitle stream to the current output stream
-slang code set the ISO 639 language code (3 letters) of the current subtitle stream

Video options:
-b bitrate set video bitrate (in kbit/s)
-vframes number set the number of video frames to record
-r rate set frame rate (Hz value, fraction or abbreviation)
-s size set frame size (WxH or abbreviation)
-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-croptop size set top crop band size (in pixels)
-cropbottom size set bottom crop band size (in pixels)
-cropleft size set left crop band size (in pixels)
-cropright size set right crop band size (in pixels)
-padtop size set top pad band size (in pixels)
-padbottom size set bottom pad band size (in pixels)
-padleft size set left pad band size (in pixels)
-padright size set right pad band size (in pixels)
-padcolor color set color of pad bands (Hex 000000 thru FFFFFF)
-vn disable video
-bt tolerance set video bitrate tolerance (in kbit/s)
-maxrate bitrate set max video bitrate tolerance (in kbit/s)
-minrate bitrate set min video bitrate tolerance (in kbit/s)
-bufsize size set ratecontrol buffer size (in kByte)
-vcodec codec force video codec ('copy' to copy stream)
-sameq use same video quality as source (implies VBR)
-pass n select the pass number (1 or 2)
-passlogfile file select two pass log file name
-newvideo add a new video stream to the current output stream

Advanced Video options:
-pix_fmt format set pixel format
-g gop_size set the group of picture size
-intra use only intra frames
-vdt n discard threshold
-qscale q use fixed video quantiser scale (VBR)
-qmin q min video quantiser scale (VBR)
-qmax q max video quantiser scale (VBR)
-lmin lambda min video lagrange factor (VBR)
-lmax lambda max video lagrange factor (VBR)
-mblmin q min macroblock quantiser scale (VBR)
-mblmax q max macroblock quantiser scale (VBR)
-qdiff q max difference between the quantiser scale (VBR)
-qblur blur video quantiser scale blur (VBR)
-qsquish squish how to keep quantiser between qmin and qmax (0 = clip, 1 = use differentiable function)
-qcomp compression video quantiser scale compression (VBR)
-rc_init_cplx complexity initial complexity for 1-pass encoding
-b_qfactor factor qp factor between p and b frames
-i_qfactor factor qp factor between p and i frames
-b_qoffset offset qp offset between p and b frames
-i_qoffset offset qp offset between p and i frames
-ibias bias intra quant bias
-pbias bias inter quant bias
-rc_eq equation set rate control equation
-rc_override override rate control override for specific intervals
-me method set motion estimation method
-me_threshold motion estimaton threshold
-mb_threshold macroblock threshold
-bf frames use 'frames' B frames
-preme pre motion estimation
-bug param workaround not auto detected encoder bugs
-strict strictness how strictly to follow the standards
-deinterlace deinterlace pictures
-psnr calculate PSNR of compressed frames
-vstats dump video coding statistics to file
-vhook module insert video processing module
-intra_matrix matrix specify intra matrix coeffs
-inter_matrix matrix specify inter matrix coeffs
-top top=1/bottom=0/auto=-1 field first
-sc_threshold threshold scene change threshold
-me_range range limit motion vectors range (1023 for DivX player)
-dc precision intra_dc_precision
-mepc factor (1.0 = 256) motion estimation bitrate penalty compensation
-vtag fourcc/tag force video tag/fourcc
-skip_threshold threshold frame skip threshold
-skip_factor factor frame skip factor
-skip_exp exponent frame skip exponent
-genpts generate pts
-qphist show QP histogram
-vbsf bitstream filter

Audio options:
-aframes number set the number of audio frames to record
-ab bitrate set audio bitrate (in kbit/s)
-aq quality set audio quality (codec-specific)
-ar rate set audio sampling rate (in Hz)
-ac channels set number of audio channels
-an disable audio
-acodec codec force audio codec ('copy' to copy stream)
-vol volume change audio volume (256=normal)
-newaudio add a new audio stream to the current output stream
-alang code set the ISO 639 language code (3 letters) of the current audio stream

Advanced Audio options:
-atag fourcc/tag force audio tag/fourcc
-absf bitstream filter

Subtitle options:
-scodec codec force subtitle codec ('copy' to copy stream)
-newsubtitle add a new subtitle stream to the current output stream
-slang code set the ISO 639 language code (3 letters) of the current subtitle stream

Audio/Video grab options:
-vd device set video grab device
-vc channel set video grab channel (DV1394 only)
-tvstd standard set television standard (NTSC, PAL (SECAM))
-ad device set audio device
-grab format request grabbing using
-gd device set grab device

Advanced options:
-map file:stream[:syncfile:syncstream] set input stream mapping
-map_meta_data outfile:infile set meta data information of outfile from infile
-benchmark add timings for benchmarking
-dump dump each input packet
-hex when dumping packets, also dump the payload
-re read input at native frame rate
-loop_input loop (current only works with images)
-loop_output number of times to loop output in formats that support looping (0 loops forever)
-threads count thread count
-vsync video sync method
-async audio sync method
-vglobal video global header storage type
-copyts copy timestamps
-shortest finish encoding within shortest input
-dts_delta_threshold timestamp discontinuity delta threshold
-ps size set packet size in bits
-error rate error rate
-muxrate rate set mux rate
-packetsize size set packet size
-muxdelay seconds set the maximum demux-decode delay
-muxpreload seconds set the initial demux-decode delay
AVCodecContext AVOptions:
-bit_rate E.VA.
-bit_rate_tolerance E.V..
-flags EDVA.
-mv4 E.V.. use four motion vector by macroblock (mpeg4)
-obmc E.V.. use overlapped block motion compensation (h263+)
-qpel E.V.. use 1/4 pel motion compensation
-loop E.V.. use loop filter
-gmc E.V.. use gmc
-mv0 E.V.. always try a mb with mv=<0,0>
-part E.V.. use data partitioning
-gray EDV.. only decode/encode grayscale
-psnr E.V.. error[?] variables will be set during encoding
-naq E.V.. normalize adaptive quantization
-ildct E.V.. use interlaced dct
-low_delay .DV.. force low delay
-alt E.V.. enable alternate scantable (mpeg2/mpeg4)
-trell E.V.. use trellis quantization
-bitexact EDVAS use only bitexact stuff (except (i)dct)
-aic E.V.. h263 advanced intra coding / mpeg4 ac prediction
-umv E.V.. use unlimited motion vectors
-cbp E.V.. use rate distortion optimization for cbp
-qprd E.V.. use rate distortion optimization for qp selection
-aiv E.V.. h263 alternative inter vlc
-slice E.V..
-ilme E.V.. interlaced motion estimation
-scan_offset E.V.. will reserve space for svcd scan offset user data
-cgop E.V.. closed gop
-fast E.V.. allow non spec compliant speedup tricks
-sgop E.V.. strictly enforce gop size
-noout E.V.. skip bitstream encoding
-local_header E.V.. place global headers at every keyframe instead of in extradata
-me_method E.V..
-gop_size E.V..
-cutoff E..A. set cutoff bandwidth
-frame_size E..A.
-qcompress E.V..
-qblur E.V..
-qmin E.V..
-qmax E.V..
-max_qdiff E.V..
-max_b_frames E.V..
-b_quant_factor E.V..
-rc_strategy E.V..
-b_strategy E.V..
-hurry_up .DV..
-bugs .DV..
-autodetect .DV..
-old_msmpeg4 .DV..
-xvid_ilace .DV..
-ump4 .DV..
-no_padding .DV..
-amv .DV..
-ac_vlc .DV..
-qpel_chroma .DV..
-std_qpel .DV..
-qpel_chroma2 .DV..
-direct_blocksize .DV..
-edge .DV..
-hpel_chroma .DV..
-dc_clip .DV..
-ms .DV..
-lelim E.V.. single coefficient elimination threshold for luminance (negative values also consider dc coefficient)
-celim E.V.. single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)
-strict E.V..
-very E.V..
-strict E.V..
-normal E.V..
-inofficial E.V..
-experimental E.V..
-b_quant_offset E.V..
-er .DV..
-careful .DV..
-compliant .DV..
-aggressive .DV..
-very_aggressive .DV..
-mpeg_quant E.V..
-rc_qsquish E.V..
-rc_qmod_amp E.V..
-rc_qmod_freq E.V..
-rc_eq E.V..
-rc_max_rate E.V..
-rc_min_rate E.V..
-rc_buffer_size E.V..
-rc_buf_aggressivity E.V..
-i_quant_factor E.V..
-i_quant_offset E.V..
-rc_initial_cplx E.V..
-dct E.V..
-auto E.V..
-fastint E.V..
-int E.V..
-mmx E.V..
-mlib E.V..
-altivec E.V..
-faan E.V..
-lumi_mask E.V.. lumimasking
-tcplx_mask E.V.. temporal complexity masking
-scplx_mask E.V.. spatial complexity masking
-p_mask E.V.. inter masking
-dark_mask E.V.. darkness masking
-idct EDV..
-auto EDV..
-int EDV..
-simple EDV..
-simplemmx EDV..
-libmpeg2mmx EDV..
-ps2 EDV..
-mlib EDV..
-arm EDV..
-altivec EDV..
-sh4 EDV..
-simplearm EDV..
-h264 EDV..
-vp3 EDV..
-ipp EDV..
-xvidmmx EDV..
-ec .DV..
-guess_mvs .DV..
-deblock .DV..
-pred E.V.. prediction method
-left E.V..
-plane E.V..
-median E.V..
-aspect E.V..
-debug EDVAS print specific debug info
-pict .DV..
-rc E.V..
-bitstream .DV..
-mb_type .DV..
-qp .DV..
-mv .DV..
-dct_coeff .DV..
-skip .DV..
-startcode .DV..
-pts .DV..
-er .DV..
-mmco .DV..
-bugs .DV..
-vis_qp .DV..
-vis_mb_type .DV..
-vismv .DV.. visualize motion vectors
-pf .DV..
-bf .DV..
-bb .DV..
-mb_qmin E.V..
-mb_qmax E.V..
-cmp E.V.. full pel me compare function
-subcmp E.V.. sub pel me compare function
-mbcmp E.V.. macroblock compare function
-ildctcmp E.V.. interlaced dct compare function
-dia_size E.V..
-last_pred E.V..
-preme E.V..
-precmp E.V.. pre motion estimation compare function
-sad E.V..
-sse E.V..
-satd E.V..
-dct E.V..
-psnr E.V..
-bit E.V..
-rd E.V..
-zero E.V..
-vsad E.V..
-vsse E.V..
-nsse E.V..
-w53 E.V..
-w97 E.V..
-dctmax E.V..
-chroma E.V..
-pre_dia_size E.V..
-subq E.V.. sub pel motion estimation quality
-me_range E.V..
-ibias E.V..
-pbias E.V..
-coder E.V..
-vlc E.V.. variable length coder / huffman coder
-ac E.V.. arithmetic coder
-context E.V.. context model
-mbd E.V..
-simple E.V..
-bits E.V..
-rd E.V..
-sc_threshold E.V..
-lmin E.V.. min lagrange factor
-lmax E.V.. max lagrange factor
-nr E.V.. noise reduction
-rc_init_occupancy E.V..
-inter_threshold E.V..
-flags2 EDVA.
-antialias .DV..
-auto .DV..
-fastint .DV..
-int .DV..
-float .DV..
-qns E.V.. quantizer noise shaping
-thread_count EDV..
-dc E.V..
-nssew E.V.. nsse weight
-skip_top .DV..
-skip_bottom .DV..
-profile E.VA.
-unknown E.VA.
-level E.VA.
-unknown E.VA.
-lowres .DV..
-frame_skip_threshold E.V..
-frame_skip_factor E.V..
-frame_skip_exp E.V..
-skipcmp E.V.. frame skip compare function
-border_mask E.V..
-mb_lmin E.V..
-mb_lmax E.V..
-me_penalty_compensation E.V..
-bidir_refine E.V..
-brd_scale E.V..
-crf E.V..
-cqp E.V..
-keyint_min E.V..
-refs E.V..
-chromaoffset E.V..
-bframebias E.V..
-trellis E.VA.
-directpred E.V..
-bpyramid E.V..
-wpred E.V..
-mixed_refs E.V..
-8x8dct E.V..
-fastpskip E.V..
-aud E.V..
-brdo E.V..
-complexityblur E.V..
-deblockalpha E.V..
-deblockbeta E.V..
-partitions E.V..
-parti4x4 E.V..
-parti8x8 E.V..
-partp4x4 E.V..
-partp8x8 E.V..
-partb8x8 E.V..
-sc_factor E.V..
-mv0_threshold E.V..
-ivlc E.V.. intra vlc table
-b_sensitivity E.V..
-compression_level E.VA.
-use_lpc E..A.
-lpc_coeff_precision E..A.
-min_prediction_order E..A.
-max_prediction_order E..A.
-prediction_order_method E..A.
-min_partition_order E..A.
-max_partition_order E..A.


You can query the version by issuing the following command.

$ ffmpeg -version
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
ffmpeg SVN-rUNKNOWN
libavutil 3211264
libavcodec 3345152
libavformat 3278080


The next command is particularly useful, it provides an exhaustive list of codecs avalable, both video and audio. The fields preceeding each codec have the following meanings:
  • 'D' Decoding available
  • 'E' Encoding available
  • 'V/A/S' Video/audio/subtitle codec
  • 'S' Codec supports slices
  • 'D' Codec supports direct rendering
  • 'T' Codec can handle input truncated at random locations, not just frame boundaries

$ ffmpeg -formats
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
File formats:
E 3g2 3gp2 format
E 3gp 3gp format
D 4xm 4X Technologies format
D RoQ Id RoQ format
D aac ADTS AAC
DE ac3 raw ac3
E adts ADTS AAC
DE aiff Audio IFF
DE alaw pcm A law format
DE amr 3gpp amr file format
DE asf asf format
E asf_stream asf format
DE au SUN AU Format
DE audio_device audio grab and output
DE avi avi format
D avs avs format
E crc crc testing format
D daud D-Cinema audio format
D dc1394 dc1394 A/V grab
D dts raw dts
DE dv DV video format
D dv1394 dv1394 A/V grab
E dvd MPEG2 PS format (DVD VOB)
D ea Electronic Arts Multimedia Format
DE ffm ffm format
D film_cpk Sega FILM/CPK format
DE flac raw flac
D flic FLI/FLC/FLX animation format
DE flv flv format
E framecrc framecrc testing format
DE gif GIF Animation
DE gxf GXF format
DE h261 raw h261
DE h263 raw h263
DE h264 raw H264 video format
D idcin Id CIN format
DE image image sequence
DE image2 image2 sequence
DE image2pipe piped image2 sequence
DE imagepipe piped image sequence
D ingenient Ingenient MJPEG
D ipmovie Interplay MVE format
DE m4v raw MPEG4 video format
D matroska Matroska file format
DE mjpeg MJPEG video
D mm American Laser Games MM format
DE mmf mmf format
E mov mov format
D mov,mp4,m4a,3gp,3g2,mj2 QuickTime/MPEG4/Motion JPEG 2000 format
E mp2 MPEG audio layer 2
DE mp3 MPEG audio layer 3
E mp4 mp4 format
DE mpeg MPEG1 System format
E mpeg1video MPEG video
E mpeg2video MPEG2 video
DE mpegts MPEG2 transport stream format
D mpegvideo MPEG video
E mpjpeg Mime multipart JPEG format
DE mulaw pcm mu law format
D mxf MXF format
D nsv NullSoft Video format
E null null video format
DE nut nut format
D nuv NuppelVideo format
DE ogg Ogg Vorbis
E psp psp mp4 format
D psxstr Sony Playstation STR format
DE rawvideo raw video format
D redir Redirector format
DE rm rm format
E rtp RTP output format
D rtsp RTSP input format
DE s16be pcm signed 16 bit big endian format
DE s16le pcm signed 16 bit little endian format
DE s8 pcm signed 8 bit format
D sdp SDP
D shn raw shorten
D smk Smacker Video
D sol Sierra SOL Format
E svcd MPEG2 PS format (VOB)
DE swf Flash format
D tta true-audio
DE u16be pcm unsigned 16 bit big endian format
DE u16le pcm unsigned 16 bit little endian format
DE u8 pcm unsigned 8 bit format
E vcd MPEG1 System format (VCD)
D video4linux video grab
D video4linux2 video grab
D vmd Sierra VMD format
E vob MPEG2 PS format (VOB)
DE voc Creative Voice File format
DE wav wav format
D wc3movie Wing Commander III movie format
D wsaud Westwood Studios audio format
D wsvqa Westwood Studios VQA format
DE yuv4mpegpipe YUV4MPEG pipe format

Image formats (filename extensions, if any, follow):
DE gif gif

Codecs:
D V 4xm
D V D 8bps
D V D aasc
DEA ac3
DEA adpcm_4xm
DEA adpcm_adx
DEA adpcm_ct
DEA adpcm_ea
DEA adpcm_ima_dk3
DEA adpcm_ima_dk4
DEA adpcm_ima_qt
DEA adpcm_ima_smjpeg
DEA adpcm_ima_wav
DEA adpcm_ima_ws
DEA adpcm_ms
DEA adpcm_sbpro_2
DEA adpcm_sbpro_3
DEA adpcm_sbpro_4
DEA adpcm_swf
DEA adpcm_xa
DEA adpcm_yamaha
D A alac
DEV D asv1
DEV D asv2
D V D avs
D V bmp
D V D camstudio
D V D camtasia
D V D cavs
D V D cinepak
D V D cljr
D A cook
D V D cyuv
D A dts
DES dvbsub
DES dvdsub
DEV D dvvideo
DEV D ffv1
DEVSD ffvhuff
DEA flac
D V D flashsv
D V D flic
DEVSD flv
D V D fraps
DEA g726
DEA gsm
DEV D h261
DEVSDT h263
D VSD h263i
EV h263p
D V DT h264
DEVSD huffyuv
D V D idcinvideo
D V D indeo2
D V indeo3
D A interplay_dpcm
D V D interplayvideo
EV jpegls
D V kmvc
EV ljpeg
D V D loco
D A mace3
D A mace6
D V D mdec
DEV D mjpeg
D V D mjpegb
D V D mmvideo
DEA mp2
D A mp3
D A mp3adu
D A mp3on4
DEVSDT mpeg1video
DEVSDT mpeg2video
DEVSDT mpeg4
D VSDT mpegvideo
DEVSD msmpeg4
DEVSD msmpeg4v1
DEVSD msmpeg4v2
D V D msrle
D V D msvideo1
D V D mszh
D V D nuv
DEV pam
DEV pbm
DEA pcm_alaw
DEA pcm_mulaw
DEA pcm_s16be
DEA pcm_s16le
DEA pcm_s24be
DEA pcm_s24daud
DEA pcm_s24le
DEA pcm_s32be
DEA pcm_s32le
DEA pcm_s8
DEA pcm_u16be
DEA pcm_u16le
DEA pcm_u24be
DEA pcm_u24le
DEA pcm_u32be
DEA pcm_u32le
DEA pcm_u8
DEV pgm
DEV pgmyuv
DEV png
DEV ppm
D A qdm2
D V D qdraw
D V D qpeg
D V D qtrle
DEV rawvideo
D A real_144
D A real_288
D A roq_dpcm
D V D roqvideo
D V D rpza
DEV D rv10
DEV D rv20
D A shorten
D A smackaud
D V smackvid
D V D smc
DEV snow
D A sol_dpcm
DEA sonic
EA sonicls
D V D sp5x
DEV D svq1
D VSD svq3
D V theora
D V D truemotion1
D V D truemotion2
D A truespeech
D A tta
D V D ultimotion
D V vc1
D V D vcr1
D A vmdaudio
D V D vmdvideo
DEA vorbis
D V vp3
D V D vqavideo
D A wmav1
D A wmav2
DEVSD wmv1
DEVSD wmv2
D V wmv3
D V D wnv1
D A ws_snd1
D A xan_dpcm
D V D xan_wc3
D V D xl
DEV D zlib
D V zmbv

Supported file protocols:
file: pipe: udp: rtp: tcp: http:
Frame size, frame rate abbreviations:
ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif
Motion estimation methods:
zero(fastest) full(slowest) log phods epzs(default) x1 hex umh iter

Note, the names of encoders and decoders dont always match, so there are
several cases where the above table shows encoder only or decoder only entries
even though both encoding and decoding are supported for example, the h263
decoder corresponds to the h263 and h263p encoders, for file formats its even
worse


Enough with the preliminaries, to begin using the utility you need to begin by specifying the input stream which can take the form of video file, a video hardware stream, or a series of images. The -i argument specifier specifies the input to be manipulated.

If you only specify an input file with no output file FFmpeg will display the input source information, for example:

$ ffmpeg -i ./ffmpeg/video0.avi
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Seems that stream 0 comes from film source: 30000.00 (30000/1) -> 29.97 (30000/1001)
Input #0, avi, from './ffmpeg/video0.avi':
Duration: 00:01:17.1, start: 0.000000, bitrate: 14082 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x480, 29.97 fps(r)
Stream #0.1: Audio: mp2, 48000 Hz, stereo, 64 kb/s

Must supply at least one output file


Note that the input stream #0 shows the video and audio specifics for the input. You'll later learn how specifying an output file you'll be enabled to manipulate the input source to the desired output format.

Let's finish off this post by converting a Mpeg4 encoded video in an AVI container to an encoded video to a MPG container.

$ ffmpeg -i ffmpeg/video0.avi /tmp/video0.mpg
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Mar 26 2007 14:28:38, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Seems that stream 0 comes from film source: 30000.00 (30000/1) -> 29.97 (30000/1001)
Input #0, avi, from 'ffmpeg/video0.avi':
Duration: 00:01:17.1, start: 0.000000, bitrate: 14082 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x480, 29.97 fps(r)
Stream #0.1: Audio: mp2, 48000 Hz, stereo, 64 kb/s
Output #0, mpeg, to '/tmp/video0.mpg':
Stream #0.0: Video: mpeg1video, yuv420p, 720x480, q=2-31, 200 kb/s, 29.97 fps(c)
Stream #0.1: Audio: mp2, 48000 Hz, stereo, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 2313 q=31.0 Lsize= 7584kB time=77.0 bitrate= 806.7kbits/s
video:6920kB audio:602kB global headers:0kB muxing overhead 0.826762%

26 February, 2009

Extracting Raw Video Stream with Ffmpeg

We utilize raw, uncompressed video streams as input to sensor related video processing. Normally, our camera streams are captured directly from the camera source and stored in raw, uncompressed data file (no header or codec). Lately, we've found it useful to extract uncompressed streams from standard video file formats. Here's how:


$ ffmpeg -i ./VideoIn.avi -f rawvideo -pix_fmt gray /tmp/video.raw


This will convert the video stream to 8-bit grayscale and store it in a raw WxH stream, which you can play with:


$ mplayer -demuxer rawvideo -rawvideo w=640:h=352:y8 /tmp/video.raw


Note, the 640x352 image resolution was outputted as part of the ffmpeg extraction command, without the resolution you'll have more trouble viewing the video than 15 minutes of "The View".

Enjoy.