Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong output aspect ratio, due to not respecting Display Aspect Ratio (DAR) #63

Open
Yasand123 opened this issue Jan 24, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@Yasand123
Copy link

Yasand123 commented Jan 24, 2025

I'm not sure if this has been discussed or addressed. I tried to search but I got nothing, I apologize if it has.


I'm encountering an issue when upscaling where the aspect ratio of the output would change from 4:3 to 5:4 (from 768×576 to 720×576). I suspected it has to do with ffmpeg, so I tried extracting frames using the ffmpeg cli tool directly. And indeed I got a similar result.

Key points:

  • Input video resolution: 768×576
  • Extracted frame resolution: 720×576
  • Issue: The extracted frames have a different aspect ratio/resolution, which means the upscaled video will also have a different aspect ratio/resolution
  • Expected behavior: The frames should be extracted at the original DAR resolution 768×576

I didn't fully understand why this happens at first, but after reading and I think I got a rough understanding of it. There's 2 things regarding resolution / aspect ratio in videos that need to be considered when extracting frames:

  1. Storage Aspect Ratio (SAR)
    This refers to how the pixel data is stored in a video file. In some cases, the pixels are not stored as square (non-square pixels), which means during display, DAR adjusts for that. However, when extracting frames, ffmpeg reads the data from the SAR directly, without performing this adjustment.

  2. Display Aspect Ratio (DAR)
    This refers to the resolution of the video as it is displayed on screen by the video player. In most cases, DAR matches SAR, meaning the video is displayed with square pixels. However, in some cases, such as with older media, DAR may differ from SAR.

I found a solution using ffmpeg's scale filter.

The key idea here is to multiply the input width iw (which is 720 in my case) by SAR (which is 16:15 in my case) to compensates for the non-square pixels in SAR in the original video.

720 * (16/15) = 768.

Here's the full command I used to get the correct aspect ratio for the extracted frames that matches DAR:

ffmpeg -i input_video.mp4 -vf "scale=w=iw*sar:h=ih" -q:v 2 frames/frame_%04d.png

Thankfully ffmpeg understands the keyword sar so this command figures out all the needed numbers for the math automatically.

Maybe this should be added as an optional setting for those who need it.

@TNTwise
Copy link
Owner

TNTwise commented Jan 24, 2025

I might look into it for the release after 2.2.0, but it won't be in a stable build for a while.

@TNTwise TNTwise added the bug Something isn't working label Jan 26, 2025
@Pickie
Copy link

Pickie commented Jan 27, 2025

ive also just experianced incorrect aspect ratio after encode , round things aint round :(

original ar 4:3

encoded ar 1.222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants