Ffmpeg: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
 
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Software
|Website=http://www.ffmpeg.org/
|License=LGPL, GPL
|OS=GNU/Linux
|Media=Audio, Video
|Format=OGG, WEBM, MPEG, AVI, MP4, MOV, QT
|Interface=Command-line interface,
|Wikipedia=http://en.wikipedia.org/wiki/FFmpeg
}}
[[Category: Software]]
Swiss army knife of video command line video tool originally written by [[Fabrice Bellard]] (under the pseudonym "Gerard Lantau")
Be sure to check you / print your own ffmpeg documentation! <br />
Be sure to check you / print your own ffmpeg documentation! <br />
http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html
http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html


== examples ==
== Usage ==
 
Like many "swiss army knife" commandline tools, ffmpeg has lots of options, with often many ways of doing something, and takes some getting used to.
 
== -i INPUT ==


extract frames (100 seconds per frame) and number the images using "zero-padded 6 digits":
With ffmpeg you always use -i NAMEOFFILE to set an input, and eventually simply give another NAMEOFFILE at the end to specify an output. (NB: This is the opposite of tools like mencoder where -o sets an output, and input files are the default).
 
== Inspect a video ==
 
Running ffmpeg with an input and no options / output dumps out information about a file. Despite the complaint that no output file has been specified, this command is very useful to check a video (file or URL!) for what kind of structure/format it has.
 
<source lang="bash">
ffmpeg -i http://constantvzw.org:8000/variable.ogg
</source>
 
== Convert a video into individual frames ==
 
The -r option sets the '''framerate'''. A framerate of .01 (or 1/100) means 100 seconds per frame. In this way you can easily make an overview of a movie:


<source lang="bash">
<source lang="bash">
ffmpeg -i rearwindow.avi -f image2 -y -r .01 -an rearwindow%06d.jpg
ffmpeg -i rearwindow.avi -f image2 -y -r .01 -an rearwindow%06d.jpg
</pre>
</source>
 
The "%06d" means to "pad" (or fill) the filename to having always 6 places (so adding extra 0's before the number as necessary so that the filenames all have the right size and avoiding any problem with sorting later). This follows the convention of the C printf command).
 
Extract 1 frame per second (padding to 3 places):
 
<source lang="bash">
ffmpeg -i inputfile.avi -r 1 -f image2 image-%3d.jpeg
</source>
 
== Setting a start time ==
 
Extract 2 fps (-r) starting at 1:45:02 (-ss) and process 10 seconds of the input (-t 10).
 
<source lang="bash">
ffmpeg -i inputfile.avi  -r 2 -ss 01:45:02 -t 10 image-%d.jpeg
</source>
 
Alternately -vframes lets you specify how many output frames you want (rather than input time)?
 
<source lang="bash">
ffmpeg -i inputfile.avi  -r 2 -ss 01:45:02 -vframes 10 image-%d.jpeg
</source>
 
== Extracting a specific part of a media file ==
 
The general form is:
 
ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
 
Where:
 
    -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
    -t specifies the duration of the clip (same format).
    Instead of -t you can also supply the end time with -to.
    -c copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.
 
== Assemble images into a video ==
 
<source lang="bash">
ffmpeg -f image2 -r 1/5 -i img%03d.png -r 30 out.mp4
</source>
 
using a glob
ffmpeg -f image2 -pattern_type glob -i 'anim*.png' -s 160x120 -y anim.ogv
 
== Resources ==
* http://ffmpeg.org/trac/ffmpeg/wiki/
 
== Concatenation / Assembling a sequence ==
 
https://trac.ffmpeg.org/wiki/Concatenate
 
https://cects.com/concatenating-windows-ffmpeg/
 
== Audio volume Manipulation ==
 
https://trac.ffmpeg.org/wiki/AudioVolume
 
== Filters / Processing Audio with ffmpeg ==
 
https://ffmpeg.org/ffmpeg-filters.html
 
== Audio Channel Manipulation ==
 
https://trac.ffmpeg.org/wiki/AudioChannelManipulation
 
== metadata ==
 
  ffmpeg -i in.avi -metadata title="my title" out.flv

Latest revision as of 08:51, 12 May 2020

Website http://www.ffmpeg.org/
License LGPL, GPL
OS GNU/Linux
Media Audio, Video
Format OGG, WEBM, MPEG, AVI, MP4, MOV, QT
Interface Command-line interface,
Wikipedia http://en.wikipedia.org/wiki/FFmpeg

Swiss army knife of video command line video tool originally written by Fabrice Bellard (under the pseudonym "Gerard Lantau")

Be sure to check you / print your own ffmpeg documentation!
http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html

Usage

Like many "swiss army knife" commandline tools, ffmpeg has lots of options, with often many ways of doing something, and takes some getting used to.

-i INPUT

With ffmpeg you always use -i NAMEOFFILE to set an input, and eventually simply give another NAMEOFFILE at the end to specify an output. (NB: This is the opposite of tools like mencoder where -o sets an output, and input files are the default).

Inspect a video

Running ffmpeg with an input and no options / output dumps out information about a file. Despite the complaint that no output file has been specified, this command is very useful to check a video (file or URL!) for what kind of structure/format it has.

ffmpeg -i http://constantvzw.org:8000/variable.ogg

Convert a video into individual frames

The -r option sets the framerate. A framerate of .01 (or 1/100) means 100 seconds per frame. In this way you can easily make an overview of a movie:

ffmpeg -i rearwindow.avi -f image2 -y -r .01 -an rearwindow%06d.jpg

The "%06d" means to "pad" (or fill) the filename to having always 6 places (so adding extra 0's before the number as necessary so that the filenames all have the right size and avoiding any problem with sorting later). This follows the convention of the C printf command).

Extract 1 frame per second (padding to 3 places):

ffmpeg -i inputfile.avi -r 1 -f image2 image-%3d.jpeg

Setting a start time

Extract 2 fps (-r) starting at 1:45:02 (-ss) and process 10 seconds of the input (-t 10).

ffmpeg -i inputfile.avi  -r 2 -ss 01:45:02 -t 10 image-%d.jpeg

Alternately -vframes lets you specify how many output frames you want (rather than input time)?

ffmpeg -i inputfile.avi  -r 2 -ss 01:45:02 -vframes 10 image-%d.jpeg

Extracting a specific part of a media file

The general form is:

ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4

Where:

   -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
   -t specifies the duration of the clip (same format).
   Instead of -t you can also supply the end time with -to.
   -c copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.

Assemble images into a video

ffmpeg -f image2 -r 1/5 -i img%03d.png -r 30 out.mp4

using a glob

ffmpeg -f image2 -pattern_type glob -i 'anim*.png' -s 160x120 -y anim.ogv

Resources

Concatenation / Assembling a sequence

https://trac.ffmpeg.org/wiki/Concatenate

https://cects.com/concatenating-windows-ffmpeg/

Audio volume Manipulation

https://trac.ffmpeg.org/wiki/AudioVolume

Filters / Processing Audio with ffmpeg

https://ffmpeg.org/ffmpeg-filters.html

Audio Channel Manipulation

https://trac.ffmpeg.org/wiki/AudioChannelManipulation

metadata

 ffmpeg -i in.avi -metadata title="my title" out.flv