locked
IMFSourceReader get wrong video resolution RRS feed

  • Question

  • Hi guys,

    I'm using IMFSourceReader to read H.264 encoded video frames from a mp4 file. Sample file is here https://www.dropbox.com/s/hrbq4n9e2o8rdzt/a.mp4?dl=0

    My code is here:

    #include "stdafx.h"
    #include <Winerror.h>
    #include <Objbase.h>
    #include <Mfidl.h>
    #include <Mfapi.h>
    #include <Mfreadwrite.h>
    #include <Dvdmedia.h>
    #include <Strmif.h>
    #include <uuids.h>
    #include <Dshow.h>
    
    int _tmain(int argc, _TCHAR* argv[])
    {   
        const WCHAR *szFilePath = L"C:\\Users\\hxuan\\Desktop\\a.mp4";   
        HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); 
        do {
            hr = MFStartup(MF_VERSION, 0);      
            if (FAILED(hr)) break;      
    
            // Get reader      
            IMFSourceReader *pReader;      
            hr = MFCreateSourceReaderFromURL(szFilePath, NULL, &pReader);
            if (FAILED(hr)) break;      
    
            // Enum video media types       
            int i = 0;      
            do {         
                IMFMediaType *pType = NULL;         
                hr = pReader->GetNativeMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, i++, &pType);         
                if (SUCCEEDED(hr))  {
                    AM_MEDIA_TYPE* pmt;
                    hr = pType->GetRepresentation(FORMAT_VideoInfo2, (void**)(&pmt));      
                    if (SUCCEEDED(hr)) {
                        VIDEOINFOHEADER2* pvih = (VIDEOINFOHEADER2*)(pmt->pbFormat); 
                        if (pmt->subtype == MEDIASUBTYPE_H264) {
                            printf("it's H.264 video, resolution = %dx%d\n", pvih->bmiHeader.biWidth, pvih->bmiHeader.biHeight);               
                        }            
                    }
                }
            } while (SUCCEEDED(hr));   
        } while (false);   
        printf("exit -- fail-----------------\n");	
        return 0;
    }

    using ffprobe we can see  the pixel format is yuv444p, but my program above prints that the resolution is 88x88. If this pixel format is not supported by Windows Media Foundation H.264 decoder, shouldn't it fail directly instead of returning something wrong? Any one has idea about it? Thanks

    $ ffprobe a.mp4
    ffprobe version N-86669-gc1d1274 Copyright (c) 2007-2017 the FFmpeg developers
     
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf57.75.100
      Duration: 00:00:01.00, start: 0.000000, bitrate: 17 kb/s
        Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 100x100, 8 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
        Metadata:
          handler_name    : VideoHandler



    • Edited by azzurro1994 Wednesday, July 5, 2017 8:01 AM
    Wednesday, July 5, 2017 7:52 AM

All replies