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

configuration options to make use of external video encoders/decoders like NVENC #31

Open
NotQuiteApex opened this issue Sep 21, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@NotQuiteApex
Copy link
Collaborator

Currently VodBot simply shells out commands to ffmpeg to handle all processing. It'd be good to have some configuration flags to help enable external encoders to be used, or to just use the CPU. I currently don't know if ffmpeg does this automatically, or if it can be controlled with the functions VodBot currently uses.

@NotQuiteApex NotQuiteApex added enhancement New feature or request help wanted Extra attention is needed labels Sep 21, 2021
@NotQuiteApex
Copy link
Collaborator Author

Bit of a lapse in brainulating today. Because VodBot deals in MP4's, and uses -c copy with ffmpeg, its purely a CPU operation simply copies data from one file to another. Closing.

@NotQuiteApex
Copy link
Collaborator Author

After thinking it over for a while, I've discovered that the above comment can be incorrect in cases where videos from multiple different source files can lead to mixing formats and bitrates, which in turn leads to potentially catastrophic video errors.

It's very much worth looking into potential external hardware encoders, although configuration of these encoders in the ffmpeg commands can be tricky.

Note to self: search any and all direct drop-in strings for potential security issues.

@NotQuiteApex NotQuiteApex reopened this Dec 20, 2021
@NotQuiteApex NotQuiteApex self-assigned this Dec 21, 2021
@NotQuiteApex NotQuiteApex added this to the 1.1.0 milestone Dec 21, 2021
@NotQuiteApex NotQuiteApex removed this from the 1.1.0 milestone Feb 5, 2022
@NotQuiteApex NotQuiteApex changed the title configuration options to make use of external video encoders like NVENC configuration options to make use of external video encoders/decoders like NVENC Aug 8, 2022
@NotQuiteApex
Copy link
Collaborator Author

NotQuiteApex commented Aug 8, 2022

Some useful encoding params...

  • ffmpeg -i input.avi -c:v libx264 output.mp4 # Software H.264
  • ffmpeg -i input.avi -c:v libx265 output.mp4 # Software HEVC/H.265
  • ffmpeg -i input.avi -c:v h264_amf output.mp4 # AMD Accel. H.264
  • ffmpeg -i input.avi -c:v hevc_amf output.mp4 # AMD Accel. HEVC/H.265
  • ffmpeg -i input.avi -c:v h264_qsv output.mp4 # Intel Accel. H.264
  • ffmpeg -i input.avi -c:v hevc_qsv output.mp4 # Intel Accel. HEVC/H.265
  • ffmpeg -i input.avi -c:v av1_qsv output.mp4 # Intel Accel. HEVC/H.265
  • ffmpeg -i input.avi -c:v h264_nvenc output.mp4 # Nvidia Accel. H.264
  • ffmpeg -i input.avi -c:v hevc_nvenc output.mp4 # Nvidia Accel. HEVC/H.265

This is specifically for the output, video decoders must be specified with -c:v decoder_here before the -i input.avi arguments.

@NotQuiteApex
Copy link
Collaborator Author

https://trac.ffmpeg.org/wiki/HWAccelIntro

Seems like hardware acceleration on Linux for AMD is meant to use VAAPI, as it at least has partial support. Instead of custom parameters from config it may be safer to simply provide a config variable with "nvidia-264", "amd-265", "intel-av1", etc. as options.

@NotQuiteApex
Copy link
Collaborator Author

So for determining decode type for using hw acceleration, ffmpeg has a side program called ffprobe that can find useful info from a file. So ffprobe -v quiet -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey= 1 /mnt/archive/vods/notquiteapex/2022-12-10T23\;01\;47Z_1675749547.mkv will return "h264", which python will need to grab to determine how to decode the file. Most if not all twitch streams will be h264.

@NotQuiteApex NotQuiteApex added this to the 1.2.0 milestone Jan 20, 2023
@NotQuiteApex
Copy link
Collaborator Author

SO! VAAPI is exclusive to Linux, and in my testing it is not at all necessary for using AMD hardware acceleration on Linux, and that the FFmpeg wiki is simply out of date.

I'm thinking of two config options to add, first is hwaccel_encoder (options are "software", "amd", "intel", and "nvidia"), next is hwaccel_decoder (same as before), and hwaccel_format (options are "h264", "hevc", and "av1"). The first two options handle how the video is managed, the last option handles how the videos are saved to the system and how they should be expected to be handled when local. There would probably be ffprobe checks in place to make sure that the expected and actual formats, though.

@NotQuiteApex
Copy link
Collaborator Author

Internally, there would simply be a multidimensional dictionary that handles translating the codec and format options to their respective ffmpeg options (like "av1" and "intel" translating to "av1_qsv"). This would not be a simple string manipulation, due to the weird/different names that ffmpeg uses for codecs and formats (h265 is hevc but not by name, intel is qsv, etc).

MKV's will still be used because its a great container format.

@NotQuiteApex
Copy link
Collaborator Author

Lastly, subprocess.run can redirect stdout to a useful output that isn't the stdout of VodBot. it would simply be using subprocess's pipe object to get the bytes data out of the programs stdout. See here https://csatlas.com/python-subprocess-run-stdout-stderr/

@NotQuiteApex NotQuiteApex removed the help wanted Extra attention is needed label Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant