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 resolutions and framerates encoded #232

Open
multiflexi opened this issue Jun 23, 2021 · 5 comments
Open

Wrong resolutions and framerates encoded #232

multiflexi opened this issue Jun 23, 2021 · 5 comments
Assignees
Labels
backend Backend issues enhancement New feature or request video

Comments

@multiflexi
Copy link
Contributor

The current system for resolutions and framerates has some flaws. All in helpers.py file.

RESOLUTIONS
The videos which do not have 16:9 aspect ratio are not encoded in the right resolutions.
Example 1: A video that has a resolution of 1280 × 544 is encoded only up to a 480p profile. Should also be in the 720p profile.
Example 2: A video that has a resolution of 544 × 1280 is encoded up to the 480p profile. Should be up to the vertical 720p profile.

The issue is that the algorithm which selects which resolutions should be encoded uses only height. Also, the vertical video detection should be done first:
if (target_width/target_height)<1:
Based on this, an appropriate set of rectangles, vertical or horizontal, is selected. 1:1 video will fall into the horizontal category.

The scaling part could be changed from
"scale=-2:" + str(target_height) + ",fps=fps=" + str(target_fps),
to something like
"scale=w=" + str(target_width) + ":h=" + str(target_height) + ":force_original_aspect_ratio=decrease,fps=fps=" + str(target_fps),
This inserts whatever aspect ratio to defined rectangles keeping the original aspect ratio intact.

Horizontal rectangle examples :

  • 256 ×144
  • 448 × 252
  • 640 × 360
  • 960 × 540
  • 1280 × 720
  • 1920 × 1080
  • 3840 × 2160
  • 7680 × 4320
    And their 90° rotated variants for videos that are vertical. I think that 480p is not quite suitable, because it does not have an integer width for 16:9 video, 240p as well.

FRAMERATE
Videos with fractional framerate are encoded as 60fps or 30fps.
This can be blamed:
# adjust the target frame rate if the input is fractional target_fps = src_framerate if isinstance(src_framerate, int) else math.ceil(src_framerate)
I do not see any reason for this. Video should be presented in the same framerate as original or it can be halved (60 fps to 30 fps). FFmpeg fps filter can just use fractional input. In case halving of ~50-60fps is needed, for ~25-30fps versions, division by 2 is possible.
"scale=-2:" + str(target_height) + ",fps=fps=" + str(source_fps),
or for halving
"scale=-2:" + str(target_height) + ",fps=fps=" + str(source_fps/2),

I am willing to help with this but there is documentation missing so this is what I was able to deduce from the helpers.py file.

@mgogoulos mgogoulos added backend Backend issues enhancement New feature or request video labels Jun 23, 2021
@mgogoulos
Copy link
Contributor

Thanks for the report, this is very useful and we should work together in making the fixes you suggest

@mgogoulos
Copy link
Contributor

Send me an email to mgogoulos@gmail.com so we can arrange a call as well!

@ssteo
Copy link

ssteo commented Sep 7, 2022

Hi @mgogoulos, is there a fix for this issue or this project is no longer maintained?

@mgogoulos
Copy link
Contributor

Hi @ssteo , you're making an incorrect assumption here, that either there's a fix for this or otherwise the project is no longer maintained. Well, the project is definitely being maintained!

There have been fixes (and some of them contributed even by @multiflexi that opened this one) but there's definitely room for improvement here.

Did you notice some strange behaviour? Feel free to share more details

@ssteo
Copy link

ssteo commented Sep 7, 2022

Thanks, I'm also encountering issues where some videos which are 1080p but when uploaded to mediacms the available transcoded resolution is only up to 720 somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend issues enhancement New feature or request video
Projects
None yet
Development

No branches or pull requests

3 participants