How to Fix FFmpeg Subtitle Errors
In this tutorial, you'll learn about How to Fix FFmpeg Subtitle Errors. We cover key concepts, practical examples, and best practices.
The Problem
FFmpeg fails to process subtitles with Subtitle encoding not supported, Fontconfig error: Cannot find default font, or Bitmap subtitles not supported by this muxer. Subtitles are either missing, garbled, or incorrectly formatted in the output.
Quick Fix
Fix 1: Bitmap Subtitles (PGS/DVD) Not Supported
WRONG — copying bitmap subtitles to output:
ffmpeg -i input.mkv -c copy output.mp4
# Could not write codec 'hdmv_pgs_subtitle': Bitmap subtitles codec not supported by muxer
RIGHT — remove the subtitle stream or convert to text:
# Remove subtitles:
ffmpeg -i input.mkv -c copy -sn output.mp4
# Convert to text-based (if SRT):
ffmpeg -i input.mkv -c:v copy -c:a copy -c:s mov_text output.mp4
Fix 2: Subtitle Encoding Issues (Corrupted Text)
ffmpeg -i input.mkv -c:s srt output.srt
# (output contains garbled characters)
RIGHT — specify the correct encoding:
ffmpeg -sub_charenc UTF-8 -i input.mkv -c:s srt output.srt
# (explicitly set UTF-8 encoding)
# For other encodings:
ffmpeg -sub_charenc CP1252 -i input.mkv -c:s srt output.srt
Fix 3: Hardcoding Subtitles (Burn-in)
ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt" output.mp4
WRONG — fontconfig error:
# Fontconfig error: Cannot find default font
RIGHT — specify the font path:
ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt:fontsdir=/usr/share/fonts" \
-c:v libx264 -c:a aac output.mp4
Or use ass format with a font:
ffmpeg -i input.mp4 -vf "ass=subtitles.ass" output.mp4
Fix 4: Extract Subtitles
# Extract all subtitle streams:
ffmpeg -i input.mkv -map 0:s:0 subtitles.srt
WRONG — extracting from a format without text subtitles:
ffmpeg -i input.mkv -map 0:s:0 output.srt
# (if the subtitle stream is PGS/binary, the output is corrupted)
RIGHT — check the subtitle codec first:
ffprobe input.mkv -show_streams -select_streams s
# Check codec_name: subrip (text), hdmv_pgs_subtitle (bitmap)
# For bitmap subtitles, OCR is needed:
Fix 5: OCR Bitmap Subtitles to Text
# Extract as SUP, then OCR:
ffmpeg -i input.mkv -map 0:s:0 subs.sup
Then use subtitleedit (not FFmpeg) for OCR.
Fix 6: Multiple Subtitle Streams
ffmpeg -i input.mkv -map 0:v -map 0:a -map 0:s:1 -c copy output.mkv
# (keeps only the second subtitle stream)
Use DodaTech's Subtitle Manager to extract, convert, and synchronize subtitles across multiple video files.
Prevention
- Check subtitle codec type with
ffprobebefore extracting. - Use
-snto strip subtitles when not needed. - Use
-c:s mov_textfor MP4 output,-c:s srtfor MKV. - Specify font path for hardcoded subtitles.
- Use the
assformat for styled subtitles.
Common Mistakes with subtitle error
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad
These mistakes appear frequently in real-world FFMPEG code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro