Files
opencv-MIRROR/modules/videoio/test
Harjoth Khara b3a6211a9b Merge pull request #30300 from harjothkhara:codex/opencv-30299-2026-10-14
videoio(ffmpeg): fix black frames for interlaced video 🤖🤖🤖 - #30300

Merge with https://github.com/opencv/opencv_extra/pull/1435

### Summary

With FFmpeg 8+, swscale rejects converting a frame flagged as interlaced into the progressive destination frame. The error returned by `sws_scale_frame()` was ignored, so `VideoCapture::read()` returned true with black frames.

The fix copies the interlaced/top-field-first flags from the source frame onto the destination frame (like FFmpeg's scale filter, which keeps the source field flags), and makes `retrieveFrame()` fail if `sws_scale_frame()` still returns an error.

Fixes #30299

### Testing

- macOS arm64, FFmpeg 9.0.2 / swscale 10.1.102.
- New test `videoio_ffmpeg.interlaced_frame_conversion_30299` (embedded fixture) fails before the change and passes after.
- Full `opencv_test_videoio` with opencv_extra testdata: 561/561 pass.
- The reporter's 5-frame tff clip now reads identical content to the progressive clip.

### Notes / limitations

- The error branch has no direct test, because the field-flag fix removes the only deterministic trigger.
- `VideoCapture::read()` still returns true with a reused non-empty Mat when retrieve fails. This is pre-existing behaviour for all backends and is not changed here.
- Older FFmpeg without `AV_FRAME_FLAG_INTERLACED` is unaffected.

Prepared with AI assistance (Claude Code); reviewed and tested by me.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
      (Accuracy test included with an embedded fixture; no opencv_extra patch needed.)
- [ ] The feature is well documented and sample code can be built with the project CMake
      (N/A: bug fix, no new API.)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-10-16 10:40:18 +03:00
..