使用 FFmpeg 从 HEVC 视频中读取 SEI 数据

Read SEI data from a HEVC video with FFmpeg

我一直在尝试使用 FFmpeg C++ 库和 x265 编码器以编程方式创建一些 HEVC 视频,使用 --master-display, --max-cll 和 x265 的其他 SEI 数据选项。现在,为了确保正确写入此信息,我想知道如何从生成的视频文件中读回此 SEI 数据,最好使用 FFmpeg C++ 库和函数。

我已经实现了一个视频解码器,它使用 av_read_frame() 并从每个 AVPacket 获得的帧中解码帧。我不确定在这个过程之前我是否可以通过这些数据包或类似的方法以某种方式获得 SEI 信息。

SEI 阅读代码存活 here, you can add debug messages to see if individual values are being read as expected. The consumer code for the sei bits is here, and it calculates the angle at which the video should be presented to the user. This is exported in AVFrame as display matrix side-data, which you can read using the API in display.h (source, doxy, annotated source)。

然后应用程序可以使用这个角度相应地旋转图像,例如使用 rotate avfilter.