Convert mp4 to avi

$ ffmpeg -i infile.mp4 outfile.avi

Resize a video or image

Resize a video such that its width is 1080 pixels and the aspect ratio is maintained, hence the height parameter is -1:

$ ffmpeg -i input.mp4 -vf scale=1080:-1 output.mp4

Convert to a specificed bitrate

$ ffmpeg -i input.avi -b 64k output.avi

Convert WAV audio file to MP3 format at a specified audio bitrate

$ ffmpeg -i input.wav -acodec mp3 -ab 128k output.mp3

Convert WAV audio file to MP3 format at a variable audio bitrate

$ ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 0 output.mp3

c.f. https://web.archive.org/web/20220214061213/https://trac.ffmpeg.org/wiki/Encode/MP3

Convert mp3 audio file to Orbvis format at a specified audio bitrate

$ ffmpeg -i input.mp3 -acodec libvorbis -crf 15 output.ogg

  • -crf: Use Constant Rate Factor to keep the best quality and don't care about the file size. The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible.

Converting a WAV file to FLAC (a lossless format) and OPUS

mediainfo audio_file.wav
ffplay audio_file.wav

ffmpeg -i audio_file.wav \
  -acodec flac \
  -ac 2 \
  -compression_level 10 \
  -map_metadata 0 \
  audio_file.flac

Converting a WAV file to OPUS

mediainfo audio_file.wav
ffplay audio_file.wav

ffmpeg -i audio_file.wav \
  -acodec libopus \
  -ab 256k \
  -vbr on \
  -ac 2 \
  -frame_duration 60 \
  -compression_level 10 \
  -map_metadata 0 \
  -application audio \
  audio_file.opus

ffplay audio_file.opus
mediainfo audio_file.opus

Options: * -acodec libopus: equivalent to -c:a opus. * -c:a opus: opus (modern audio codec generally good for speech) * -c:a flac: FLAC (free lossless audio codec) * -ab 256k: Set bitrate to 256k. Suggested values: * 128k: input is a lossless format or a 320k MP3 * 64k: input is a 192k MP3 * -vbr on: turns on variable bitrate which may increase quality at the cost of using some additional kbits for some seconds. * -ac 2: left and right audio channels. * -frame_duration 60: increases quality at the cost of 40 additional miliseconds of latency. * -compression_level 10: highest compression rate at the cost of slower compression speed. * -map_metadata 0: copy tags from the MP3 file to the OPUS file. * -application voip (for speech) or -application audio (for music).

References: * https://wiki.hydrogenaud.io/index.php?title=Opus * https://wiki.hydrogenaud.io/index.php?title=Flac * https://hydrogenaud.io

Convert avi file to specified audio sampling rate (22050 Hz), audio bitrate (32 kbps), and frame size (640x480)

$ ffmpeg -i input.avi -ar 22050 -ab 32 -s 640×480 video.mp4

One can use named frame sizes such as

-s vga

Combine multiple files into one file

$ ffmpeg -safe 0 -f concat -i ./my_file_list.txt -c copy output_file.mp3

my_file_list.txt is

# some comment
file './part_file_1.mp3'
file './part_file_2.mp3'
file './part_file_3.mp3'

Trim a video or audio according to starting and ending times

ffmpeg -ss hh:mm:ss -to hh:mm:ss -i 'input.mp4' -c copy output.mp4

Clipping multiple parts of a video and join them into one video with properly adjusted metadata

ffmpeg -i in.mp4 \
    -vf  "select='between(t,4,6.5)+between(t,17,26)+between(t,74,91)', setpts=N/FRAME_RATE/TB" \
    -af "select='between(t,4,6.5)+between(t,17,26)+between(t,74,91)', asetpts=N/SR/TB" \
    out.mp4

Options

See formats and codecs available on your computer

$ ffmpeg -formats

References

External links

blog comments powered by Disqus