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%

29 April, 2009

vlc

#!/bin/bash

#---server---
# vlc -vvv /tmp/video.avi --sout '#transcode{vcodec=DIV3,vb=256,scale=1,acodec=mp3,ab=32,channels=2}:std{access=mmsh,mux=asfh,dst=:8080}' &
# vlc -vvv --loop /tmp/video.avi --sout '#transcode{vcodec=DIV3,vb=1024,scale=1,acodec=mp3,ab=32,channels=2}:std{access=mmsh,mux=asfh,dst=:8080}' &
vlc -vvv --loop /tmp/clip.avi --sout '#transcode{vcodec=DIV3,vb=1024,scale=1,acodec=mp3,ab=32,channels=2}:std{access=mmsh,mux=asfh,dst=:8080}' &
vlc -vvv --loop /tmp/clip.avi --sout '#transcode{vcodec=DIV3,vb=1024,scale=1,width=320,height=240,acodec=mp3,ab=32,channels=2}:std{access=mmsh,mux=asfh,dst=:8080}' &

#---client---
sleep 3
vlc mmsh://127.0.0.1:8080

Can play with Windows Explorer by specifying URL as:
mms://192.168.2.3:8080

24 April, 2009

AutoStart VM with Xen

I've been evaluating Xen, VirtualBox, and VMware as part of work. We require a system to autoboot virtual machines as a feature of the virtualization technology we choose. I just found how to autoboot using Xen and thought it worthy of a quick post.



# mkdir /etc/xen/auto
# ln -s /etc/xen/mymachine.cfg /etc/xen/auto/


You can test this by restarting the xendomain service as follows:

# /etc/init.d/xendomains stop

16 April, 2009

Xen 3.0 Installation - Debian 4.0

This morning I started my investigation of using Xen virtualization, this post will focus on the installation of Xen and the steps to create my first WinXp Professional guest OS.

Xen Installation
This installation took place on a Debian 4.0 AMD 64 distribution, with VT-X hardware support:

user@debian:~$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 CPU L7400 @ 1.50GHz
stepping : 6
cpu MHz : 1234.565
cache size : 4096 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips : 3180.78
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 CPU L7400 @ 1.50GHz
stepping : 6
cpu MHz : 1234.565
cache size : 4096 KB
physical id : 1
siblings : 1
core id : 0
cpu cores : 1
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips : 3180.78
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
You can determine if your cpu supports virtualization extensions by issuing the following command. If your cpu does not support virtualization extensions it won't support full virtualization and therefore won't support Windows guest operating systems.

user@debian:~$ egrep '^flags.*(vmx|svm)' /proc/cpuinfo
flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm




Our journey begins by installing the appropriate Xen Debian packages using Synaptic; following is a screen shot of the packages I installed.


Install the above packages using Synaptic or apt-get; whichever you prefer.

After completing the installation of these packages, you'll need to reboot. You'll find that a new Xen-based kernel image has been installed and should be defined as the default boot image. You'll notice that some Xen-specific logging prior to the Linux boot sequence. After completion, you should boot to a familiar looking system....login prompt and similar desktop as you've grown to love.

WinXp Guest Installation
You should now be ready to install your first guest operating system. Xen refers to these as domains...really don't care as every other virtualization technology calls them virtual machines and I'll be sticking with that terminology.

If you're familiar with VirtualBox, or VMware you'll quickly notice that Xen configuration is less user-friendly. Gone are the GUI configuration utilities, gone are the virtual machine status displays, and gone are the single-click access to virtual machine consoles. No worries though, we'll work with what the good Xen developers gave us.

Guest OS Installation Media
The installation procedures I referenced made use of an ISO image of the WinXp installation cd. How exactly you'd do this with live media is left as an exercise to the reader :)

I created a raw copy of the WinXp Installation CD by using the dd utility as follows:
Note, you must unmount the cdrom BEFORE issuing this command.

$ dd if=/dev/scd0 of=/home/user/WinXpPro.iso
You'll notice that I was using an external usb cdrom by the /dev/scd0 device name.
Creation of the Virtual Machine Hard-Drive File System
# mkdir /home/xen/domains/win01
# dd if=/dev/zero of=/home/xen/domains/win01/win_vm.img bs=1M count=2048

Creation of Virtual Machine Configuration File
While the user-friendly configuration user interfaces are non-existant, you still have available a highly configurable virtual machine. Configuration is done by a text based configuration file that you must create prior to starting the machine. I used the following for my WinXp guest operating system installation. You'll need to create this as root in the specified directory.
debian:~# cat /etc/xen/win01.cfg
kernel = '/usr/lib/xen-3.0.3-1/boot/hvmloader'
builder = 'hvm'
memory = '1024'
device_model='/usr/lib/xen-3.0.3-1/bin/qemu-dm'

# Disks
disk = [ 'file:/home/xen/domains/win01/win_vm.img,ioemu:hda,w',
'file:/home/user/WinXpPro.iso,ioemu:hdc:cdrom,r' ]

# Hostname
name='win01'

# Networking
vif = ['type=ioemu, bridge=xenbr0']

# Behaviour
boot='d'
vnc=1
vncviewer=1
vncunused=0
sdl=0
debian:~#

One thing I found was I initially didn't install the Xen-IoEmu package which later gave me errors during booting of the VM so make sure you installed that package.

Note, that the disk field specifies a hard-drive file system image and the OS installation ISO image. First time booting of this VM will kick off the installation from the ISO image.

Booting the VM
You should now be ready to start the VM. You start (or create) the VM by issuing the following command:

# xen create win01.cfg -c


Pay special attention to the -c argument, otherwise this thing may fail silently. You should get a started win01
response from this command.

You next need to know how to query the status of the VM and connect to the VM console. You can query the status of running virtual machines by issuing the command:

debian:~# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 947 2 r----- 457.1
win01 3 1024 1 -b---- 17.6
debian:~#


This status tells you general info, but at this point you want to pay special attention to the ID as it is how you will connect to the VM.

VNC is integrated into Xen VMs and this is the means to connect to the machine. The VM ID indirectly tells you what port to connect to (by adding 5900+ID). You can connect to this machine by issuing:

$user@debian:~$ vncviewer 127.0.0.1:5903


During the installation process the machine reboots a couple times, each time a new ID is assigned so when you lose your connection repeat the xm list + vncviewer sequence again.

That's all for now.

15 April, 2009

Starting VirtualBox as a Service

I've been trying to compare VirtualBox features with VMware Server 2.0. One of the first features that doesn't exist (without some work) is the concept of auto-starting virtual machines at system start-up.

With head-less virtual machine modes and RDP connectivity, it appears that all the core features exist.

By incorporating the starting of virtual machines in head-less modes as a service that is started at system start-up you'd have the equivalent of VMware Server. This post will document the means to do just that.

First, since system start-up is executed by root, the virtual machine will need to be associated with the root user. You can accomplish this by firing up VirtualBox interactively and create the desired virtual machines. I, however, had the virtual machines I wanted to start created in an alternative user account, so I created a soft-link between the root user home directory and the user directory (keep you security concerns to yourself, this is simply proof of concept).


# cd /root
# ln -s /home/user/.VirtualBox .VirtualBox


Next, create a script that serves as the necessary service daemon:


#!/bin/bash
# scriptName: VBoxD

VBOXHEADLESS="/usr/bin/VBoxHeadless"

vbox_start() {
echo "...starting $1" >> /var/tmp/myLog
$VBOXHEADLESS -s $1 > /dev/null &
}

#---main---
case "$1" in
start)
echo "...starting my service" >> /var/tmp/myLog
logger -p user.notice "starting service"
vbox_start WinXp
;;
stop)
echo "...stopping my service" >> /var/tmp/myLog
logger -p user.notice "stopping service"
;;
restart)
echo "...restarting my service" >> /var/tmp/myLog
;;
esac

exit 0



Note that this script has hard-coded virtual machine named WinXp; again, this is proof of concept. Please keep in mind, this isn't a complete service script solely enough to demonstrate the ability of introducing a service into system start-up.

You can test the script behavior can by invoking:

# ./VBoxD start
# ./VBoxD stop


To incorporate this into the system start-up, you first find what runlevel you are currently running:

# ps -aef | grep init
root 1 0 0 20:23 ? 00:00:00 init [2]
root 5047 4725 0 20:58 pts/0 00:00:00 grep init


Shows run-level 2; meaning that the service must reside in /etc/rc2.d

Changing to /etc/rc2.d you add the service by creating a soft-link to /root/VBoxD with a prefix S followed by a 2-digit numeric (the larger the numeric the later the service is started). In this example, I created S91VBoxD as follows:

xion:/etc/rc2.d# ls -l S91VBoxD
lrwxrwxrwx 1 root root 11 2009-04-12 19:47 S91VBoxD -> /root/VBoxD


If you've properly enabled RDP for this machine at port 3389 you should be able to connect to the head-less virtual machine by:

$ rdesktop 127.0.0.1:3389

14 April, 2009

VirtualBox Command Line Commands

Assuming you have created a virtual machine called WinXp can start the machine in a headless mode (non-gui) by invoking the command:


VBoxHeadless --startvm WinXp


To shutdown the virtual machine, you can invoke the command

VBoxManage controlvm WinXp poweroff