mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
27.84k stars 2.87k forks source link

VAAPI hardware encoders are not supported when transcoding #10510

Closed FarisR99 closed 1 year ago

FarisR99 commented 2 years ago

Important Information

Provide following Information:

Reproduction steps

Run mpv --profile=gpu-hq --vaapi-device=/dev/dri/renderD128 input.mkv -vf=format=nv12,hwupload -ovc=hevc_vaapi -o=output.mkv

Expected behavior

mpv should encode to output.mkv using hevc_vaapi

Actual behavior

Error occurs.

Log file

https://pastebin.com/XXw81ctd

Extra information

Running ffmpeg like so works: ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -i input.mkv -vf format=nv12,hwupload -c:v hevc_vaapi output.mkv Also using mpv --hwdec=vaapi works, it's just the encoding with -ovc=hevc_vaapi that doesn't.

I've tried installing Ubuntu 20.04, 22.04, Debian 11 and none work. I've also tried with both my AMD 6900XT and with Intel iGPU, and neither work.

philipl commented 2 years ago

Why would you wan to encode with mpv rather than ffmpeg?

You're also pointlessly trying to download the frames to system memory instead of passing them directly from the decoder to the encoder on the GPU side.

While I question why you'd do it this way, you'll definitely need it to do hardware decoding in mpv (--hwdec=vaapi) to have any chance of this working.

Traneptora commented 2 years ago

mpv doesn't support the hardware vaapi encoders when transcoding because it lacks the -init_hw_device or equivalent options that FFmpeg has. You'll either have to use ffmpeg, or use a software encoder like libx264.

FarisR99 commented 2 years ago

Why would you wan to encode with mpv rather than ffmpeg?

I require the --glsl-shaders feature of mpv The command I gave is just an example of what works in ffmpeg vs what doesn't work in mpv The actual command I run is a lot more complicated and longer

FarisR99 commented 2 years ago

mpv doesn't support the hardware vaapi encoders when transcoding because it lacks the -init_hw_device or equivalent options that FFmpeg has. You'll either have to use ffmpeg, or use a software encoder like libx264.

Ah, yes I noticed the lack of those specific arguments and was hoping mpv had some alternative libx264 and libx265 do work, they're just significantly slower so I'd prefer to use hardware encoding

lavilao commented 2 years ago

Why would you wan to encode with mpv rather than ffmpeg?

its easier compile mpv with support for vapoursynth and glsl shaders than to recompile ffmpeg for it.

lavilao commented 2 years ago

mpv doesn't support the hardware vaapi encoders when transcoding because it lacks the -init_hw_device or equivalent options that FFmpeg has. You'll either have to use ffmpeg, or use a software encoder like libx264.

will mpv ever add support for it?

lavilao commented 2 years ago

@thebombzen if it's not supported then why would SVP add it as an option? I have been hitting my head hard to make it work, now I see it was not me who was wrong.

BlueSwordM commented 2 years ago

@lavilao @FarisR99 You people do realize that ffmpeg does have glsl shader compatibility?

libplacebo has been a thing in ffmpeg for a while now.

lavilao commented 2 years ago

@BlueSwordM glsl yes, vapoursynth no. Edit:while I remember have seen a discussion about this, I can't find the libplacebo options now, what is it?

hooke007 commented 2 years ago

Even though you didn't use mpv, you could make a transcoding with mpv shaders.

Traneptora commented 2 years ago

ffmpeg has a libplacebo filter as linked above, and while FFmpeg technically supports vapoursynth scripts, it's much easier to just pipe it:

vspipe script.vpy --y4m - | ffmpeg -i - -c:v ...
lavilao commented 2 years ago

@thebombzen thanks, did not knew You could Pipe it. @hooke007 Thats the discussion! Although it gives me an error saying failed to set value vulkan for option init_hw_device cannot allocate memory

FarisR99 commented 2 years ago

@lavilao @FarisR99 You people do realize that ffmpeg does have glsl shader compatibility?

libplacebo has been a thing in ffmpeg for a while now.

@BlueSwordM I'm aware libplacebo exists, and have of course attempted to use it - however in my experience with it, I've been completely unsuccessful trying various different methods of using it. Sometimes errors with "filter conversions", one command works but doesn't apply any filter even though libplacebo is specified, it's all a bit of a mess. I like mpv because it makes things far easier to work with, however as stated in the original issue, I'm unable to use my AMD GPU to transcode and have to resort to libx264 which is significantly slower.

To everyone else, thanks for the suggestions - I'm aware of a lot of alternatives and have attempted some of them, but ran into issues. In the end, I'll just purchase a cheap 30 series card for NVENC which "just works".

Dudemanguy commented 1 year ago

I think it's pretty safe to say that we won't be adding hardware encoders to mpv.