Skip to content

Instantly share code, notes, and snippets.

@adrianjagielak
Last active January 10, 2025 14:58
Show Gist options
  • Save adrianjagielak/0dee9b9cb0bbf9194e7cdce592cde9db to your computer and use it in GitHub Desktop.
Save adrianjagielak/0dee9b9cb0bbf9194e7cdce592cde9db to your computer and use it in GitHub Desktop.
A shell script that uses ffmpeg to convert your video files into the correct format for the TinyTV2. This script takes one input parameter (the path to the video file), checks if the file is already an .avi, and then converts it with the appropriate settings.
#!/bin/bash
# Check if the input parameter is provided
if [ -z "$1" ]; then
echo "Error: No video file specified."
echo "Usage: $0 <video_file>"
exit 1
fi
INPUT_FILE="$1"
EXT="${INPUT_FILE##*.}"
BASENAME="${INPUT_FILE%.*}"
OUTPUT_FILE="${BASENAME}.avi"
# Check if the file already has an .avi extension
if [ "$EXT" == "avi" ]; then
echo "Error: The file is already an AVI file."
exit 1
fi
# Convert the video
ffmpeg -i "$INPUT_FILE" \
-vf "scale=210:135:force_original_aspect_ratio=increase,crop=210:135" \
-c:v mjpeg -q:v 4 \
-c:a pcm_u8 -ar 10000 -ac 1 \
-r 24 \
"$OUTPUT_FILE"
# Check if the conversion was successful
if [ $? -eq 0 ]; then
echo "Conversion successful: $OUTPUT_FILE"
else
echo "Error: Conversion failed."
exit 1
fi
@adrianjagielak
Copy link
Author

adrianjagielak commented Jan 10, 2025

Key Details of the Script:

  1. Resolution and Aspect Ratio:

    • Scales the video to 210x135 with aspect ratio preservation using scale=210:135:force_original_aspect_ratio=increase.
    • Crops the video to the exact dimensions if the aspect ratio differs after scaling using crop=210:135.
  2. Video Codec:

    • Converts the video to mjpeg (Baseline) with a quality setting of -q:v 4.
  3. Audio Codec:

    • Converts the audio to pcm_u8 with a sample rate of 10000 Hz and 1 channel.
  4. Frame Rate:

    • Sets the frame rate to 24 fps.
  5. Error Handling:

    • Throws an error if the file is already an .avi or if the conversion fails.

Usage:

  1. Save the script as convert_to_tinytv2.sh.
  2. Make it executable:
    chmod +x convert_to_tinytv2.sh
  3. Run the script with a video file as the parameter:
    ./convert_to_tinytv2.sh path/to/video.mp4
  4. The converted video will be saved as path/to/video.avi.

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