Difference between revisions of "Ffmpeg reference"

From Phonlab
Jump to navigationJump to search
Line 29: Line 29:
 
-c:v copy # for newer versions of ffmpeg only
 
-c:v copy # for newer versions of ffmpeg only
 
-vcodec copy # for all versions of ffmpeg</nowiki>
 
-vcodec copy # for all versions of ffmpeg</nowiki>
  +
  +
The -q parameter can also be used to control the quality of the video output. Set -q 2 to get a pretty high quality video bitrate.
   
 
== Changing the video resolution (scaling) ==
 
== Changing the video resolution (scaling) ==

Revision as of 21:36, 3 September 2014

ffmpeg is a command line tool for working with video files. In the Lab we use it to automate the creation of video stimulus files--adding features such as lead-in still frames or replacing the audio track with processed audio.

Note that some commands are not compatible with older versions of ffmpeg. These are know to work with version 1.0.7.

Visit the ffmpeg site for full documentation of the tool.

Extracting video

To extract video from a certain time, use the -ss and -t flags to specify start time and duration, respectively:

ffmpeg -ss HH:MM:SS[.CS] INFILE -t DURATION OUTFILE

This command, for example, would extract a 1.5-second clip starting at 5.3 seconds into 'longfile.avi' and save it to 'shortfile.avi':

ffmpeg -ss 00:00:05.30 longfile.avi -t 1.5 shortfile.avi

Bitrate and MPEG compression

Set the bitrate of the output file with the -b:v argument. Add this argument somewhere in the command, set off by spaces--for example, right before specifying the output file. Set it closer to the original file's bitrate to reduce the amount of compression.

-b:v 30000k

Unfortunately, this parameter is not available in older versions of ffmpeg; you can use -vcodec copy to copy over the video from the original file without re-encoding it. This will override any encoding-related settings.

-c:v copy     # for newer versions of ffmpeg only
-vcodec copy  # for all versions of ffmpeg

The -q parameter can also be used to control the quality of the video output. Set -q 2 to get a pretty high quality video bitrate.

Changing the video resolution (scaling)

Select the output video resolution with the video filter parameter:

-vf scale=WIDTH:HEIGHT

Note that the video image will be stretched horizontally or vertically if the output width/height ratio is different from the ratio in the input file.

Avoiding audio compression

Many compressed video outputs will also include compressed audio by default. Since the normal goal is to use movies in a listening experiment, we usually want to avoid making unintentional changes to the audio channels when processing video files. In particular, we want to avoid applying lossy compression (perhaps multiple times) when applying MPEG compression.

To ensure that audio channels are simply copied without additional compression from input to output video files, specify copy as the output audio codec.

-c:a copy    # for newer versions of ffmpeg only
-acodec copy # for all versions of ffmpeg

The copy codec tells ffmpeg to skip the default compression (when converting to MPEG or another format with default audio compression) and to pass through the audio with the same format it has in the input file.