mediacms icon indicating copy to clipboard operation
mediacms copied to clipboard

Wrong resolutions and framerates encoded

Open multiflexi opened this issue 4 years ago • 5 comments

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.

multiflexi avatar Jun 23 '21 16:06 multiflexi

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

mgogoulos avatar Jun 23 '21 19:06 mgogoulos

Send me an email to [email protected] so we can arrange a call as well!

mgogoulos avatar Jun 23 '21 19:06 mgogoulos

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

ssteo avatar Sep 07 '22 14:09 ssteo

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

mgogoulos avatar Sep 07 '22 15:09 mgogoulos

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.

ssteo avatar Sep 07 '22 16:09 ssteo