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.

No comments: