Flag | What | Example |
---|---|---|
-s | size | |
-c | code | |
-f | format | |
-v | verbosity | |
-r | framerate | |
-t | duration (seconds) | |
-metadata | key=value | |
-frames:v | limit number of frames | |
-an | no audio | |
-ar | sample rate | |
-vn | no video | |
-y | overwride existing video | |
-pix_fmt | accommodate colorspace |
v=(640x360 1280x720); \
for res in $v; do \
ffmpeg -i video.mp4 -profile:v baseline -level 3.0 -s $res -start_number 0 -hls_time 10 -hls_list_size 0 -f hls index_$res.m3u8; \
done
Use the .mkv
extension to allow for fail-safe recordings. Check this for more information.
ffmpeg -i http://example.com/radio.mp3 -c copy /path/to/output/file.mkv
ffmpeg -re -i http://example.com/radio.mp3 -ar [sample_rate] -f [codec] -c:a copy -f rtp rtp://127.0.0.1:1234
An example sample_rate
is 44100
. An example codec
is pcm_s16le
.
ffmpeg -i input.avi output.mp4
AVI files:
ffmpeg -i <input.avi> -q <quality> <output>
MP4 files:
ffmpeg -i <input.mp4> -crf <quality> <output>
Audio
ffmpeg -i <input> -b:a <bitrate> <output>
Video:
ffmpeg -i <input> -b:v <bitrate> <output>
Audio and Video
ffmpeg -i <input> -b:a <bitrate> -b:v <bitrate> <output>
ffmpeg -i <input> -filter:a "volume=<multiplier>" <output>
ffmpeg -i <input.mp4> -i <watermarl.jpg> -filter_complex "overlay=x:y" <output>
ffplay http://myradio.com/stream.mp3
# config could is: <left input>-<left output>|<right input>-<right output>
# i.e. 0-0|0-1
ffmpeg -i <input> -filter:a "channelmap=<config>" <output>
Switch left channel to right and right channel to left with the channelmap audio filter:
ffmpeg -i <stereo.mp3> -filter_complex "channelmap=map=FL-FR|FR-FL:channel_layout=stereo" <output.mp3>
Or with the pan audio filer:
ffmpeg -i <stereo.ogg> -af pan=stereo|c0=c1|c1=c0 <output.wav>
Or with -map_channel:
ffmpeg -i <stereo.ogg> -map_channel 0.0.1 -map_channel 0.0.0 <output.wav>
ffmpeg -i <input.mp3> -ac 2 <output.m4a>
ffmpeg -i <left.mp3> -i <right.mp3> -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" <output.mp3>
or
ffmpeg -i left.mp3 -i right.mp3 -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map "[a]" output.mka
ffmpeg -i <front_left.wav> \
-i <front_right.wav> \
-i <front_center.wav> \
-i <lfe.wav> \
-i <back_left.wav> \
-i <back_right.wav> \
-filter_complex "[0:a][1:a][2:a][3:a][4:a][5:a]join=inputs=6:channel_layout=5.1[a]" \
-map "[a]" <output.wav>
ffmpeg -i <input.wav> \
-filter_complex "channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR]" \
-map "[FL]" front_left.wav \
-map "[FR]" front_right.wav \
-map "[FC]" front_center.wav \
-map "[LFE]" lfe.wav \
-map "[BL]" back_left.wav \
-map "[BR]" back_right.wav
ffmpeg -i <stereo1.wav> \
-i <stereo2.wav> \
-filter_complex "[0:a][1:a]amerge=inputs=2,pan=stereo|c0<c0+c2|c1<c1+c3[a]" \
-map "[a]" <output.mp3>
Or use -ac 2 instead of the pan audio filter:
ffmpeg -i <stereo1.wav> \
-i <input2.wav> \
-filter_complex "[0:a][1:a]amerge=inputs=2[a]" \
-map "[a]" \
-ac 2 <output.mp3>
Use the avfoundation device:
ffmpeg -f avfoundation -list_devices true -i ""
# Expected output:
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
...
[AVFoundation indev @ 0x7f8349006000] AVFoundation video devices:
[AVFoundation indev @ 0x7f8349006000] [0] FaceTime HD Camera (Built-in)
[AVFoundation indev @ 0x7f8349006000] [1] Capture screen 0
[AVFoundation indev @ 0x7f8349006000] AVFoundation audio devices:
[AVFoundation indev @ 0x7f8349006000] [0] Loopback Audio
[AVFoundation indev @ 0x7f8349006000] [1] Built-in Microphone
This will enumerate all the available input devices including screens ready to be captured. Once you've figured out the device index corresponding to the screen to be captured, use:
ffmpeg -f avfoundation -i "<screen device index>:<audio device index>" output.mkv
This will capture the screen from and audio from into the output file output.mkv.
Use .mkv so you don't lose the file even if the application crashes.
If your CPU is not fast enough, the encoding process might take too long. To speed up the encoding process, you can use lossless encoding and disable advanced encoder options, e.g.:
ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 -c:v libx264rgb -crf 0 -preset ultrafast output.mkv
-crf 0
tells x264
to encode in lossless mode; -preset ultrafast
advises it to do so fast. Note the use of libx264rgb
rather than libx264
; the latter would do a lossy conversion from RGB to yuv444p
.
ffmpeg -f avfoundation -i 2:0 -c:v libx264 -preset veryfast -tune zerolatency -f flv rtmp://[$host][$streamPath]
You can also grab the contents of a livestream with the following command:
ffmpeg -re -i http://[$host][$streamPath] -c copy -f FORMAT output.mkv
ffmpeg -i INPUT -acodec libmp3lame -ar 11025 --f rtp rtp://host:port
ffmpeg -re -i http://[$host][$streamPath] -ar [44100] -f FORMAT -f rtp rtp://[$host]:[$port]