#!/usr/bin/env bash # Re-encode OpenCV-written mp4v videos to broadly-playable H.264. # usage: reencode_h264.sh [...] set -euo pipefail enc() { local f="$1" tmp="${1%.mp4}.h264.tmp.mp4" ffmpeg -nostdin -v error -y -i "$f" \ -c:v libx264 -preset veryfast -crf 18 -pix_fmt yuv420p \ -movflags +faststart -an "$tmp" mv -f "$tmp" "$f" echo " reencoded $(basename "$f")" } for a in "$@"; do if [ -d "$a" ]; then while IFS= read -r -d '' f; do enc "$f"; done < <(find "$a" -maxdepth 1 -name '*.mp4' -print0) else enc "$a"; fi done