Page 1 of 1

FFmpeg hardware accelerated transcoding

Posted: Thu Sep 13, 2018 11:30 am
by clicktician
Many thanks to the MX dev team for the great work getting hardware acceleration integrated in the FFmpeg 3.x build. (Probably Stevo's handy work).
Video transcoding is something I do every day, and I just took it for granted that FFmpeg was the same on all distros. Oh, no it's not!

At a friend's house last nite (a wool-dyed Ubuntu/Mint family) and he was transcoding a 96 minute bluray mkv movie to dvd quality mp4 to load on his phone. After an hour went by, I volunteered to do it on my MX17 tablet.
It took 4 mins.

To my surprise, his FFmpeg build had no GPU support.
I got home and felt so grateful that this stuff just works for me on MX without a big fight.

Re: FFmpeg hardware accelerated transcoding

Posted: Thu Sep 13, 2018 1:17 pm
by Stevo
Give credit to the Debian team for having the hardware acceleration built in for ffmpeg, not me; I just backport their configuration...though if you're talking about using Handbrake with Intel GPU support, we're porting the deb-multimedia version which leverages libmfx for that, which the Debian/Ubuntu/Mint versions do not.

Re: FFmpeg hardware accelerated transcoding

Posted: Thu Sep 13, 2018 2:11 pm
by clicktician
Stevo wrote:
Thu Sep 13, 2018 1:17 pm
Give credit to the Debian team for having the hardware acceleration built in for ffmpeg, not me; I just backport their configuration...though if you're talking about using Handbrake with Intel GPU support, we're porting the deb-multimedia version which leverages libmfx for that, which the Debian/Ubuntu/Mint versions do not.
Excellent. I use the heck out of FFmpeg because it has hardware accel. I'd use Handbrake a lot more if it had it, too. Can't wait.

Re: FFmpeg hardware accelerated transcoding

Posted: Thu Sep 13, 2018 4:01 pm
by Stevo
clicktician wrote:
Thu Sep 13, 2018 2:11 pm
Stevo wrote:
Thu Sep 13, 2018 1:17 pm
Give credit to the Debian team for having the hardware acceleration built in for ffmpeg, not me; I just backport their configuration...though if you're talking about using Handbrake with Intel GPU support, we're porting the deb-multimedia version which leverages libmfx for that, which the Debian/Ubuntu/Mint versions do not.
Excellent. I use the heck out of FFmpeg because it has hardware accel. I'd use Handbrake a lot more if it had it, too. Can't wait.
What was it using in your tablet? Did you have to pass any special flag in the ffmpeg command?

Re: FFmpeg hardware accelerated transcoding

Posted: Thu Sep 13, 2018 5:28 pm
by clicktician
Stevo wrote:
Thu Sep 13, 2018 4:01 pm
What was it using in your tablet? Did you have to pass any special flag in the ffmpeg command?
Oh, yeah. You have to tell FFmpeg explicitly to use Nvidia, AMD, or Intel. It has a special set of args for them. On my tablet (a dinky Intel atom with 6xx gpu), it's the standard vaapi set. So, I used something like this:

Code: Select all

/usr/bin/ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.mkv -vf 'hwupload,fps=29.97,scale_vaapi=w=864:h=486:format=nv12' -c:v h264_vaapi -threads 0 -qp 20 -acodec copy output.mp4
In this case, I wanted to open the mp4 stream of the mkv file, upload the frames to the device "renderD128", then I wanted the hardware to filter it to 29.97 fps and scale down to dvd resolution. The original color space was in yuv420p, but intel hardware only understands nv12, so FFmpeg had to filter the format, too. Normally you would download the frames to FFmpeg's memory space (hwdownload) and process the output there, but I told it to let the GPU re-encode the frames as h264_vaapi because it's mucho presto presto. The audio on the mkv was already AAC, so I just copied it to the output mp4 container, but I could have re-encoded it, too. The -threads arg is probably the default, but I always throw it in for good measure out of habit. -qp, of course, is the quality and lower is better. The Intel hardware can also deinterlace if you want the output progressive, but the mkv stream was already progressive.

I have the 965 driver installed, along with vainfo.

Code: Select all

apt-get install i965-va-driver vainfo
You can see what capabilities your Intel GPU has with the "vainfo" command. But I'm sure you can process mpg1-2, divix, h264, and h265 on anything that's recent.