Showing posts with label compare. Show all posts
Showing posts with label compare. Show all posts

Saturday, March 13, 2021

Side By Side Video Makefile

Photo by Anthony from Pexels

 

Creating a side-by-side video from two input files requires knowledge of the input file dimensions, mainly to extend the overlay to a proper size and applying the overlay.  Most often, this is manually specified in the command line, but with some constraints some of it can be automated in a makefile.


If the left-most video dimensions are larger than the right, the following makefile will place the videos side-by-side and pull the audio from the left-most file.

$ cat Makefile 

all: sideBySide.mp4


left.mp4: ../big_buck_bunny_1080p_h264.mov

${SH} ffmpeg -i $<  -filter:v "crop=1024:768:0:0" -ss 60 -t 10 $@


right.mp4: ../big_buck_bunny_1080p_h264.mov

${SH} ffmpeg -i $<  -filter:v "crop=1280:720:0:0" -t 15 $@


%.size: %

${SH} ffprobe -v error -show_entries stream=width,height $< > $@


#--generate side-by-side, assumes left image is larger (or equally large) to right image

sideBySide.mp4: left.mp4 right.mp4 left.mp4.info right.mp4.info

${SH} export left=$(shell echo $^ | cut -d ' ' -f 1); \

      export right=$(shell echo $^ | cut -d ' ' -f 2); \

      export W1=$(shell grep "^width=" left.mp4.info | cut -f 2 -d '='); \

      export H1=$(shell grep "^height=" left.mp4.info | cut -f 2 -d '='); \

      export W2=$(shell grep "^width=" right.mp4.info | cut -f 2 -d '='); \

      export H2=$(shell grep "^height=" right.mp4.info | cut -f 2 -d '='); \

      export Y=$(shell echo '\($$H1-$$H2\)/2'); \

      ffmpeg -i $$left -i $$right -filter_complex "[0:v]pad=$$W1+$$W2:0:color=gray[int];\

                     [int][1:v]overlay=$$W1:0+$$Y[vid]" -map "[vid]" -map 0:a -acodec copy $@


%.info: %

${SH} ffprobe -v error -show_format -show_streams $< > $@


clean:

${RM} *.mp4 *.info


For more details, refer to FFmpeg Official Site: http://ffmpeg.org/