VideoHelp Forum
+ Reply to Thread
Results 1 to 16 of 16
Thread
  1. I have a MP4 video with the following attributes:
    • Windows "frame width" and "frame height" metadata tags are 480 and 480
    • VLC plays the video in a square, that is, visually it is a ratio of 1:1
    • VLC plays the video with people tall and skinny
    • VLC shows codec information of: H264
    • VLC shows codec information of: video resolution: 480x480
    • VLC shows codec information of: buffer dimensions: 480x480
    • ffmpeg show the video information as: 480x480 [SAR 1:1 DAR 1:1]

    When I use this command (my version of ffmpeg: N-101923-gc012f9b265):
    Code:
    ffmpeg -i in.mp4 -vf setdar=16/9 out.mp4
    or
    Code:
    ffmpeg -i in.mp4 -aspect 16:9 out.mp4
    visually in VLC it looks right. But, when I look at the codec information in VLC and ffmpeg, I see:
    • VLC shows codec information of: video resolution: 480x480
    • VLC shows codec information of: buffer dimensions: 480x480
    • ffmpeg show the video information as: 480x480 [SAR 16:9 DAR 16:9]

    Using ffmpeg to change the "frame width" and "frame height" metadata tags does not change any of that information in VLC. And, it is not changing that information in Windows Explorer (unlike my previous experiences).

    Clearly I don't understand everything I want to know about aspect ratio, SAR, and, DAR - hence this thread and multiple questions:
    1. How/why is the codec dimensions different from SAR and/or DAR in VLC?
    2. How/why/where would SAR and DAR be different from each other?
    3. What is the difference, at least in VLC, between "video resolution" and "buffer dimensions"?
    4. Is there a way for me to know what the real/best dimensions for the original MP4 should be (i.e. 4/3, 16/9, 640x480, 853x480)?
    5. How can I use ffmpeg to make the "480x480 [SAR 16:9 DAR 16:9]" information all show the same aspect ratio information?
    6. What changes would also change the Window Explorer "frame width" and "frame height" metadata tag values?
    7. Do video players other than VLC value/use ""video resolution", "buffer dimensions", SAR, and/or DAR differently?
    8. For saving/archiving a video, is there any of these values that is more important projecting the best viewing experience in the future?

    The purpose of this post is to learn more about ffmpeg. Therefore, I am not looking for answers such as "use HandBrake".
    Last edited by the_steve_randolph; 17th Jul 2021 at 21:30.
    Quote Quote  
  2. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    VLC appears to show, the physical (actual pixels) in the data -hence 480x480. I don't think "buffer dimensions" is worth worrying about.

    FFmpeg gives the actual data (480x480), the storage aspect and the display aspect. They're 16x9 because the file has non-square pixels.
    It's 480x 480 displayed (stretched) to 16/9 - 853x480. In this case the sar and dar are both the same. But they don't have to be.
    I have a file that shows like this
    Code:
    720x576 [SAR 64:45 DAR 16:9]
    This is because the display aspect is 16x9 (1024x576), but the shape of the non-square pixel is 65:45 or 1024:720
    If you don't like non-square pixels resize (scale) in ffmpeg to force the actual resolution change
    Quote Quote  
  3. Originally Posted by davexnet View Post
    VLC appears to show, the physical (actual pixels) in the data -hence 480x480. I don't think "buffer dimensions" is worth worrying about.

    FFmpeg gives the actual data (480x480), the storage aspect and the display aspect. They're 16x9 because the file has non-square pixels.
    It's 480x 480 displayed (stretched) to 16/9 - 853x480. In this case the sar and dar are both the same. But they don't have to be.
    I have a file that shows like this
    Code:
    720x576 [SAR 64:45 DAR 16:9]
    This is because the display aspect is 16x9 (1024x576), but the shape of the non-square pixel is 65:45 or 1024:720
    If you don't like non-square pixels resize (scale) in ffmpeg to force the actual resolution change
    So, I tried this command:
    Code:
    ffmpeg -i in.mp4 -vf scale=852:480 -c:a copy out.mp4
    This is what I see with out.mp4:
    • VLC shows the video in the same aspect ratio (people tall and skinny) but with black bars on the left and right
    • VLC codec information shows that video resolution is: 852x480
    • VLC codec information shows that buffer dimension is: 864x480
    • ffmpeg show this video information: 852x480 [SAR 40:71 DAR 1:1]

    So, that didn't fix things. But, it creates another question: in VLC, why would the buffer dimension be different?

    Edit: BTW, the Windows "frame width" metadata value is changed to: 852
    Last edited by the_steve_randolph; 18th Jul 2021 at 02:41.
    Quote Quote  
  4. I think some players only pay attention to a Sample/Pixel aspect ratio written to the video stream rather than the container (or the other way around) so if they don't match, or one is missing, it can lead to the wrong DAR.

    I'm far from an expert on ffmpeg, but in the past I've used this version of ffmpeg to change h264 metadata. It doesn't re-encode.
    https://forum.doom9.org/showthread.php?t=152419

    It looks like these days the standard ffmpeg has similar functionality. It doesn't re-encode either.
    https://ffmpeg.org/ffmpeg-bitstream-filters.html#h264_005fmetadata

    It'd be something like this (SAR of 8:9 in this case):
    E:\ffmpeg.exe -i E:\input.mp4 -y -codec copy -bsf:v h264_metadata=sample_aspect_ratio=8/9 D:\output.mp4

    Trouble is, it doesn't change the container DAR, only the SAR in the video metadata (the old ffmpeg version I linked to above is the same). So when I tried the above command line with a 720x480 video and a 16:9 DAR, it should have changed to display as 4:3.

    720 * (8 / 9) = 640
    640 / 480 = 4:3

    MPC-HC still displayed the following for File/Properties though.
    Video: MPEG4 Video (H264) 720x480 (16:9)

    And MediaInfo says:
    Display aspect ratio : 16:9
    Original display aspect ratio : 4:3

    I assume "Display aspect ratio" is the container aspect ratio and "Original DAR" is derived from the video stream SAR.

    Anyhow... in my case the solution is to open the new MP4 with MKVToolNix and set 4:3 as the DAR for the video stream, then remux as MKV.

    For the output MKV MPC-HC shows:
    Video: MPEG4 Video (H264) 720x480 (4:3)

    And MediaInfo only shows:
    Display aspect ratio : 4:3

    Trouble is, I can't work out how to set the container DAR when remuxing with ffmpeg and every time I try to use MP4Box I end up suicidal. You'd assume it'd be an automatic thing when re-encoding, but someone else may know how to change it when muxing. In your case the DAR and the SAR should both be 16:9 (or whatever you think looks right), and as you can see from the above, it pays for the video and container aspect ratios to be in agreement.

    Or, if you're not married to MP4, remuxing as MKV while changing the container aspect ratio is easy enough with MKVToolNix.

    The video dimensions of 480x480 are just that. The video width and height. The display dimensions can be something else based on the sample/pixel aspect ratio.

    Video Width x SAR = Display Width
    Display Width / Video Height = Display Aspect Ratio.

    When the SAR is 1:1, the video width / height is the DAR.
    Last edited by hello_hello; 18th Jul 2021 at 02:55.
    Quote Quote  
  5. Originally Posted by hello_hello View Post
    I think some players only pay attention to a PAR/SAR written to the video stream rather than the container (or the other way around) so if they're not the same it can lead to the wrong DAR.

    :
    :
    :

    Or, if you're not married to MP4, remuxing as MKV while changing the container aspect ratio is easy enough with MKVToolNix.
    The purpose for this thread is to learn about ffmpeg by finding a command that accomplishes (what I think are the obvious) desired results. My research and testing so far pushes me toward choosing MP4 over MKV for my purposes. But, there is obviously some value in learning how ffmpeg handles MP4 and MKV differently.

    Also, I understand how different players may look at one piece of information that another might toss. But, part of me deciding which player I prefer would include understanding the different pieces of information. So, while the players will have differences, it would be beneficial for me to understand the differences in these pieces of information. For example, if I set the dimensions, but, VLC somehow finds a different "buffer dimension" value, why does that "buffer dimension" even exist?
    Quote Quote  
  6. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Steve, hello_hello, I'm not an expert either. Take a look at this sample, it contains, the source, command and result.
    Hopefully this is what you want.
    Image Attached Files
    Quote Quote  
  7. Originally Posted by the_steve_randolph View Post
    The purpose for this thread is to learn about ffmpeg by finding a command that accomplishes (what I think are the obvious) desired results. My research and testing so far pushes me toward choosing MP4 over MKV for my purposes. But, there is obviously some value in learning how ffmpeg handles MP4 and MKV differently.

    Also, I understand how different players may look at one piece of information that another might toss. But, part of me deciding which player I prefer would include understanding the different pieces of information. So, while the players will have differences, it would be beneficial for me to understand the differences in these pieces of information. For example, if I set the dimensions, but, VLC somehow finds a different "buffer dimension" value, why does that "buffer dimension" even exist?
    I was just explaining how to change the SAR in the video stream without re-encoding, as that won't reduce the quality, but I don't know how to change the container DAR with ffmpeg too.
    As I said though, if the info in the video stream and the container agree, there's no need to worry about which one a particular player might pay attention to.

    I assume the buffer dimensions are the same as the video dimensions, rather than the video DAR, but for a video with a 1:1 SAR, they'll probably always be the same.

    I see davexnet has posted an example. I haven't downloaded it yet, but maybe he has the solution.

    Edit: I'm "guessing" davexnet's example must re-encode. That's fine, but there must be a way to do it by changing the DAR/SAR without re-encoding too. I assume....
    Quote Quote  
  8. Originally Posted by davexnet View Post
    Steve, hello_hello, I'm not an expert either. Take a look at this sample, it contains, the source, command and result.
    Hopefully this is what you want.
    OK, from your example, I used this command:
    Code:
    ffmpeg -i in.mp4 -vf scale=852:480 -aspect 16/9 -c:a copy out.mp4
    This seems to fix the problem!

    In VLC, there is still "buffer dimensions: 864x480", which I still don't understand. And, while I have corrected this specific video, I am not sure if I have learned more about SAR and DAR.

    In any case, thanks for the help.
    Quote Quote  
  9. Originally Posted by hello_hello View Post
    Edit: I'm "guessing" davexnet's example must re-encode. That's fine, but there must be a way to do it by changing the DAR/SAR without re-encoding too. I assume....
    Well, that is part of my OP anyways. I need to go back and try to digest the previous post that talked about "non-square pixels" and see if that leads me to more research.

    Yeah, I guess one the questions becomes: if the video displays at the wrong aspect ratio, how do you fix/change that (with ffmpeg) without re-encoding? It would seem that the "-vf scale=" switch does not do that.


    Edit: So, I went back to davexnet's post and understood most of it. And, this link and this link provided some good explanations. It would seem that changing the pixel shape may not have to require re-encoding, but, splitting/duplicating pixels would cause re-encoding. But, just another example of why I posted this thread - trying to learn about ffmpeg, SAR, and, DAR.
    Last edited by the_steve_randolph; 18th Jul 2021 at 07:56.
    Quote Quote  
  10. Originally Posted by the_steve_randolph View Post
    In VLC, there is still "buffer dimensions: 864x480", which I still don't understand.
    OK, I seem to have found out why VLC can have "buffer dimensions" that are different from the "video resolution". It seems to be related to the H264 encoder and it wanting to have each number in the dimensions to be evenly divisible by 16. 852 is not evenly divisible, but, 864 is. So, I will try converting again with either 864 or 848 and see if I can see a difference in VLC.

    https://obsproject.com/forum/threads/what-are-buffer-dimensions.122760/
    Quote Quote  
  11. Originally Posted by the_steve_randolph View Post
    I have a MP4 video with the following attributes:
    • Windows "frame width" and "frame height" metadata tags are 480 and 480
    • VLC plays the video in a square, that is, visually it is a ratio of 1:1
    • VLC plays the video with people tall and skinny
    • VLC shows codec information of: H264
    • VLC shows codec information of: video resolution: 480x480
    • VLC shows codec information of: buffer dimensions: 480x480
    • ffmpeg show the video information as: 480x480 [SAR 1:1 DAR 1:1]
    Your source was not created properly. It doesn't specify the aspect ratio so VLC assumes square pixels (SAR=1:1). Hence the square frame size results in a square picture.

    Originally Posted by the_steve_randolph View Post
    When I use this command (my version of ffmpeg: N-101923-gc012f9b265):
    Code:
    ffmpeg -i in.mp4 -vf setdar=16/9 out.mp4
    or
    Code:
    ffmpeg -i in.mp4 -aspect 16:9 out.mp4
    visually in VLC it looks right. But, when I look at the codec information in VLC and ffmpeg, I see:
    • VLC shows codec information of: video resolution: 480x480
    • VLC shows codec information of: buffer dimensions: 480x480
    • ffmpeg show the video information as: 480x480 [SAR 16:9 DAR 16:9]
    That's exactly how it should be. Using -setdar or -aspect doesn't change the frame size. It simply includes a flag that tells the player the video should be played with that aspect ratio, regardless of the frame size.

    Originally Posted by the_steve_randolph View Post
    Clearly I don't understand everything I want to know about aspect ratio, SAR, and, DAR
    All you need to know is:
    Code:
    DAR = FAR * SAR
    
    DAR = display aspect ratio (the final shape of the picture)
    FAR = frame aspect ratio, frame_width:frame_height, in pixels
    SAR = sample aspect ratio, the shape of individual pixels*
    * techinically, pixels have no shape, they are points. SAR is the relative distance between those points along the x (width) and y (height) axis. When the video is rendered on-screen those points become rectangles -- hence the "shape of the individual pixels."

    Originally Posted by the_steve_randolph View Post
    So, I tried this command:
    Code:

    ffmpeg -i in.mp4 -vf scale=852:480 -c:a copy out.mp4

    This is what I see with out.mp4:

    VLC shows the video in the same aspect ratio (people tall and skinny) but with black bars on the left and right
    VLC codec information shows that video resolution is: 852x480
    VLC codec information shows that buffer dimension is: 864x480
    ffmpeg show this video information: 852x480 [SAR 40:71 DAR 1:1]
    That is because you changed the frame size but didn't specify the SAR or DAR. Specify one or the other, SAR=1:1, or DAR=16:9.
    Quote Quote  
  12. Originally Posted by jagabo View Post
    Originally Posted by the_steve_randolph View Post
    I have a MP4 video with the following attributes:
    • Windows "frame width" and "frame height" metadata tags are 480 and 480
    • VLC plays the video in a square, that is, visually it is a ratio of 1:1
    • VLC plays the video with people tall and skinny
    • VLC shows codec information of: H264
    • VLC shows codec information of: video resolution: 480x480
    • VLC shows codec information of: buffer dimensions: 480x480
    • ffmpeg show the video information as: 480x480 [SAR 1:1 DAR 1:1]
    Your source was not created properly. It doesn't specify the aspect ratio so VLC assumes square pixels (SAR=1:1). Hence the square frame size results in a square picture.
    Well, yeah, and, I want to understand how to fix it

    Originally Posted by jagabo View Post
    Originally Posted by the_steve_randolph View Post
    When I use this command (my version of ffmpeg: N-101923-gc012f9b265):
    Code:
    ffmpeg -i in.mp4 -vf setdar=16/9 out.mp4
    or
    Code:
    ffmpeg -i in.mp4 -aspect 16:9 out.mp4
    visually in VLC it looks right. But, when I look at the codec information in VLC and ffmpeg, I see:
    • VLC shows codec information of: video resolution: 480x480
    • VLC shows codec information of: buffer dimensions: 480x480
    • ffmpeg show the video information as: 480x480 [SAR 16:9 DAR 16:9]
    That's exactly how it should be. Using -setdar or -aspect doesn't change the frame size. It simply includes a flag that tells the player the video should be played with that aspect ratio, regardless of the frame size.
    And, that was an unsuccessful try in the middle of this thread.

    Originally Posted by jagabo View Post
    Originally Posted by the_steve_randolph View Post
    Clearly I don't understand everything I want to know about aspect ratio, SAR, and, DAR
    All you need to know is:
    Code:
    DAR = FAR * SAR
    
    DAR = display aspect ratio (the final shape of the picture)
    FAR = frame aspect ratio, frame_width:frame_height, in pixels
    SAR = sample aspect ratio, the shape of individual pixels*
    * techinically, pixels have no shape, they are points. SAR is the relative distance between those points along the x (width) and y (height) axis. When the video is rendered on-screen those points become rectangles -- hence the "shape of the individual pixels."
    Well, yeah, I have found that information. But, I have not found how to set those things properly with ffmpeg, hence this thread.

    Originally Posted by jagabo View Post
    Originally Posted by the_steve_randolph View Post
    So, I tried this command:
    Code:

    ffmpeg -i in.mp4 -vf scale=852:480 -c:a copy out.mp4

    This is what I see with out.mp4:

    VLC shows the video in the same aspect ratio (people tall and skinny) but with black bars on the left and right
    VLC codec information shows that video resolution is: 852x480
    VLC codec information shows that buffer dimension is: 864x480
    ffmpeg show this video information: 852x480 [SAR 40:71 DAR 1:1]
    That is because you changed the frame size but didn't specify the SAR or DAR. Specify one or the other, SAR=1:1, or DAR=16:9.
    And, again, that was another unsuccessful try in the middle of the thread. Please see post #8 where I was finally successful.
    Quote Quote  
  13. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Also, from your OBS link, see the comment by Rich on May 26
    Quote Quote  
  14. Buffer dimensions have to do with internally handling of the codec and player/editor. Codecs often have requirements that the encoded frame size must be an even multiple of 4, or 8, or 16, etc. So internally they will pad the frame to match that requirement but only output the actual frame size. Players/editors may also have such requirements too, or may want to better align data in memory to speed up processing. So they may pad the frame internally. This isn't anything you need to worry about unless you are creating your own codec or player/editor.

    For example, your video in post #3 has a frame width or 852 (a mod 4 size) but is handled internally as 864 (a mod 8 size). But you only see the 852 width when editing/encoding.
    Quote Quote  
  15. So, understanding that SAR is the aspect ratio of each individual pixel, what would be the advantage of having an SAR that is not 1:1?
    Quote Quote  
  16. Originally Posted by the_steve_randolph View Post
    So, understanding that SAR is the aspect ratio of each individual pixel, what would be the advantage of having an SAR that is not 1:1?
    It depends on the context and what you start with

    When you start with original SD content - it very often does not have a SAR of 1:1 (e.g. DVD-video never has a SAR of 1:1, SD video formats such as DV do not either) . If you re-encode or resize to "square pixel" equivalents, or a SAR 1:1, you lose quality or waste storage . e.g resizing a 16:9 NTSC DVD frame from 720x480 to 854x480 using "traditional" scaling methods gains nothing. You end up needing more bitrate and you lose more quality when using lossy encoding, than if you keep the original storage dimensions and just let the player resize on playback

    The majority of newer HD and UHD content almost always use a SAR of 1:1 (although some older HD formats use 1440x1080 for 16:9 DAR with a SAR of 4:3)
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!