PeerTube icon indicating copy to clipboard operation
PeerTube copied to clipboard

Provide filter parameter to addEncoderPriority

Open TheoLeCalvar opened this issue 4 years ago • 4 comments

Describe the problem to be solved

I use a custom video encoding profile to enable hardware acceleration on my instance. However the hardware encoder cannot decode all codec and fails to transcode some videos.

Describe the solution you would like:

Peertube could retry failed transcode jobs that use a custom profile with default transcode profile which has better support for input codecs and video geometry.

TheoLeCalvar avatar Jul 28 '21 18:07 TheoLeCalvar

Hello,

It would require too much work and we can't really know why a transcoding job failed. Instead, I think we could add a filter parameter to addVODEncoderPriority that is a function returning a boolean depending on file input (so you can choose to not use your hardware encoder depending on the input codecs)

Chocobozzz avatar Jul 29 '21 06:07 Chocobozzz

Hi,

The filter idea sounds good. If metadata about the file is easily available could it also be passed to the filter ? So that the plugin doesn't have to redo what peertube has already done with ffprobe to extract metadata. I think with these metadata I would be able to correctly detect if the hardware encoder can process the video or not:

  • input codec
  • video dimensions
  • video orientation

Otherwise, perhaps you could add a method to get metadata from a video path the to peertubeHelpers so that is can easily be used in plugins.

TheoLeCalvar avatar Jul 29 '21 10:07 TheoLeCalvar

Like stated in #3994 it would be nice if we could have different encoders per resolution.

I'd like to keep my mobile users when using AV1 as the default codec so it would be nice if VP9/AAC was used on 480p and AV1/Opus on 1080p-1440p.

vid-bin avatar Sep 09 '22 14:09 vid-bin

Like stated in #3994 it would be nice if we could have different encoders per resolution.

I'd like to keep my mobile users when using AV1 as the default codec so it would be nice if VP9/AAC was used on 480p and AV1/Opus on 1080p-1440p.

Preferably multiple codecs per resolution that get served to viewers, based on a user agent whitelist that checks a internal compatibility matrix with configurable overrides.

emansom avatar Sep 09 '22 17:09 emansom

@emansom @scanlime

Might interest you. In the attached zip is a modified ffmpeg-encoders.ts that goes in server/helpers/ffmpeg along with an example of my transcoding-debug profile settings.

With these changes you can have custom encoders based on resolution. In my example I have working h264/aac for compatibility with mobile devices on 480p along with AV1 encoders for higher resolutions.

In the code only the 480p30, 480p60, 720p30, 720p60, 1080p30, 1080p60, 1440p30 and 1440p60 profiles are supported. Though, you could easily modify this for other profiles.

I think live streaming will also work, but I don't personally use live streaming so haven't tested.

I've also modified the source code in other areas so I can call pix_fmt in the transcoding plugin. If you don't modify your peertube instance to allow this just remove it from my example.

You may also want to look into modifying youtube-dl-cli.ts if you allow/use http imports so it downloads the highest quality video available instead of based on max resolution. Something like the following:

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

Have fun!

ffmpeg-encoders.zip

vid-bin avatar Mar 23 '23 21:03 vid-bin