Created
February 1, 2026 00:36
-
-
Save ejfox/f493cac5d2fe7dc099b183b6e999aba6 to your computer and use it in GitHub Desktop.
Miyoo Mini video encoder - 640x480 with classic yellow subtitles
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 | |
| # Miyoo Mini Movie Encoder - Enhanced Version | |
| # Encodes movies to 480p 4:3 with burned-in subtitles for Miyoo Mini | |
| # Usage: ./miyoo_encode_enhanced.sh [input_file_or_folder] [subtitle_language_code] [output_directory] [options] | |
| set -e | |
| # Default settings for Miyoo Mini (640x480 native screen) | |
| TARGET_WIDTH=640 | |
| TARGET_HEIGHT=480 | |
| BITRATE="600k" | |
| AUDIO_BITRATE="96k" | |
| # Classic yellow subtitles - no outline | |
| SUB_STYLE="FontSize=28,FontName=Arial,Bold=1,PrimaryColour=&H00FFFF,BorderStyle=0,Outline=0,Shadow=0,MarginV=20" | |
| # Function to encode a single file | |
| encode_file() { | |
| local input_file="$1" | |
| local subtitle_lang="${2:-eng}" | |
| local output_dir="${3:-./miyoo_encoded}" | |
| local black_white="${4:-false}" | |
| # Create output directory | |
| mkdir -p "$output_dir" | |
| # Get filename without extension | |
| local basename=$(basename "$input_file") | |
| local name="${basename%.*}" | |
| local suffix="_miyoo" | |
| # Add BW suffix if black and white mode | |
| if [[ "$black_white" == "true" ]]; then | |
| suffix="_miyoo_bw" | |
| fi | |
| local output_file="$output_dir/${name}${suffix}.mp4" | |
| echo "Encoding: $input_file" | |
| echo "Output: $output_file" | |
| echo "Subtitle language: $subtitle_lang" | |
| if [[ "$black_white" == "true" ]]; then | |
| echo "Filter: Black & White" | |
| fi | |
| # Check if file has embedded subtitles | |
| local has_subs=$(ffprobe -v quiet -select_streams s -show_entries stream=codec_name -of csv=p=0 "$input_file" 2>/dev/null | wc -l) | |
| # Look for external subtitle files | |
| local input_dir=$(dirname "$input_file") | |
| local srt_file="" | |
| # Try to find matching .srt file | |
| local subtitle_upper=$(echo "$subtitle_lang" | tr '[:lower:]' '[:upper:]') | |
| for ext in srt SRT; do | |
| for pattern in "${name}" "${name}*${subtitle_upper}" "${name}*${subtitle_lang}" "${name}*ENG" "${name}*eng"; do | |
| if [[ -f "$input_dir/$pattern.$ext" ]]; then | |
| srt_file="$input_dir/$pattern.$ext" | |
| break 2 | |
| fi | |
| done | |
| done | |
| # Build FFmpeg command | |
| local ffmpeg_cmd="ffmpeg -i \"$input_file\"" | |
| local filter_complex="" | |
| local map_args="-map 0:v:0 -map 0:a:0" | |
| # Build filter chain | |
| local video_filters="scale=${TARGET_WIDTH}:${TARGET_HEIGHT}:force_original_aspect_ratio=increase,crop=${TARGET_WIDTH}:${TARGET_HEIGHT}" | |
| # Add black and white filter if requested | |
| if [[ "$black_white" == "true" ]]; then | |
| video_filters="${video_filters},hue=s=0" | |
| fi | |
| # Add subtitle burning with readable styling | |
| if [[ $has_subs -gt 0 ]]; then | |
| # Use embedded subtitles | |
| filter_complex="[0:v]${video_filters},subtitles='$input_file':si=0:force_style='$SUB_STYLE'[v]" | |
| map_args="-map [v] -map 0:a:0" | |
| elif [[ -n "$srt_file" ]]; then | |
| # Use external subtitle file | |
| filter_complex="[0:v]${video_filters},subtitles='$srt_file':force_style='$SUB_STYLE'[v]" | |
| map_args="-map [v] -map 0:a:0" | |
| else | |
| # No subtitles found, just apply video filters | |
| filter_complex="[0:v]${video_filters}[v]" | |
| map_args="-map [v] -map 0:a:0" | |
| echo "Warning: No subtitles found for $input_file" | |
| fi | |
| # Execute FFmpeg command | |
| eval "$ffmpeg_cmd -filter_complex \"$filter_complex\" $map_args -c:v libx264 -preset medium -crf 28 -b:v $BITRATE -maxrate $BITRATE -bufsize $(echo $BITRATE | sed 's/k$//')k -c:a aac -b:a $AUDIO_BITRATE -ac 2 -ar 44100 -movflags +faststart -y \"$output_file\"" | |
| echo "Completed: $output_file" | |
| echo "File size: $(du -h "$output_file" | cut -f1)" | |
| echo "" | |
| } | |
| # Function to process a directory | |
| process_directory() { | |
| local input_dir="$1" | |
| local subtitle_lang="${2:-eng}" | |
| local output_dir="${3:-./miyoo_encoded}" | |
| local black_white="${4:-false}" | |
| echo "Processing directory: $input_dir" | |
| # Find all video files, including webm | |
| find "$input_dir" -type f \( -iname "*.mkv" -o -iname "*.mp4" -o -iname "*.avi" -o -iname "*.mov" -o -iname "*.m4v" -o -iname "*.webm" \) | while read -r file; do | |
| # Skip sample files and partial downloads | |
| local basename=$(basename "$file") | |
| if [[ "$basename" =~ ^[Ss]ample ]] || [[ "$basename" =~ \.part$ ]] || [[ "$basename" =~ \.mhtml$ ]]; then | |
| echo "Skipping: $file" | |
| continue | |
| fi | |
| # Auto-detect Matrix for black and white treatment | |
| local use_bw="$black_white" | |
| if [[ "$basename" =~ [Mm]atrix ]] && [[ "$black_white" == "auto" ]]; then | |
| use_bw="true" | |
| echo "Auto-detected Matrix - applying black & white filter" | |
| fi | |
| encode_file "$file" "$subtitle_lang" "$output_dir" "$use_bw" | |
| done | |
| } | |
| # Main script logic | |
| main() { | |
| local input_path="$1" | |
| local subtitle_lang="${2:-eng}" | |
| local output_dir="${3:-./miyoo_encoded}" | |
| local black_white="false" | |
| # Parse additional arguments | |
| shift 3 2>/dev/null || true | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| --bw|--black-white) | |
| black_white="true" | |
| shift | |
| ;; | |
| --auto-bw) | |
| black_white="auto" | |
| shift | |
| ;; | |
| *) | |
| echo "Unknown option: $1" | |
| shift | |
| ;; | |
| esac | |
| done | |
| if [[ -z "$input_path" ]]; then | |
| echo "Miyoo Mini Movie Encoder - Enhanced" | |
| echo "Usage: $0 [input_file_or_folder] [subtitle_language_code] [output_directory] [options]" | |
| echo "" | |
| echo "Examples:" | |
| echo " $0 movie.mkv eng" | |
| echo " $0 /path/to/movies/ eng ./encoded" | |
| echo " $0 matrix.mkv eng ./output --bw" | |
| echo " $0 /path/to/movies/ eng ./output --auto-bw" | |
| echo "" | |
| echo "Options:" | |
| echo " --bw, --black-white Convert to black and white" | |
| echo " --auto-bw Auto-detect Matrix films for B&W conversion" | |
| echo "" | |
| echo "Supported subtitle languages: eng, por, fre, ger, spa, etc." | |
| echo "Supported formats: mkv, mp4, avi, mov, m4v, webm" | |
| exit 1 | |
| fi | |
| if [[ ! -e "$input_path" ]]; then | |
| echo "Error: Input path does not exist: $input_path" | |
| exit 1 | |
| fi | |
| # Check if FFmpeg is installed | |
| if ! command -v ffmpeg &> /dev/null; then | |
| echo "Error: FFmpeg is not installed. Please install FFmpeg first." | |
| exit 1 | |
| fi | |
| echo "Miyoo Mini Movie Encoder - Enhanced" | |
| echo "===================================" | |
| echo "Target resolution: ${TARGET_WIDTH}x${TARGET_HEIGHT}" | |
| echo "Video bitrate: $BITRATE" | |
| echo "Audio bitrate: $AUDIO_BITRATE" | |
| echo "Subtitle language: $subtitle_lang" | |
| echo "Output directory: $output_dir" | |
| if [[ "$black_white" == "true" ]]; then | |
| echo "Filter: Black & White enabled" | |
| elif [[ "$black_white" == "auto" ]]; then | |
| echo "Filter: Auto-detect Matrix for B&W" | |
| fi | |
| echo "" | |
| if [[ -f "$input_path" ]]; then | |
| # Single file | |
| encode_file "$input_path" "$subtitle_lang" "$output_dir" "$black_white" | |
| elif [[ -d "$input_path" ]]; then | |
| # Directory | |
| process_directory "$input_path" "$subtitle_lang" "$output_dir" "$black_white" | |
| else | |
| echo "Error: Input path is neither a file nor a directory: $input_path" | |
| exit 1 | |
| fi | |
| echo "All encoding completed!" | |
| } | |
| # Run main function with all arguments | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment