2

I have a NVIDIA Quadro P620. I have a lot of research on how to accelerate my transcoding using my graphic card.

I stumble on this page https://trac.ffmpeg.org/wiki/HWAccelIntro#Usewiththeffmpegcommand-linetool

So, I tried

ffmpeg -hwaccel cuda -i input.avi output.mp4

It did not turn out any faster than

ffmpeg -i input.avi output.mp4

It actually took longer for transcoding.

I can see it spend the same CPU usage on resmon as without -hwaccel option.

Did I do something wrong? How do I know ffmpeg is correctly using my GPU?

Hoy Cheung
  • 141
  • 1
  • 6
  • So, I'm assuming you're using Linux? That would be one the details you should've posted already, that and your Nvidia drivers and CUDA versions. – ChanganAuto Apr 22 '21 at 15:23
  • I am using windows 10. I can see it did accelerate now after adding the h264_nvenc codec now – Hoy Cheung Apr 22 '21 at 15:24
  • You may want to ask a different question or edit this one. This isn't a forum, it's a Q&A. – ChanganAuto Apr 22 '21 at 15:29
  • 4
    Different encoders have different goals. Nvidia encoders (and hardware encoders in general) are more optimised for streaming and speed and efficient use of power than they are towards high quality and small file size. If you want best quality for smallest size then CPU encoding is the way to go. Fixed function hardware is far faster, but due to being fixed in hardware has far less scope for catering for every possible optimisation and is entirely incapable of being upgraded in place. You want a newer and better encoder, you replace your graphics card type thing... – Mokubai Apr 22 '21 at 15:44
  • 2
    In short, hardware encoders and decoders for video files — think archiving — really stink unless you are using video card that is specifically designed for high quality video compression. And in my experience x264 is the best format for hardware encoding and decoding. x265 is a very CPU intensive codec and one can assume the only video cards that can really handle that well — as far as encoding goes — are really pricey. – Giacomo1968 Apr 22 '21 at 16:24

1 Answers1

4

According to the Video Encode and Decode GPU Support Matrix, your GPU supports hardware-assisted decode and encode, also called NVENC.

The only troubling point here is the list of codecs that your GPU supports, which are: H.264 and H.265. If your videos are not encoded with these codecs, hardware acceleration might not work for you.

For the right codecs and for reference, the Stack Overflow post make ffmpeg chose Nvidia CUDA over Intel QSV mentioned that hardware acceleration was working with the following command:

ffmpeg -hide_banner -hwaccel cuda -i "input.avi" -c:a copy -ac 1 -c:v h264_nvenc -preset hq -movflags faststart -qp 30 "output.mp4"
harrymc
  • 455,459
  • 31
  • 526
  • 924
  • I viewed my p620 spec. It says the card specialized in encoding H.264 and HEVC. Which does a better compression? How do I transcode too HEVC in ffmpeg? – Hoy Cheung Apr 22 '21 at 16:51
  • See [Why is HEVC Better than H.264?](https://applegazette.com/mac/why-is-hevc-better-than-h-264/) – harrymc Apr 22 '21 at 16:54
  • I found the codec name for hevc is libx265. So when I try to transcode the file, ffmpeg told me off: Video uses a non-standard and wasteful way to store B-frames ('packed B-frames'). Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it. Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scaler_0' Error reinitializing filters! Failed to inject frame into filter network: Function not implemented Error while processing the decoded data for stream #0:0 How do I get pass this? – Hoy Cheung Apr 22 '21 at 17:00
  • Try H.264, but the problem might be with the format of the input. – harrymc Apr 22 '21 at 17:03
  • Problem is H264 compression is no good. File size is so big. – Hoy Cheung Apr 22 '21 at 17:05
  • @user1978421 *"I found the codec name for hevc is libx265"* That's not a hardware accelerated encoder. FFmpeg supports many other HEVC encoders including hevc_nvenc which is what you probably want. *"So when I try to transcode the file, ffmpeg told me off"* That's an unrelated problem. *"Problem is H264 compression is no good. File size is so big."* Try hevc_nvenc and see [Best settings for FFmpeg with NVENC](https://superuser.com/a/1296511/). – llogan Apr 22 '21 at 17:16
  • Instead of trying to get this to work, I would instead have a look at a project called [other-video-transcoding] (https://github.com/donmelton/video_transcoding) by DonMelton on github. As I have found, this gives great results in compressing video without losing too much of quality. It automatically selects existing hardware for accelleration, and if there is none, it has a fallback for software based encoding as well. I use it for transcoding DVD rips made with MakeMkv before I put them onto my NAS. – DarkDiamond Apr 26 '21 at 11:47