Video
Video Tips¶
Converting with ffmpeg¶
ffmpeg is really powerful, but doesn't have the simplest UI! Here are some useful conversions:
Shrink and speed up and rotate 180 degrees¶
ffmpeg -i 20170614_024144.MOV -c:v libx265 -vf "scale=800:-1:flags=lanczos,transpose=2,transpose=2,setpts=0.125*PTS" ~/Videos/outputfile2.mp4
scale=800:-1— scales to 800 wide by whatever high to keep aspect ratiotranspose=2— rotate 90°. Specify twice for 180°setpts=0.125*PTS— keep framerate the same but drop frames to give 8x speed
Convert to H.265¶
ffmpeg -i inputfile.mov -vf yadif -c:v libx265 /tmp/outputfile.mp4
There's also a -crf option which controls how much compression is done. 0 is lossless, 51 is lowest
quality, 23 is the default.
De-interlace 1080i AVCHD video from a camcorder into H265¶
Produces a file about a quarter of the size without the interlacing artifacts:
ffmpeg -i inputfile.MTS -vf yadif -c:v libx265 /tmp/outputfile.mp4
Pick a deinterlacing engine from one of:
- bwdif
- yadif
- kerndeint
- nnedi
- w3fdif
See https://github.com/kfrn/ffmpeg-things/blob/master/deinterlacing.md
Transcode to GIF¶
ffmpeg -i simplescreenrecorder-2021-10-13_15.54.26.mkv \
-vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam -f image2pipe - \
| convert -delay 10 - -loop 0 -layers optimize output.gif
Compress all videos recursively from current folder down¶
IFS=$'\n'
for i in `find . -name '*MOV' -o -name '*AVI'`; do
echo $i
ffmpeg -loglevel quiet -stats -i "$i" -vcodec libx265 -crf 24 "$i".mp4
mv "$i" "$i".done
done
Scale video¶
-vf scale=w=1280:h=720
Stabilisation¶
This is really slow, but can clean up shaky footage. See https://www.paulirish.com/2021/video-stabilization-with-ffmpeg-and-vidstab/
ffmpeg -i clip.mkv -vf vidstabdetect -f null -
ffmpeg -i clip.mkv -vf vidstabtransform clip-stabilized.mkv
Stack for comparison: