You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GStreamer获取视频轨道的净光圈与编码尺寸?

解决方案

获取编码尺寸

GstDiscovererVideoInfo封装了底层的GstVideoInfo结构,你可以通过它直接提取编码维度:

g_autoptr(GstDiscovererVideoInfo) video_info = GST_DISCOVERER_VIDEO_INFO(stream_iter->data);
const GstVideoInfo *base_info = gst_discoverer_video_info_get_video_info(video_info);

// 提取编码宽高
video_metadata[EncodedWidth] = std::to_string(gst_video_info_get_encoded_width(base_info));
video_metadata[EncodedHeight] = std::to_string(gst_video_info_get_encoded_height(base_info));

获取净光圈(Clean Aperture)

净光圈信息存储在视频流的Caps结构中,需要从GstDiscovererVideoInfo中提取Caps后,解析对应的字段:

GstCaps *caps = gst_discoverer_video_info_get_caps(video_info);
GstStructure *caps_struct = gst_caps_get_structure(caps, 0);

gint ca_width, ca_height, ca_x_offset, ca_y_offset;

// 先检查字段是否存在,再提取参数
if (gst_structure_get_int(caps_struct, "clean-aperture-width", &ca_width) &&
    gst_structure_get_int(caps_struct, "clean-aperture-height", &ca_height) &&
    gst_structure_get_int(caps_struct, "clean-aperture-x-offset", &ca_x_offset) &&
    gst_structure_get_int(caps_struct, "clean-aperture-y-offset", &ca_y_offset)) {
    video_metadata[CleanApertureWidth] = std::to_string(ca_width);
    video_metadata[CleanApertureHeight] = std::to_string(ca_height);
    video_metadata[CleanApertureXOffset] = std::to_string(ca_x_offset);
    video_metadata[CleanApertureYOffset] = std::to_string(ca_y_offset);
} else {
    // 处理无净光圈信息的情况,比如设默认值或跳过该字段
}

关键提示

  • 并非所有视频都会携带净光圈数据,必须通过gst_structure_get_int的返回值判断字段是否存在,避免非法访问。
  • 编码尺寸是视频编码时的原始帧大小,和你之前获取的显示宽高可能存在差异,这通常和像素宽高比(pixel aspect ratio)有关。

内容的提问来源于stack exchange,提问作者ZZak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 11:42:38