Skip to content

Fix spherical MP4 metadata preservation with FFmpeg 7 - #1109

Open
rajeshgk wants to merge 1 commit into
OpenShot:developfrom
rajeshgk:fix/spherical-metadata-ffmpeg7-1083
Open

rajeshgk wants to merge 1 commit into
OpenShot:developfrom
rajeshgk:fix/spherical-metadata-ffmpeg7-1083

Conversation

@rajeshgk

Copy link
Copy Markdown

Summary

Fixes the loss of spherical video metadata when exporting MP4 files using FFmpeg 7.

The change preserves spherical coded side data across codec parameter initialization, ensuring that exported MP4 files retain their spherical projection and orientation information.

Root cause

On FFmpeg 7, FFmpegWriter::AddSphericalMetadata() attaches AV_PKT_DATA_SPHERICAL to the output stream's codecpar->coded_side_data.

A subsequent call to avcodec_parameters_from_context() during FFmpegWriter::open_video() clears the previously attached coded side data.

Consequently, the spherical metadata is lost before the MP4 muxer writes the output file.

Fix

  • Preserve spherical coded side data before copying codec parameters.
  • Restore the metadata after avcodec_parameters_from_context() completes.
  • Apply the preservation logic for FFmpeg/libavformat 61 and newer.
  • Retain existing behavior for older FFmpeg versions.

Regression testing

Added tests/SphericalMetadata.cpp, which independently inspects MP4 sv3d/proj/prhd boxes and verifies the exported orientation metadata.

Tested orientations:

Yaw Pitch Roll
30° 0° 0°
45° 30° 15°
-90° -30° -15°

Environment: GCC 15, FFmpeg 7.1.1, Linux.

Result: All 12 assertions passed in 1 test case.

The complete libopenshot build also succeeded.

Scope

This is an independent fix based directly on OpenShot/libopenshot:develop. It does not depend on PR #1088.

Related to #1083.

Preserve AV_PKT_DATA_SPHERICAL across codec parameter copying in FFmpegWriter when using libavformat 61 or newer.

Add MP4 structural regression coverage for positive, zero, and negative yaw, pitch, and roll values.
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