Hi, I am reading SD PAL sized avi files that are 4:3 and 16:9 display aspect ratio but am not able to read this from the file.
When I call MFGetAttributeRatio() with GUID MF_MT_PIXEL_ASPECT_RATIO this returns 1:1. The MFVideoFormat also contains 1:1 and the aspect ratio in VideoInfo2 is 5:4 for both 4:3 and 16:9. I understand that the aspect ratio in VideoInfo2 is the storage aspect ratio and that I need the pixel aspect ratio and by multiplying this with the storage aspect ratio this then gives the display aspect ratio but I have not been successful in reading this value. Also the interlaced field is always progressive which is incorrect, it should be interlaced.
Analysing the output from MFTrace when attached to windows media player on Windows 7 I can see that the MF_MT_PIXEL_ASPECT_RATIO value on calls to setInputType and setOutputType will change from 1,1 to 16,15 and then 64,45, the latter when multiplied with 5:4 gives 16:9.
I have started using media foundation and have read the article: http://msdn.microsoft.com/en-us/library/bb530115(v=VS.85).aspx
but this does not explain how I obtain the source display aspect ratio I am after.
Any suggestions and help much appreciated as I think I am not the only person who is struggling with this. To give a little more information I am using Media Foundation to import AVI files into our editor software and I can read all other video information such as size and frame rate but need to know the interlace mode and display aspect ratio before reading the samples into our application.
The pixel aspect ratio is for the shape of the pixels and not the shape of the entire image. Pixels in most videos are square, hence the 1:1 you are getting.
To get the aspect ratio of of the entire image, you divide the video width by the video height. That is by definition the aspect ratio of the image. An example is 1920x1080. If you divide the width and height you get 1920/1080 which simplifies to 16/9 and hence 16:9. 640x480 is 640/480 -> 4/3 -> 4:3.
Yes that is correct but a video file can have different display aspect ratios such as 4:3 or 16:9 in SD (720x576 for PAL) so 720x576 gives 5:4 which is the dimension in pixels and is the storage aspect ratio and I observe this value in the VideoInfo2 header information but retrieving the MF_MT_PIXEL_ASPECT_RATIO value is always 1:1 even after I call SetCurrentMediaType to YUV2 media type or query the native media type. For HD video this is not an issue as HD always uses square pixels but SD video clips do not. So I would like to know how to query this information including the correct interlace mode as this property is always progressive which is also incorrect. I do not understand why the dimensional information and FPS is populated and not the pixel aspect ratio or interlace modes correctly. Is there something I am missing from setting up the media source?
I'm not entirely convinced that the pixel aspect ratio is/should be used in this scenario. You're talking about taking an image with certain dimensions and playing it back with a different aspect ratio. You would consider this anamorphic playback. With standard definition in particular, you'll see this circumstance where 16:9 analog video is delivered in a 4:3 frame structure but should be played back at 16:9 to preserve the nature of the video otherwise it looks vertically distorted. This behaviour is not synonymous with pixel shape unless it is a characteristic of the digital stream you are reading from a device.
I could be wrong but pixel aspect ratio is used more for the general structure and interpretation of pixel information in media so that it is not displayed as garbage. When you play the media back in other media players, is it displayed with the intended ratio you have described? Is the playback letterboxed or stretched?
Well Quicktime does not display the 16:9 file correctly so it is squashed. Windows Media Player 11 displays the 16:9 file with black bars so letterboxed, this is preserved even when you resize the playback window and for the 4:3 file it is also displayed in the correct aspect ratio. I think that VLC also plays both files correctly. When I run the Topoedit SDK sample and I initially drop the 16:9 clip, the connection to the input node of the Video Renderer (display window) shows that the MF_MT_PIXEL_ASPECT_RATIO is 16:15 initially (this is also true for the 4:3 file). When I play this clip and stop the playback and look at this property again, the value changes to 64:45 for the 16:9 file and for the 4:3 file it stays at 16:15. So how and why does this value change after playback for the 16:9 file? Is this something that it necessary in order to obtain the correct display aspect ratio?
I can't say that I've pursued the avenue of playback compatibility that you have. However, after reading your problem, checking out your references and going by my own experiences I can only offer the following advice:
-Using the pixel aspect ratio of the EVR doesn't help. This is typically the ratio of the display window dimensions and the source video resolution. If you change the size of the playback window, the PAR of the EVR should change.
-Display Aspect Ratio(DAR) and Picture Aspect Ratio, within the scope of media foundation, are one-in-the-same. This is the width and height of the source video and nothing else
-If the Pixel Aspect Ratio of the media source is 1:1 then the pixels are supposed to be interpreted as squares. If your source reader reports 1:1 in the native media type then this is the case unless there is a major bug/error with media foundation itself.
-If the video is 4:3 but should be played back at 16:9(Anamorphic 16:9) and this is not reflected via the pixel aspect ratio, I cannot think of any other media type attributes within Media Foundation that will accomodate this.
If you want to know for sure whether or not your media container type supports the concept of variable display aspect ratios. Try inspecting media properties of the file with VLC media player or Quicktime Movie Inspector. If these players suggest that there is a discrepency between the media resolution and its intended playback resolution but Media Foundation does not support this, you should lodge a request to support this feature.
Could you please tell me more about the media you are playing back? What container format is it? AVI, MP4, MOV etc. What encoding/compression technologies does it use? uncompressed, DV, H264, MPEG2 etc.
The files are all AVI container files, I had several files some encoded using DV and other using Canopus HQ, quicktime fails to play the 16:9 aspect ratio clip correctly for DV, I don't remember if VLC fails or not, it certainly fails to play the Canopus encoded clip as it does not recognise the fourCC code. This does seem to be a failing of media foundation but I have also found that direct show does not give me the correct aspect ratio, it too reports 4:3 for both 4:3 and 16:9 clips. Also I think I cannot use media foundation because it cannot load the direct show filter necessary to decode Canopus, something I was not sure of until I tried to render the file using Topoedit. Part of the problem is that AVI does not have a standardised specification for storing pixel aspect and interlaced information, this would explain why apps like media info and G-Spot report different things when I try to analyse my AVI clips. Thank you for all your responses but the fact that I cannot decode Canopus encoded files means I ultimately cannot use media foundation anyway.