如何确定 mpeg-2 节目流文件的视频尺寸

发布于 2024-07-09 00:57:32 字数 127 浏览 12 评论 0原文

如何以编程方式找出 mpeg-2 transport 程序流文件中视频的宽度和高度?

编辑:我正在使用 C++,但很高兴获得任何语言的示例。 编辑:更正问题 - 我问的可能是程序流

How do I programmatically find out the width and height of the video in an mpeg-2 transport program stream file?

Edit: I am using C++, but am happy for examples in any language.
Edit: Corrected question - it was probably program streams I was asking about

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

画骨成沙 2024-07-16 00:57:32

查看 libmpeg2(F/OSS MPEG2 解码器)的源代码。 宽度和高度似乎是在 header.c 中的 mpeg2_header_sequence() 函数中设置的。 不过,我不确定控制如何流向该特定功能。 我建议使用 libmpeg2 (例如 MPlayer)打开 MPEG2 文件并附加调试器来查看更准确地说它正在做什么。

Check out the source code to libmpeg2, a F/OSS MPEG2 decoder. It appears that the width and height are set in the mpeg2_header_sequence() function in header.c. I'm not sure how control flows to that particular function, though. I'd suggest opening up an MPEG2 file in something using libmpeg2 (such as MPlayer) and attaching a debugger to see more closely exactly what it's doing.

゛时过境迁 2024-07-16 00:57:32

如果你使用的是DirectX,VMRWindowlessControl接口中有一个方法:

piwc->GetNativeVideoSize(&w, &h, NULL, NULL);

或者IBasicVideo接口:

pivb->GetVideoSize(&w, &h);

If you are using DirectX, there is a method in the VMRWindowlessControl interface:

piwc->GetNativeVideoSize(&w, &h, NULL, NULL);

Or the IBasicVideo interface:

pivb->GetVideoSize(&w, &h);
无可置疑 2024-07-16 00:57:32

对于 MPEG2 视频,水平和水平方向 垂直尺寸可以在视频序列头(来自视频比特流)中找到。 序列头代码为0x000001B3。 下面是一些示例代码。 但是,如果在序列扩展标头中指定,则它不会考虑水平/垂直尺寸扩展。

#define VIDEO_SEQUENCE_HDR  0xB3
#define HOR_SIZE_MASK       0xFFF00000
#define HOR_SIZE_SHIFT      20
#define VER_SIZE_MASK       0x000FFF00
#define VER_SIZE_SHIFT      8

unsigned char *pTmp = tsPacket;
int len = 188;
int horizontal, vertical;

 while(len>0 && !horizontal && !vertical)
 {        
        if(*pTmp == 0 && *(pTmp+1) == 0
           && *(pTmp+2)== 0x01 && *(pTmp+3) == 0xB3 && (len-1) >0)
        {
            unsigned int *pHdr = (unsigned int *)pTmp;    
            pHdr++ ; 
            unsigned int secondByte = ntohl(*pHdr);
            horizontal = (secondByte & HOR_SIZE_MASK) >> HOR_SIZE_SHIFT;
            vertical = (secondByte & VER_SIZE_MASK) >> VER_SIZE_SHIFT;           
            break;
        }
        pTmp++;
        len--;
    }

for MPEG2 Video the horizontal & vertical size can be found in the Video Sequence Header (from the video bit stream). The sequence header code is 0x000001B3. Some example code below. However it does not take into account the horizontal/vertical size extension if specified in sequence extension header.

#define VIDEO_SEQUENCE_HDR  0xB3
#define HOR_SIZE_MASK       0xFFF00000
#define HOR_SIZE_SHIFT      20
#define VER_SIZE_MASK       0x000FFF00
#define VER_SIZE_SHIFT      8

unsigned char *pTmp = tsPacket;
int len = 188;
int horizontal, vertical;

 while(len>0 && !horizontal && !vertical)
 {        
        if(*pTmp == 0 && *(pTmp+1) == 0
           && *(pTmp+2)== 0x01 && *(pTmp+3) == 0xB3 && (len-1) >0)
        {
            unsigned int *pHdr = (unsigned int *)pTmp;    
            pHdr++ ; 
            unsigned int secondByte = ntohl(*pHdr);
            horizontal = (secondByte & HOR_SIZE_MASK) >> HOR_SIZE_SHIFT;
            vertical = (secondByte & VER_SIZE_MASK) >> VER_SIZE_SHIFT;           
            break;
        }
        pTmp++;
        len--;
    }
浮华 2024-07-16 00:57:32

hamishmcn 表示 Adam Rosenfield 的答案正是他所需要的。 这让我怀疑这个问题的准确性。 MPEG 传输流没有具有视频序列标头。 该标头可在 MPEG 节目流中找到。

我没有答案。 我只是希望有人的答案是正确的,因为我需要一个。

hamishmcn said that Adam Rosenfield's answer was what he needed. This makes me wonder about the accuracy of the question. An MPEG transport stream doesn't have a video sequence header. That header is found in an MPEG program stream.

I don't have an answer. I was just hoping against hope that someone's answer was correct, because I need one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文