Visualization - Enhance FFmpeg Compatibility Layer and Update Video Recorder#582
Visualization - Enhance FFmpeg Compatibility Layer and Update Video Recorder#582dpasukhi merged 5 commits intoOpen-Cascade-SAS:IRfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new FFmpeg compatibility layer and updates the video recorder and codec context management to support both FFmpeg 4.x and 5.x (and newer) APIs. Key changes include:
- Creation of Media_FFmpegCompatibility.pxx to wrap deprecated functions and API changes.
- Refactoring of Media_FormatContext and Media_CodecContext to use the new compatibility layer.
- Updates to Image_VideoRecorder and its tests to leverage the new compatibility functions and ensure proper codec context handling.
Reviewed Changes
Copilot reviewed 31 out of 33 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Visualization/TKService/Media/Media_FormatContext.cxx | Uses conditional compilation for new FFmpeg API usage and protocol for codec context initialization. |
| src/Visualization/TKService/Media/Media_FFmpegCompatibility.pxx | New file providing macros and inline functions to bridge changes between FFmpeg versions. |
| src/Visualization/TKService/Media/Media_CodecContext.cxx | Updates codec context allocation, parameter copying, and cleanup based on FFmpeg version. |
| src/Visualization/TKService/Media/FILES.cmake | Updated file list to include the new compatibility layer. |
| src/Visualization/TKService/Image/Image_VideoRecorder.hxx | Added getCodecContext() and new member for codec context; updated documentation. |
| src/Visualization/TKService/Image/Image_VideoRecorder.cxx | Updated video codec initialization and frame encoding to use new compatibility functions. |
| src/Visualization/TKService/GTests/Image_VideoRecorder_Test.cxx | New tests that validate the updated video recorder behavior. |
| Other files | Various build and vcpkg patches; updated GitHub action to enable FFmpeg. |
| if (myVideoCodec == ffmpeg_find_encoder_by_name("mpeg2video")) | ||
| { | ||
| // just for testing, we also add B frames | ||
| aCodecCtx->max_b_frames = 2; | ||
| aCodecCtx->bit_rate = 6000000; | ||
| } | ||
| else if (aCodecCtx->codec == avcodec_find_encoder_by_name("mpeg4")) | ||
| else if (myVideoCodec == ffmpeg_find_encoder_by_name("mpeg4")) | ||
| { | ||
| // | ||
| } | ||
| else if (aCodecCtx->codec == avcodec_find_encoder_by_name("mjpeg")) | ||
| else if (myVideoCodec == ffmpeg_find_encoder_by_name("mjpeg")) | ||
| { | ||
| aCodecCtx->pix_fmt = AV_PIX_FMT_YUVJ420P; | ||
| aCodecCtx->qmin = aCodecCtx->qmax = 5; | ||
| } | ||
| else if (aCodecCtx->codec == avcodec_find_encoder_by_name("huffyuv")) | ||
| else if (myVideoCodec == ffmpeg_find_encoder_by_name("huffyuv")) |
There was a problem hiding this comment.
[nitpick] To improve maintainability and avoid potential side effects from repeated function calls, consider caching the result of ffmpeg_find_encoder_by_name("mpeg2video") (and similarly for other codec names) in a local variable before performing comparisons.
| #if FFMPEG_NEW_API | ||
| myCodecCtx = avcodec_alloc_context3(NULL); | ||
| #else | ||
| myCodecCtx = avcodec_alloc_context3(NULL); | ||
| #endif |
There was a problem hiding this comment.
Seems like both branches of the macro are doing the same. Is there any reason to have the macro here?
There was a problem hiding this comment.
No, no reason for now.
Thank you.
| #if FFMPEG_NEW_API | ||
| avcodec_flush_buffers(myCodecCtx); | ||
| #else | ||
| avcodec_flush_buffers(myCodecCtx); | ||
| #endif |
There was a problem hiding this comment.
Seems like both branches of the macro are doing the same. Is there any reason to have the macro here?
There was a problem hiding this comment.
No, no reason for now.
Thank you.
…ecorder - Introduced a new compatibility layer (Media_FFmpegCompatibility.pxx) to handle differences between FFmpeg versions 4.x and 5.x, including deprecated functions and API changes. - Updated Image_VideoRecorder to utilize the new compatibility functions for codec context management and video encoding. - Refactored Media_CodecContext and Media_FormatContext to integrate compatibility functions, ensuring seamless operation across FFmpeg versions. - Replaced deprecated FFmpeg functions with their modern counterparts, improving code maintainability and future-proofing. - Added checks for codec context allocation and parameter copying based on FFmpeg version, enhancing robustness. - Improved error handling and logging for codec operations, providing clearer feedback on failures.
…and updating API usage
…bility and code consistency
Uh oh!
There was an error while loading. Please reload this page.