How to determine the size of the video file stream program mpeg-2

How to programmatically find out the width and height of a video in the mpeg-2 transport stream file ?

Edit: I am using C ++, but I am happy with the examples in any language. Edit: The fixed question is probably the program threads I was asking about

+3
source share
5 answers

Check the source code for libmpeg2 , the MPEG2 F / OSS decoder. It appears that the width and height are given in function mpeg2_header_sequence()c header.c. However, I am not sure that control is moving to this particular function. I would suggest opening the MPEG2 file in something using libmpeg2 (like MPlayer ) and attaching a debugger to see more precisely what it does.

+3
source

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

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

Or the IBasicVideo interface:

pivb->GetVideoSize(&w, &h);
+1
source

MPEG2 Video ( ). 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--;
    }
+1

hamishmcn said Adam Rosenfield's answer was what he needed. This makes me wonder about the accuracy of the question. MPEG transport stream does not havevideo title This header is in the MPEG program stream.

I have no answer. I just hoped that someone would answer correctly, because I need it.

0
source

Source: https://habr.com/ru/post/1699512/


All Articles