ffmpeg basic

ffmpeg basic

Donny Donny
November 26, 2018
April 17, 2022
411
-

Input and Output

$ ffmpeg -i input.mp4 output.mp4

Cutting Video or Audio

Begin and length:

$ ffmpeg -i input.mp4 -ss 00:00:10 -t 01:00:10 output.mp4

Beginning time and ending time:

$ ffmpeg -i input.mp4 -ss 01:00 -to 10:00 -c copy output.mp4

  • "-c" is short for "-codec". Use "-codec:a" or "-codec:v" to specify audio or viedo respectively.

  • "-c copy" suggests that the data will be copy directly to output (rather than being converted in some cases).

Video Converting

$ ffmpeg -i input1.flv input2.flv -framerate 30 -f mp4 -vf "scale=1280x720" output.mp4
$ ffmpeg -i input1.flv input2.flv -framerate 30 -f mp4 -vf "crop=${w}:${h}:${x}:${y}" output.mp4

  • "-framerate 30" fixes the framerate to 30 fps.
  • "-f mp4" before output file (or before input files) specifies the output (or input) format is mp4, by default the format will be detected via the suffix of output (or input) name.

Increase Volume

Detect the volume:

$ ffmpeg -i input.mp3 -af "volumedetect" -vn -sn -dn -f null /dev/null

  • "-vn" / "-an" / "-sn" / -"dn" instructs ffmpeg to skip inclusion of video / audio /subtitle / data streams respectively.

  • "-af" is short for "-filter:a".

Read the output values from the command line log:

[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] mean_volume: -16.0 dB
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] max_volume: -5.0 dB

Than:

$ ffmpeg -i input.mp3 -af "volume=5.0dB" output.mp3

For more information, refer to How can i normalize audio using ffmpeg? - Super User