Skip to content

Visualization - Enhance FFmpeg Compatibility Layer and Update Video Recorder#582

Merged
dpasukhi merged 5 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi:ffmpeg_patch
Jun 27, 2025
Merged

Visualization - Enhance FFmpeg Compatibility Layer and Update Video Recorder#582
dpasukhi merged 5 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi:ffmpeg_patch

Conversation

@dpasukhi
Copy link
Copy Markdown
Member

@dpasukhi dpasukhi commented Jun 22, 2025

  • 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.

@dpasukhi dpasukhi linked an issue Jun 22, 2025 that may be closed by this pull request
4 tasks
@dpasukhi dpasukhi changed the title Visualization - Enhance FFmpeg Compatibility Layer and Update Video R… Visualization - Enhance FFmpeg Compatibility Layer and Update Video Recorder Jun 22, 2025
@dpasukhi dpasukhi marked this pull request as ready for review June 22, 2025 23:31
@dpasukhi dpasukhi added this to the Release 8.0 milestone Jun 23, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +328 to +343
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"))
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copilot uses AI. Check for mistakes.
@dpasukhi dpasukhi added 2. Enhancement New feature or request 1. Visualization AIS cases, animation, ray-tracing, viewer integration into external software and etc... 1. Configuration CMake/QMake processes of OCCT or samples labels Jun 23, 2025
Comment on lines +44 to +48
#if FFMPEG_NEW_API
myCodecCtx = avcodec_alloc_context3(NULL);
#else
myCodecCtx = avcodec_alloc_context3(NULL);
#endif
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like both branches of the macro are doing the same. Is there any reason to have the macro here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no reason for now.
Thank you.

Comment on lines +204 to +208
#if FFMPEG_NEW_API
avcodec_flush_buffers(myCodecCtx);
#else
avcodec_flush_buffers(myCodecCtx);
#endif
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like both branches of the macro are doing the same. Is there any reason to have the macro here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no reason for now.
Thank you.

dpasukhi added 4 commits June 27, 2025 09:24
…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.
@dpasukhi dpasukhi requested a review from AtheneNoctuaPt June 27, 2025 08:27
@github-project-automation github-project-automation bot moved this from Todo to Integration in Maintenance Jun 27, 2025
@dpasukhi dpasukhi merged commit 22d437b into Open-Cascade-SAS:IR Jun 27, 2025
34 checks passed
@dpasukhi dpasukhi deleted the ffmpeg_patch branch June 27, 2025 13:38
@github-project-automation github-project-automation bot moved this from Integration to Done in Maintenance Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1. Configuration CMake/QMake processes of OCCT or samples 1. Visualization AIS cases, animation, ray-tracing, viewer integration into external software and etc... 2. Enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

VCPKG Manifest mode support

3 participants