exwm / yt_clipper

Mark up YouTube videos and quickly generate clipped webms.
https://openuserjs.org/scripts/elwm/yt_clipper
MIT License
50 stars 12 forks source link

Add support for NVidia Codecs #46

Open rehandaphedar opened 2 days ago

rehandaphedar commented 2 days ago

Please describe the need for the feature: Currently, it is not possible to use hardware acceleration on NVidia cards for transcoding.

Please describe the feature and the requirements for its ideal implementation: The h264 codec has an nvenc version as per ffmpeg -codecs. Thus, it should be added to the list of available options.

Please describe any alternatives you have tried or considered: NA

Additional Notes or Context On looking through the source code, I found these relevant lines:

I was going to make a PR but I'm not sure I understand the reduce stutter bits.

exwm commented 9 hours ago

I was going to make a PR but I'm not sure I understand the reduce stutter bits.

Are you referring to the --h264-disable-reduce-stutter option?

If so, this option disables setting the -r ffmpeg video output option which when used with h264 videos will remove duplicate frames from the input. For example, if the input video is 30 fps but uses a duplicate frame every other frame, the output will also have duplicate frames. I noticed that playback with duplicate frames is sometimes stuttery. Setting -r 30 will still output 30 fps will remove the duplicate frames and instead hold each frame for twice as long.

See also https://trac.ffmpeg.org/wiki/ChangingFrameRate.

exwm commented 9 hours ago

I have played with hardware accelerated codecs before, but there are compatibility issues with a number of ffmpeg filters. It's not as straightforward as just using a different codec, some filters will not work at all while others require special set up. Additionally, the quality may not always be on par with the pure cpu variant of the codec.

If you're still interested in this, it may be okay to introduce the codec with documentation mentioning these caveats and disabling or disallowing filters/features that are not supported by the codec.

rehandaphedar commented 5 hours ago

Sadly I don't have access to an NVidia machine anymore (Was testing on my old computer back home).

I was able to progress upto this branch, incase anyone wants to continue: https://github.com/rehandaphedar/yt_clipper/tree/h264-nvenc.

Running a command like yt_clipper --video-codec h264_nvenc --markers-json markers.json fails with:

[h264_nvenc @ 0x5860d10319c0] Multiple reference frames are not supported by the device
[h264_nvenc @ 0x5860d10319c0] No capable devices found
[vost#0:0/h264_nvenc @ 0x5860d13f2d00] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
Error while filtering: Generic error in an external library

I edited -refs 4 to -refs 1, which still results in the same error. (System: Linux Mint 22, Geforce GTX 1050 Ti).

For my usecase, I might try to make a simple script to parse markers.json (I had a similar CLI clipping program, but it was not as convenient as the browser extension ofcourse) and generate plain ffmpeg commands.