List codecs
ffmpeg -codecs | grep -i sub
Quiet output:
ffmpeg -i input.avi -loglevel fatal -stats output.mp4
Search for more streams by analyzing more video:
ffmpeg -i input.avi -analyzeduration 300M -probesize 300M output.mp4
ffplay -i input.avi -vf crop=ih
Define specific codecs
ffmpeg -i input.avi -c:v:0 h264 -c:a:0 aac output.mp4
Resize video mantaining aspect ratio
ffmpeg -i input.avi -vf scale=-1:720 output.mp4
Define bitrate
ffmpeg -i input.avi -vcodec h264 -b:v:0 250k -acodec aac -b:a:0 128k output.mp4
Export only the first 30 seconds:
ffmpeg -i input.avi -t 30 output.mp4
Export only the defined section:
ffmpeg -i input.avi -ss 00:04:28 -to 00:55:06 output.mp4
Note: If speed is important... use -c copy
to avoid encoding.
Useful for removing and reordering streams:
- Identifier: (source:type:number)
ffmpeg -i input.avi -map 0:v:0 -map 0:a:2 -map 0:a:0 output.mp4
Use cropdetect
to auto-detect crop size:
ffplay -i input.avi -vf cropdetect
Use the crop filter:
crop=w:h:x:y
These 3 are the same:
ffmpeg -i input.avi -vf crop=640:360:1280:250 output.mp4
ffmpeg -i input.avi -vf crop=16*10*4:9*10*4:1920-16*10*4:250 output.mp4
ffmpeg -i input.avi -vf crop=iw/3:ih/3:iw-ow:250 output.mp4
The filter will automatically center the crop if x
and y
are omitted:
crop=w:h
Crop 10 pixels from the top, and 10 from the bottom:
ffmpeg -i input.avi -vf crop=iw:ih-2*10 output.mp4
Note: If speed is important... use -c:a copy
to avoid audio encoding.
ffmpeg -i input.avi -vf fps=10 output.mp4
ffmpeg -i input.avi -i left.wav -i right.wav -map 0 -map 1 -map 2 -c copy output.mp4
Audio & Video
ffmpeg -i input1.mp4 -i input2.mkv -i input3.mov -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.mp4
Just audio
ffmpeg -i input1.wav -i input2.wav -i input3.wav -i input4.wav -i input5.wav -i input6.wav -filter_complex "[0:a:0][1:a:0][2:a:0][3:a:0][4:a:0][5:a:0]concat=n=6:v=0:a=1 [a]" -map "[a]" output.mp3
REMOVE_FROM="00:00:06"
REMOVE_TO="00:00:08.8"
ffmpeg -i input.mp3 -c copy -to $REMOVE_FROM input-temp1.mp3; \
ffmpeg -i input.mp3 -c copy -ss $REMOVE_TO input-temp2.mp3; \
ffmpeg -i input-temp1.mp3 -i input-temp2.mp3 \
-filter_complex "[0:a:0][1:a:0]concat=n=2:v=0:a=1 [a]" \
-map "[a]" output.mp3; \
rm input-temp*.mp3;
Convert multichannel audio to stereo (Audio channels)
ffmpeg -i input.avi -ac:a:0 2 output.mp4
Define specific levels of audio channels to stereo (Audio filter)
- FL/FC/BL: Front/Center/Back Left
ffmpeg -i input.avi -af "pan=stereo|FL=FC+0.30*FL+0.30*BL|FR=FC+0.30*FR+0.30*BR" output.mp4
Analyze the file using the volumedetect
filter
ffmpeg -i input.mp3 -af volumedetect -f null - 2>&1 | grep volume:
Adjust the volume by 10% or 5dB down
ffmpeg -i input.mp3 -af "volume=0.9" output.mp3
# or
ffmpeg -i input.mp3 -af "volume=-5dB" output.mp3
Start with a black screen and fade into full view over 3 seconds
ffmpeg -i input.avi -vf "fade=t=in:st=0:d=3" output.mp4
Start fading to black over 5 seconds at the 10-second mark
ffmpeg -i input.avi -vf "fade=t=out:st=10:d=5" output.mp4
The audio file will start at a low volume and fade in to full over 5 seconds.
ffmpeg -i input.mp3 -af "afade=t=in:st=0:d=5" output.mp3
The audio file will start fading to zero volume over 5 seconds starting at the 15-second mark.
ffmpeg -i input.mp3 -af "afade=t=out:st=15:d=5" output.mp3
You can apply both fade in and out effects at the same time, to avoid having to re-encode twice.
ffmpeg -i input.avi -vf "fade=t=in:st=0:d=3,fade=t=out:st=10:d=5" output.mp4
Slow mo:
ffmpeg -i input.avi -vf "setpts=PTS/0.5" -af "atempo=0.5" output.mp4
Speed up:
ffmpeg -i input.avi -vf "setpts=PTS/2" -af "atempo=2.0" output.mp4
NOTE: The atempo filter is limited to using values between 0.5 and 2.0 (so it can slow it down to no less than half the original speed, and speed up to no more than double the input). If you need to, you can get around this limitation by stringing multiple atempo filters together. The following with quadruple the audio speed:
ffmpeg -i input.avi -vf "setpts=PTS/4" -af "atempo=2.0,atempo=2.0" output.mp4
Timelapse:
- Speed: 60x (1 hour in 1 min, 1 min in 1 sec)
- Audio: No
ffmpeg -i input.avi -vf "setpts=PTS/60" -an output.mp4
cat ./VIDEO_TS/*.VOB | ffmpeg -i - output.mp4
ffmpeg -i rtmp://s39mvapi4g5wnh.cloudfront.net/cfx/st/flv:VideosPortalNuevo/Finanzas/Revaluacion_Moneda_Extranjera -profile:v high -preset slow -threads 0 Revaluacion_Moneda_Extranjera.mp4
ffmpeg -i "[your rtsp link]" -f flv -r -s -an "[Your rtmp link]"
http://subshifter.bitsnbites.eu
Download YouTube files (youtube-dl)
youtube-dl --extract-audio --audio-format mp3 -i -o "%(title)s.%(ext)s" https://www.youtube.com/watch?list=RDQMYgJ4UDCmSlA
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' -o "%(title)s.%(ext)s" https://www.youtube.com/watch?v=R8wG1W1TPgw
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' -o "%(title)s.%(ext)s" --referer https://www.taitradio.com/products/tait-enable-network-management/enablemonitor https://player.vimeo.com/video/106990265
mp3splt is a program for splitting mp3s without re-encoding that has a silence detector (among other detection methods).
Usage with the Silence mode (-s)
:
mp3splt -s input.mp3
For later review: