Background/goal:
In my workflow, sometimes I need a quick video manipulation. No time for those GUI mouse-click-click video editing app.
Toys:
- mpv - Cross platform media player.
- ffmpeg - Anything audio-video. Record, convert, stream, or even summon Kraken with it.
- youtube-dl - One ring to rule them all. Download video from more than 900+ video sites.
Go crazy into ffmpeg
documentation or discussions.
Below are my frequent actions. Tweet me your other fav command..
Get video size
Get width x height (ref: link)
ffprobe -v error -select_streams v:0 \
-show_entries stream=width,height -of csv=s=x:p=0 input.mp4
or simply just
ffprobe video.mp4
Resize video dimension
Resize to width 640
, keep aspect ratio with -1
(ref: ffmpeg scaling)
ffmpeg -i output.mp4 -vf scale=640:-1 test.mp4
Play/seek video time
Play:
mpv boring_long_video.mp4
ormpv *
o
- Show onscreen display
Seek time:
[
]
- decrease/increase playback speedShift+Ctrl+BACKSPACE
- mark position.
More in mpv
documentation
Cut video
Cut from minutes 44:24
, up to 49
seconds (ref: link)
ffmpeg -ss 00:44:24 -i file.mp4 -to 00:00:49 -c copy file-copy.mp4
Create empty video
- With image (ref: link):
ffmpeg -loop 1 -i image.png -t 900 -r 1 -c:v libx264 image.mp4
- Without image (ref: link):
ffmpeg -f lavfi -i color=c=gray:s=320x240:d=10 \
-vf "drawtext=text='BIJY':fontcolor=white" output.mp4
Reverse & flip video
Quick way to create a reverse meme video (ref: link):
ffmpeg -i vid.mp4 -vf reverse -af areverse rev.mp4
Flip horizontal/vertical (ref: link):
ffmpeg -i vid.mp4 -vf vflip -c:a copy vflip.mp4
ffmpeg -i vid.mp4 -vf hflip -c:a copy hflip.mp4
Rotate 90-> or <-90:
ffmpeg -i vid.mp4 -vf transpose=1 -c:a copy rotate.mp4
ffmpeg -i vid.mp4 -vf transpose=2 -c:a copy rotate.mp4
Subtitling
Burn subtitle (.srt file) into the video file (ref: link):
ffmpeg -i test.mp4 \
-vf "subtitles=subtitlefile.srt:force_style='Fontsize=40,PrimaryColour=&Hffffff&'" \
-c:a copy test-subtitle.mp4
Fix video for Twitter post
If somehow video not accepted by Twitter (don't ask why) (ref: link, link):
ffmpeg -i test.mov -vcodec libx264 \
-vf 'scale=640:trunc(ow/a/2)*2' \
-acodec aac -vb 1024k -minrate 1024k -maxrate 1024k \
-bufsize 1024k -ar 44100 -strict experimental -r 30 test.mp4