Skip to content

Instantly share code, notes, and snippets.

@niamu
Last active July 13, 2023 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niamu/d7d6b0672e2006aa732172eb8ac7dd6b to your computer and use it in GitHub Desktop.
Save niamu/d7d6b0672e2006aa732172eb8ac7dd6b to your computer and use it in GitHub Desktop.
Archive tool for The Matrix Resurrections teasers
#!/usr/bin/env bash
make_trailer() {
echo 'Generating 17'$1'-a-b'$3'-c'$2'-d-e'$4'-f-g'$5'-h'$6'-i.mp4...'
mkdir -p ./tmp/
choice=$1
time=$2
b=$3
e=$4
g=$5
h=$6
cat > ./tmp/video_segments.txt << EOF
file ../segments/$choice-a.mp4
file ../segments/$choice-b-$b.mp4
file ../segments/$choice-$time.mp4
file ../segments/$choice-d.mp4
file ../segments/$choice-e-$e.mp4
file ../segments/$choice-f.mp4
file ../segments/$choice-g-$g.mp4
file ../segments/$choice-h-$h.mp4
EOF
ffmpeg -hide_banner -loglevel error -safe 0 -f concat -i ./tmp/video_segments.txt -c copy '17'$1'-a-b'$3'-c'$2'-d-e'$4'-f-g'$5'-h'$6'-i.mp4'
rm -rf ./tmp/
}
get_string() {
echo -ne '17'$1'-a-b'$3'-c'$2'-d-e'$4'-f-g'$5'-h'$6'-i\0'
}
main() {
mkdir -p ./segments/
for choice in "red" "blue"; do
for x in {1..3}; do
time=$(printf "%02d%02d" 0 0)
s=$(get_string $choice $time $x $x $x $x)
out=$(printf "%s-%d-%s-%d-%d-%d" $choice $x $time $x $x $x)
# Assume that we have all segments stored if the last segment is present
if [ ! -f "./segments/$choice-h-$x.mp4" ]; then
mkdir -p ./tmp/
echo "Generating segments for $choice $x..."
if [ ! -f "./tmp/$out.mp4" ]; then
curl --silent -L "https://thechoiceisyours.whatisthematrix.com/generated/v7/high/$(md5 -qs $s | head -c32).mp4" -o "./tmp/$out.mp4"
fi
ffmpeg -hide_banner -loglevel error -i "./tmp/$out.mp4" -c copy -map 0 -segment_times 13,19,32,34,36,38,41 -f segment -reset_timestamps 1 "./tmp/$choice-$x-segment%d.mp4"
if [ ! -f "./segments/$choice-a.mp4" ]; then mv "./tmp/$choice-$x-segment0.mp4" "./segments/$choice-a.mp4"; fi
if [ ! -f "./segments/$choice-b-$x.mp4" ]; then mv "./tmp/$choice-$x-segment1.mp4" "./segments/$choice-b-$x.mp4"; fi
if [ ! -f "./segments/$choice-0000.mp4" ]; then mv "./tmp/$choice-$x-segment2.mp4" "./segments/$choice-0000.mp4"; fi
if [ ! -f "./segments/$choice-d.mp4" ]; then mv "./tmp/$choice-$x-segment3.mp4" "./segments/$choice-d.mp4"; fi
if [ ! -f "./segments/$choice-e-$x.mp4" ]; then mv "./tmp/$choice-$x-segment4.mp4" "./segments/$choice-e-$x.mp4"; fi
if [ ! -f "./segments/$choice-f.mp4" ]; then mv "./tmp/$choice-$x-segment5.mp4" "./segments/$choice-f.mp4"; fi
if [ ! -f "./segments/$choice-g-$x.mp4" ]; then mv "./tmp/$choice-$x-segment6.mp4" "./segments/$choice-g-$x.mp4"; fi
if [ ! -f "./segments/$choice-h-$x.mp4" ]; then mv "./tmp/$choice-$x-segment7.mp4" "./segments/$choice-h-$x.mp4"; fi
rm -rf ./tmp/
fi
done
done
for choice in "red" "blue"; do
for hour in {0..23}; do
for minute in {0..59}; do
time=$(printf "%02d%02d" ${hour} ${minute})
s=$(get_string $choice $time 1 1 1 1)
out=$(printf "%s-%d-%s-%d-%d-%d" $choice 1 $time 1 1 1)
if [ ! -f "./segments/$choice-$time.mp4" ]; then
echo "Generating time segment for $choice $time..."
mkdir -p ./tmp/
if [ ! -f "./tmp/$out.mp4" ]; then
curl --silent -L "https://thechoiceisyours.whatisthematrix.com/generated/v7/high/$(md5 -qs $s | head -c32).mp4" -o "./tmp/$out.mp4"
fi
ffmpeg -hide_banner -loglevel error -i "./tmp/$out.mp4" -c copy -map 0 -segment_times 13,19,32,34,36,38,41 -f segment -reset_timestamps 1 "./tmp/$choice-segment%d.mp4"
mv "./tmp/$choice-segment2.mp4" "./segments/$choice-$time.mp4"
rm -rf ./tmp/
fi
done
done
done
}
main
# The following generates the red pill trailer for 9:52pm
# The video segment numbers can be any number from 1..3
# make_trailer "red" 2152 1 1 1 1
@niamu
Copy link
Author

niamu commented Jul 13, 2023

This script depends on the following:

  • ffmpeg
  • md5
  • curl

If you run the main function of this script it will end up storing ~13GB worth of video segments. It will ultimately end up downloading much more in the process.

The make_trailer function splices the generated video segments back into a complete teaser video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment