Auto top/bottom

This script will crop and join the cameras so that the rear camera is flipped like a rear view mirror and placed above the main camera.

The front input is expected to be UHD/4k (3840×2160) and the rear input is expected to be FHD (1920×1080). The output will be FHD (1920×1080) due to the rear camera being only that resolution to begin with. The script can be modified accordingly to your specifications.

The output file is lossless H.264 which you will probably want to compress if you don’t plan on doing any more editing with it.

Usage is simply:

script front.mp4 rear.mp4 output.mp4

Original front

 

Original rear

 

Output

#!/bin/bash

ffmpeg -loglevel verbose \
-i $1 \
-c:a aac \
-vbr 5 \
-c:v libx264 \
-crf 0 \
-vf 'crop=3840:1296:0:160,scale=1920:648' \
-coder 1 \
-context 1 \
-g 1 \
-threads 8 \
-y \
-r 30000/1001 \
front-temp.mp4

ffmpeg -loglevel verbose \
-i $2 \
-map 0 \
-map_metadata 0 \
-map -0:d \
-map -0:s \
-map -0:t \
-c:a aac \
-vbr 5 \
-c:v libx264 \
-crf 0 \
-vf 'crop=1920:432:0:396,hflip' \
-coder 1 \
-context 1 \
-g 1 \
-threads 8 \
-y \
-r 30000/1001 \
rear-temp.mp4

ffmpeg -i rear-temp.mp4 \
-i front-temp.mp4 \
-filter_complex \
vstack=inputs=2  \
-c:a aac \
-vbr 5 \
-c:v libx264 \
-crf 0 \
-y \
$3