Skip to content

Instantly share code, notes, and snippets.

@bsidhom
Created September 12, 2020 05:28
Show Gist options
  • Save bsidhom/a1901af79648fe8c1dffbee2949a05b1 to your computer and use it in GitHub Desktop.
Save bsidhom/a1901af79648fe8c1dffbee2949a05b1 to your computer and use it in GitHub Desktop.
Concatenate MP4 files and inject 360 metadata. Similar to concat-mp4.py, but depends on https://github.com/google/spatial-media
#!/usr/bin/env bash
# Usage: ffcat <output> <input> [input ...]
set -euo pipefail
# Prints the contents of a concat file for ffmpeg.
function catfile() {
local inputs=($@)
local input
for input in "${inputs[@]}" ; do
# TODO: Escape embedded ' characters.
printf "file '%s'\n" "$(readlink -f $input)"
done
}
function main() {
if [[ $# < 2 ]] ; then
echo "Usage: $0 <output> <input> [input ...]" >&2
exit 2
fi
local output="$1"
shift
local inputs=($@)
local tempdir
tempdir="$(mktemp -d 'ffcat.XXXXXXXXXX')"
echo "Writing to temp dir: $tempdir"
local tempfile="$tempdir/cat.mp4"
catfile "${inputs[@]}"
echo "Concatenating files"
ffmpeg -f concat -safe 0 -i <(catfile "${inputs[@]}") -c copy "$tempfile"
echo "Injecting 360 metadata"
python3 "$HOME/dls/git/spatial-media/spatialmedia" -i "$tempfile" "$output"
rm -r "$tempdir"
echo "Done"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment