Skip to content

feat: fall back to system ffmpeg when OpenCV can't decode the video - #460

Open
minh-vt wants to merge 7 commits into
YaoFANGUK:mainfrom
minh-vt:feat/ffmpeg-fallback-reader
Open

feat: fall back to system ffmpeg when OpenCV can't decode the video#460
minh-vt wants to merge 7 commits into
YaoFANGUK:mainfrom
minh-vt:feat/ffmpeg-fallback-reader

Conversation

@minh-vt

@minh-vt minh-vt commented Jul 10, 2026

Copy link
Copy Markdown

Problem

OpenCV's bundled FFmpeg (opencv-python pip package) doesn't support AV1, HEVC/H.265, or VP9. Opening an AV1-encoded video shows:

[ERROR:0] global cap_ffmpeg_impl.hpp:1309 open
Could not open codec av1, error: -1163346256

The app is completely unusable for these videos. The existing "Video Decoder" setting in Settings only affects VideoSubFinder's internal decoder, not OpenCV.

Solution

Adds backend/tools/ffmpeg_reader.py — a sequential frame reader using system ffmpeg pipe with a cv2.VideoCapture-compatible API (isOpened(), get(), set(), read(), release()).

Three entry points automatically fall back to ffmpeg when OpenCV fails:

Location Purpose
ui/home_interface.py:load_video Video preview slider
backend/main.py:SubtitleExtractor.__init__ Processing metadata + frame extraction
backend/tools/subtitle_ocr.py:ocr_task_producer OCR pipeline frame reading

Each tries cv2.VideoCapture(path) first (fast for H.264). If isOpened() returns False, it falls back to FFmpegReader(path) using system ffmpeg. No settings to toggle — automatic.

Files changed

  • backend/tools/ffmpeg_reader.py (new, ~110 lines)
  • backend/main.py (+6 lines)
  • backend/tools/subtitle_ocr.py (+6 lines)
  • ui/home_interface.py (+5 lines)
    `

minh-vt added 7 commits July 7, 2026 03:18
VSF crops frames to the subtitle region before sending them to OCR.
The OCR filter compares detection coordinates (relative to cropped image)
against the subtitle area (relative to original full frame), causing
all detections to fail intersection checks with 'Out of selection'.

Fix: pass filter_sub_area=None when VSF is used, since VSF already
filters by cropping. DET and FPS modes continue to use the subtitle
area for filtering as before.
Adds FFmpegReader — a cv2.VideoCapture-compatible reader using system ffmpeg.
Supports AV1, HEVC, VP9, and any other codec OpenCV's bundled ffmpeg omits.

- Detects OpenCV failure via isOpened()
- Falls back to FFmpegReader automatically
- Sequential pipe reading for the OCR pipeline
- Forward-only seeking via frame skipping
ffmpeg's auto-selection tries hardware decode for AV1 on this platform,
which fails with 'Failed to get pixel format' and 'Missing Sequence Header'.
Force the libdav1d software decoder when codec is AV1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant