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

Abillity to modify plex client ffmpeg arguments #11

Open
FCLC opened this issue Dec 29, 2020 · 7 comments
Open

Abillity to modify plex client ffmpeg arguments #11

FCLC opened this issue Dec 29, 2020 · 7 comments

Comments

@FCLC
Copy link

FCLC commented Dec 29, 2020

Hi team,

Unless I've missed something from the documentation- I don't see a way to modify/append arguments captured from UnicornFFMPEG before they're sent to the transcoder. the reason I ask is that this could be a vector to add in support for different HWAccels that are platform dependent, say AMF encoding, openCL etc.

If I've missed something let me know!

-FCLC

@Maxou44
Copy link
Member

Maxou44 commented Dec 29, 2020

In this case, we recommend to patch the ffmpeg args on the UnicornTranscoder side (just before running it)

Hardware transcode will be hard to add, more info available on this issue: UnicornTranscoder/UnicornTranscoder#24

@FCLC
Copy link
Author

FCLC commented Dec 30, 2020

Hi @Maxou44

if my understanding is correct this is the current flow, and the new flow is below.

flow as designed by unicorn transcoder

plex client that cannot direct play FILE request transcode from server

UnicornLB intercepts request and sends to host system of UnicornTranscoder

Unicorn Transcoder repeats request from the initial client and sends to plex server.

Plex Server calls Plex Transcoder; the transcoder has been replaced by UnicornFFMPEG

Unicorn FFmpeg sends the arguments to Unicorn Loadbalancer

UnicornLoadBalancer sends request to UnicornTranscoder which then requests arguments from UnicornLoadBalancer

Unicorn Transcoder then serves the requested stream

Changes and new flow

/* before going live: create list that contains transcode capabilities of each relevant server (HEVC, h264, 4k 1080p, 24 30-60-120fps? */

Plex client that cannot direct play FILE request transcode from server

UnicornLB intercepts request and sends to host system of UnicornTranscoder

Unicorn Transcoder repeats request from the initial client and sends to plex server.

Plex Server calls Plex Transcoder; the transcoder has been replaced by UnicornFFMPEG

change from standard

Unicorn FFMPEG Sends arguments to custom script.

Custom script thens send the file to the apropriate system

Unicorn FFmpeg sends the arguments to Unicorn Loadbalancer

Custom scrips detects file requirments, and allocates resources based on most appropriate available server

UnicornLoadBalancer sends request to UnicornTranscoder which then requests arguments from UnicornLoadBalancer

Unicorn Transcoder then serves the requested stream

Specific change in source of UnicornTranscoder

change area: change args in section //get args
line 36-92 is relevant section

@FCLC
Copy link
Author

FCLC commented Dec 30, 2020

Also, for what it's worth I'm a C and VHDL dev, haven't done a ton of Node in the past.

But I assume that you could do something like a case statement of presets? so we would look for any instance of

-c:v libx264 -b:v {requested bitrate} -maxrate {if requested} -bufsize 1M

to

-c:v {relevant HW accel from host platform in codec requested [hevc, h264, VP9 av1 etc.]} -b:v {requested bitrate} -maxrate {if requested} -bufsize 1M

@FCLC
Copy link
Author

FCLC commented Dec 30, 2020

Continuing to dig into how to make this work- I see that on lines 43-46 we're already doing a codec substitution on the string that will be sent to ffmpeg due to a problem with the aac_lc audio codec

// Hack to replace aac_lc by aac because FFMPEG don't recognise the codec aac_lc
if (arg === 'aac_lc')
                            return 'aac';

Unless I'm misreading this, could we not search for specific string such as

'ffmpeg' to 'ffmpeg 'vaapi' -hwaccel_output_format vaapi'

and then

'-c:v libx264' to '-c:v hevc_vaapi'

@FCLC
Copy link
Author

FCLC commented Jan 1, 2021

Hi @Maxou44, just realized I'd forgotten to tag you in the response, mind sharing your thoughts on the above when you have a moment?

@Maxou44
Copy link
Member

Maxou44 commented Jan 2, 2021

We don't generate the ffmpeg args, we just patch args sent by Plex Media Server. It's possible to support HW transcoding but:

  • The best solution is support it on transcoder side
  • You have to code a HW detection to know args to add to ffmpeg execution (and how many streams you can support with each HW case)
  • You have to disable HW transcode on your Plex Media server

It's not simple to support and I don't have a lot of hardware to test

@FCLC
Copy link
Author

FCLC commented Jan 23, 2021

Hey mate! apologies for the delay in replying- working on another portion of my project. (BTW Francais?)

We don't generate the ffmpeg args, we just patch args sent by Plex Media Server.

The approach I'm thinking of using as a proof of concept is the use the same argument patching as mentioned above.

Digging into the src for the load balancer, I wonder if it might be possible to add a config parameter for what acceleration/features are available for each transcode node. This should be something we can parse as an option/field just like max number of sessions and other "per node" configuration options. Thoughts?

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

No branches or pull requests

2 participants