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

Import from YouTube is not using the highest quality available #3987

Closed
SimplyCorbett opened this issue Apr 19, 2021 · 11 comments
Closed

Import from YouTube is not using the highest quality available #3987

SimplyCorbett opened this issue Apr 19, 2021 · 11 comments

Comments

@SimplyCorbett
Copy link

SimplyCorbett commented Apr 19, 2021

I'm comparing two video imports from the same URL. One is downloaded through peertube, another is downloaded with youtube-dl and uploaded manually.

URL: https://www.youtube.com/watch?v=eByKuI7_F7g

Peertube URL import: https://vidrot.com/videos/watch/cd93a375-9655-45a1-a0d8-9430af53db97

youtube-dl upload (4k, please use 1080p option to compare): https://vidrot.com/videos/watch/ea61d8d8-3e9c-46d6-9dbb-2d7f0c356e80

PeerTube instance:

URL: vidrot.com
version: 3.1.0
NodeJS version: 15
Ffmpeg version: 4.2.2

VOD Setup:

480p, 1080p allowed, the rest disabled.

Steps to reproduce:

  1. Import URL
  2. Upload 4k version of the same clip downloaded manually with youtube-dl
  3. Compare bitrate of both 1080p versions in peertube. 2) is 1Mbps higher then 1)

Expected behavior:

Bitrate should be the same on both clips.

@rigelk
Copy link
Collaborator

rigelk commented Apr 19, 2021

hi @SimplyCorbett,

Could you fill the issue template and be more specific in your issue title? I don't see any problem description in your issue.

@rigelk rigelk added the Template not filled Doesn't use or fill one of the issue templates. Can be closed anytime. label Apr 19, 2021
@SimplyCorbett SimplyCorbett changed the title Suggestion: Change how youtube imports are handled Same video, different bitrates Apr 19, 2021
@SimplyCorbett
Copy link
Author

@rigelk Tried to make this more clear.

I think what's going on is if you have 1080p selected but 4k disabled peertube will grab the 1080p youtube video. The 1080p youtube video has more compression then the 4k version and so the final product on peertube is more watered down.

@rigelk
Copy link
Collaborator

rigelk commented Apr 19, 2021

@SimplyCorbett we changed the import selector to only import the video matching the highestd resolution selected, so this is only to be expected. It allows faster imports and transcode, especially for small instances that only selected small resolutions. As for the "watered down" effect, it is also due to YT being the source, and not the original file.

@SimplyCorbett
Copy link
Author

@rigelk Right, I'm just pointing out the 4k file when transcoded down to 1080p is 1Mbps higher/double the bitrate.

Not sure if a faster transcode time is worth the quality loss, but that's my opinion. Any chance you could make this optional on the admin backend?

@ghost
Copy link

ghost commented Apr 19, 2021

transcoding from a low bit rate source should not be the default, imo. peertube is pretty hard on folks who are trying to keep their video quality high.

@rigelk
Copy link
Collaborator

rigelk commented Apr 19, 2021

Not sure if a faster transcode time is worth the quality loss, but that's my opinion. Any chance you could make this optional on the admin backend?

Sure; and as @scanlime pointed most people favor quality over VPS load.

@rigelk rigelk added Component: Import Component: Transcoding Type: Feature Request ✨ and removed Template not filled Doesn't use or fill one of the issue templates. Can be closed anytime. labels Apr 19, 2021
@rigelk rigelk changed the title Same video, different bitrates Import from YouTube is not using the highest quality available Apr 20, 2021
@SimplyCorbett
Copy link
Author

Any progress on this?

@Chocobozzz
Copy link
Owner

Hello,

If the new option transcoding.always_transcode_original_resolution is set to true, we now import the best available resolution.

@SimplyCorbett
Copy link
Author

@Chocobozzz testing on 4.2.2...7804e57 (fresh install) with a fresh yt-dlp, nodejs 16 and ffmpeg 5.0.1.

It does work (and keep) the original resolution. So, yay! Any chance you can add the option to remove the original resolution once transcoding has finished?

The idea was that since youtube starved bitrate on lower resolution videos that if your instance was limited to 1080p if a 1440p or 4k version was available it would transcode off the highest resolution possible, but your instance would still only have the 1080p resolution available for play.

Maybe I didn't explain that right originally. Sometimes I'm dumb like that.

@vid-bin
Copy link

vid-bin commented Sep 3, 2022

As an example youtube has a 1440p version with 10.5Mbps bitrate and a 1080p with 3.5Mbps. I want peertube to grab the 1440p (higher bitrate) version and then transcode the 1080p video from that. I don't want it to waste CPU cycles transcoding the 1440p version (which with VP9 will take hours).

By using 1440p as the base resolution the bitrate is doubled on the transcoded 1080p video.

@vid-bin
Copy link

vid-bin commented Sep 16, 2022

For anyone who wants higher quality 1080p transcodes (because youtube starves 1080p bitrate):

In server/helpers/youtube-dl/youtube-dl-cli.ts:

    if (!useBestFormat) {
      const resolution = enabledResolutions.length === 0
        ? VideoResolution.H_720P
        : Math.max(...enabledResolutions)

      result = [
        `bestvideo[vcodec^=avc1][height=${resolution}]+bestaudio[ext=m4a]`, // case #1
        `bestvideo[vcodec!*=av01][vcodec!*=vp9.2][height=${resolution}]+bestaudio`, // case #2
        `bestvideo[vcodec^=avc1][height<=${resolution}]+bestaudio[ext=m4a]` // case #
      ]
    }

Change this to:

    if (!useBestFormat) {
      const resolution = enabledResolutions.length === 0
        ? VideoResolution.H_720P
        : Math.max(...enabledResolutions)

      result = [
        `bestvideo[vcodec!*=av01][vcodec!*=vp9.2][height=1440]+bestaudio`, // prefer 1440p downloads with high quality VP9
        `bestvideo[vcodec!*=av01][vcodec!*=vp9.2][height=${resolution}]+bestaudio`, // prefer high quality VP9 over AVC1
        `bestvideo[vcodec^=avc1][height=${resolution}]+bestaudio[ext=m4a]`, // case #1
        `bestvideo[vcodec^=avc1][height<=${resolution}]+bestaudio[ext=m4a]` // case #
      ]
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants