Generate Videos Using ffmpeg

This note is for using ffmpeg on a linux machine (bash). See full script below:

LOGLEVEL="panic" #info, warning, panic
for FNAME in materials/*.mp4; do
	FNAME2=$(basename "$FNAME")
	echo ${FNAME2%.mp4}
	# crop the useful part of the video
	ffmpeg -nostdin -i "$FNAME" -loglevel $LOGLEVEL -filter:v "crop=1488:837:10:50" -c:a copy -an -y "buf1.mp4"
	# scale to 1920 x 1088
	ffmpeg -i buf1.mp4 -loglevel $LOGLEVEL -vf scale=1920:1088 -codec:a copy -y buf2.mp4
	mv buf2.mp4 buf1.mp4
	# add frame.png
	ffmpeg -i buf1.mp4 -i frame.png -loglevel $LOGLEVEL -filter_complex "[0:v][1:v] overlay=0:0:enable='between(t,0,10000)'" -pix_fmt yuv420p -c:a copy -y buf2.mp4
	mv buf2.mp4 buf1.mp4
	# add text label
	ffmpeg -i buf1.mp4 -loglevel $LOGLEVEL -vf drawtext="fontfile=SourceSansPro-Bold.ttf: \
	text='${FNAME2%.mp4}': fontcolor=white: fontsize=56: box=1: boxcolor=black@0.5: \
	boxborderw=5: x=(w-text_w)/2: y=20" -codec:a copy -y "$OUTDIR/${FNAME2%.mp4}-1080p.mp4"
	rm buf1.mp4

Sample output are listed in github 1 and github 2. Downloadable files for the sample script above:


Luke Sy
PhD Candidate

My research interests include state estimation, robotics, wearable sensors, machine learning, and biomedical engineering.