Video streaming devops blog

FFMPEG tricks used at Spuul


Get video meta-data in an usable way

Use json output with ffprobe:

ffrpobe -v quiet -print_format json -show_format -show_streams -i my_movie.mp4

Detect black borders in a movie

By using the cropdetect filter. Default parameters for limit (24), round (16) and reset (0), worked fine for me.

ffmpeg -i my_movie.mp4 -vf "cropdetect=24:16:0" -f null -

You will get a crop guess for every frame crop=1280:544:0:86 telling you that the cropped width is 1280, the cropped height is 544 and that the position of the crop box is 0px from the left and 86 px from the top.

You want to seek some minutes into the movie and look at only some amount of frames. Let’s seek 10 minutes inside the movie and look only at 24 frames:

ffmpeg -ss 600 -i my_movie.mp4 -vframes 24 -vf "cropdetect=24:16:0" -f null -

You still need to get only one value. Let’s filter the result out and pick the one with the most occurrences:

ffmpeg -ss 600 -i my_movie.mp4 -vframes 24 -vf "cropdetect=24:16:0" -f null - 2>&1 |  grep -o crop=.* | sort | uniq -c | sort -n | tail -n1 | awk '{print $2}'

Verify the values with ffplay:

ffplay -i my_movie.mp4 -vf crop=1280:544:0:86

Without downloading the file:

ffmpeg -ss 600 -i -vframes 24 -vf "cropdetect=24:16:0" -f null - 2>&1 |  grep -o crop=.* | sort | uniq -c | sort -n | tail -n1 | awk '{print $2}'

Concatenate two movies with different aspect ratios

We need to add some padding to accommodate the different sizes:

echo "file 'my_movie1.mp4'" > my_list.txt
echo "file 'my_movie2.mp4'" >> my_list.txt
ffmpeg -re -f concat -i my_list.txt -filter_complex '[0:0]pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black' my_new_movie.mp4
Posted 2016-10-04
Page history

Devops at Spuul. Any tips or suggestions? Reach out!