Rear Mirror

This script will crop and flip the rear camera, and place it on the front camera to look like a rear view mirror.

The front input is expected to be UHD/4k (3840×2160) and the rear input is expected to be FHD (1920×1080). 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

# Convert to constant frame rate of 30000/1001 (29.97)
# Crop

# x264 lossless
# aac

ffmpeg  -loglevel verbose \
-i $1 \
-map 0 \
-map_metadata 0 \
-map -0:d \
-map -0:s \
-map -0:t \
-c:a aac \
-vbr 5 \
-c:v libx264 \
-crf 0 \
-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  -loglevel verbose \
-i front-temp.mp4 \
-i rear-temp.mp4 \
-c:a aac \
-vbr 5 \
-c:v libx264 \
-crf 0 \
-filter_complex  "[0:v][1:v] overlay=960:0" \
-coder 1 \
-context 1 \
-g 1 \
-threads 8 \
-y \
-r 30000/1001 \
$3