av_convert

The program av_convert can convert between some video file formats and provide basic editing functions. This includes extracting arbitrary parts out of different video files and combining them in one destination file.

In normal operation, video frames and audio is decoded wile reading the source and recompressed upon writing the destination file. This decoding/encoding is performed by libVideoFile.

In an alternate operating mode, videoframes are not decompressed but copied directly to the destination file. Of course, this mode has some limitations: A scene can only start at a GOP (group of pictures) boundary and no operations such as resizing or cropping can be applied to the frames.

Input files

Since av_convert can do basic video editing with multiple sources it is necessary to describe the video sources and the timeline. When invoking av_convert all input files are listed on the command line. Here each source can have several attributes such as start time and the end time. More options are described below. There are three types of source files: combined video and audio, video only and audio only. This type is defined by the option letter:

-i combined video and audio
-v video only
-a audio only

After this option letter the description of the file follows. This consists of an optional name of the io-plugin to handle this file type separated by "::" and the filename. Parameters are enclosed in "[]" and follow directly after the file name.

The name of the io-plugin can be one of Avi, QT, Mpeg, Dvd, MpegVideo, mp3, ... A complete list of io-plugins can be obtained by
av_convert -h IO-Modules

The complete input file definition looks like this
-i Avi::movie.avi[10-100:2.5]
-i Dvd:Title=1:Start=10:End=12::/dev/dvd

In the first example the file type is Avi. If the part "Avi::" is not given av_convert will try to find out the file type using the file command.
The three numbers after the file name give the start and end position and the audio offset respectively.
In the second example the IO-plugin Dvd is used, which accepts the options Title, Start and End. Options are passed after the plugin name and separated by ":".

When audio and video is stored in different files or if only the audio or video track should be processed, -a or -v is used instead of -i. A pair of -a and -v will form an input with audio and video track.

This file definition now can be repeated for multiple inputs, which of course can be different files or different parts of the same file. Reading all this inputs in the same order as they appear on the command line makes up the timeline of the output.

Selecting the track number

If there is more than one audio or video track in one file, the one to use can be chosen by the options

-a n number of audio track
-v n number of video track

This should follow directly the file definition.

Crop frames

For each input file a rectangular box can be defined to crop the image to this box. The definition of the box follows the each input file and looks like this:
-c <x1,y1,x2,y2>
where the coordinates (x1,y1) and (x2,y2) represent the upper left end lower right corner of the image respectively. If -c is given before the first input file it is the default for all input files.

Output file

The output file definition looks the same way as for the input file. Here however specifing the IO-plugin is mandatory. The option for the output file is -o.
-o Avi::output.avi

Audio and video codecs

Beside the name of the output file the codecs for audio and video compression have to be defined. A list of all codecs can be obtained by -h A-Codecs and -h V-Codecs.
The audio codec is defined by
-A codec-name
and the video codec by
-V codec-name

The codecs can have additional options. These are given by
-A option=value or -V option=value
for the audio and the video codec. Using any unknown option (e.g. help=1) will print out a list of all known options of that codec.

Output size

The size of the output image can be given by
-s <X>x<Y>
in pixels. If this option is not given, the size of the first input file is used. Images are scaled to fit the output size.

Filters

Some filters can be applied to the video track in order to reduce noise or interlace artefacts prior to compression. This will significantly improve image quality or compression ratio for interlaced or noisy sources. The filters available are

-d deinterlace
-f 1 interpolate subsequent frames in time
this is good for non-interlaced video with random noise
-f 2 interpolate adjacent lines within one frame
this filter may give better results than -d on noisy interlaced frames
-b n blank n lines at top and bottom

Examples

av_convert -i Quicktime::Rec.mov -o Avi::Rec.avi -V XVID -V MinQuantisation=4 -V MaxQuantisation=8 -V Bitrate=1000 -A mp3 -A VBR=1 -A VBR_Quality=5

This example shows how to convert the input Rec.mov to the avi file Rec.avi. The video codec is XVID and the audio codec mp3. Some options are passed to the codecs.

Nonlinear video editing

av_convert -i Rec.mov[100-250.3] -i Rec.mov[5000-5200] -i ... -o Avi::Out.avi -V ... -A ...

The parts of Rec.mov from 100sec to 250.3sec and 5000sec to 5200sec are written to the destination file Out.avi.

Options overview
-i <file> Input file. The argument file has the format
fmt:option=value:...::filename[start-end:offset]
This parameter can be repeated for multiple input files:
av_convert -i Avi::file_1.avi[100-200] -i Avi::file_1.avi[300-500] ...
fmt IO-module
options=value Sets options of the IO-Module - use help=1 for list of options.
filename The name of the file. Some IO-Modules can use "-" for stdin.
start-end start and end give the part of the input file in seconds.
offset Offset sets a time difference between the video- and audio-stream.
-v <file> video input file
-a <file> audio input file
-o <fmt::file> output file, fmt: IO-module
-v n use video track n
-a n use audio track n
-V <Codec> set video codec
-V <option=value> set codec options
-V DIVX -V Bitrate=800 -V MinQuantisation=3 -V ...
-A <Codec> set audio codec
-A <option=value> set codec options
-h IO-Modules list IO-Modules
-h V-Codecs list video codecs
-h A-Codecs list audio codecs
Filteroptions
-d deinterlace
-f 1 interpolate in time
-f 2 interpolate between lines
-b n blank n lines at top and bottom
Outputoptions
-g size Maximum filesize for the output file in MB.
%n in the filenamen gets replaced with file number.
-c <x1,y1,x2,y2> crop box from inputframes.
-s <X>x<Y> output size
-C n audio channel for mono output
-D direct copy frame data