Last active
November 16, 2023 14:04
-
-
Save coderobe/c9c2bced9e47d19d7a801b1ebb1de6d0 to your computer and use it in GitHub Desktop.
Renders mp4 to the demo format used by DB FIA passenger information displays - https://twitter.com/coderobe/status/1724915339513716922
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the input argument (MP4 file) is provided | |
if [ "$#" -ne 1 ]; then | |
echo "coderobe's gleis6.sh <3" | |
echo "Usage: $0 <inputfile.mp4>" | |
exit 1 | |
fi | |
# Input MP4 file | |
inputfile=$1 | |
# Directory to store the output frames | |
outputdir="output_frames" | |
mkdir -p "$outputdir" | |
# Extract, convert, resize, and invert color of every 10th frame | |
ffmpeg -i "$inputfile" -vf "select=not(mod(n\,10)),scale=480:128:force_original_aspect_ratio=decrease,pad=480:128:(ow-iw)/2:(oh-ih)/2:white,format=gray,negate" -vsync vfr -c:v bmp "$outputdir/%04d.bmp" | |
echo "Frames are saved in $outputdir" | |
# FFMPEG doesn't use the correct bitmap format | |
echo -ne "Fixing bmp format" | |
for f in $outputdir/*.bmp; do convert -monochrome $f BMP3:$f.out; mv $f.out $f; echo -ne "."; done | |
echo "" | |
# Output file to write the formatted content | |
outputfile="$outputdir/CMD.TXT" | |
# Start writing to the file | |
echo "[BITMAPS]" > "$outputfile" | |
counter=1 | |
# List all bitmap files and their corresponding numbers | |
for frame in "$outputdir"/*.bmp; do | |
echo "$(basename "$frame") $counter" >> "$outputfile" | |
let counter++ | |
done | |
# Write the [LOOP] section | |
echo "" >> "$outputfile" | |
echo "[LOOP]" >> "$outputfile" | |
echo "" >> "$outputfile" | |
echo "Test96x64:" >> "$outputfile" | |
# Reset counter for the LOOP section | |
counter=1 | |
# Write each CREATE line for each frame | |
for frame in "$outputdir"/*.bmp; do | |
echo "CREATE 0 0 480 256 0 0 0 0 0 $counter" >> "$outputfile" | |
echo "DELETE 1" >> "$outputfile" | |
let counter++ | |
done | |
echo "" >> "$outputfile" | |
echo "END" >> "$outputfile" | |
unix2dos $outputfile | |
echo "CMD file is saved as $outputfile" | |
echo "Job's done :*" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
telegram-cloud-document-4-5956104682945384631.mp4