Unmanic / unmanic

Unmanic - Library Optimiser
GNU General Public License v3.0
1.65k stars 82 forks source link

Unmanic fails to initialize VAAPI properly #212

Closed mardab closed 3 years ago

mardab commented 3 years ago

Description

After confirming that VA-API now works with both of my AMD GPUs I tried re-enabling hardware acceleration as stated in provided documentation, however it still refuses to process anything in library, with -vf format=nv12|vaapi,hwupload or not.

Steps to Reproduce

  1. docker run -ti --rm \ -e PUID=$(id -u) \ -e PGID=$(id -g) \ -e TZ=Pacific/Auckland \ -p 8888:8888 \ -v ~/unmanic/config:/config \ -v ~/Videos:/library \ -v /tmp/unmanic:/tmp/unmanic \ josh5/unmanic:latest
  2. wait for worker to pick a job
  3. view details of latest job in history

Expected behavior: Completed job in history list.

Actual behaviour:

Default Unmanic Process

COMMAND:

ffmpeg -hide_banner -loglevel info -strict -2 -i /library/wjc.mp4 -vf format=nv12|vaapi,hwupload -map 0:0 -map 0:1 -c:v:0 hevc_vaapi -c:a:0 copy -y /tmp/unmanic/unmanic_file_conversion-1631100511.888833/wjc-1631100511.8888469-WORKING-1.mkv

LOG:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/library/wjc.mp4':
   Metadata:
     major_brand : isom
     minor_version : 512
     compatible_brands: isomiso2avc1mp41
     encoder : Lavf58.20.100
   Duration: 00:00:48.52, start: 0.000000, bitrate: 1336 kb/s
     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 640x480 [SAR 1:1 DAR 4:3], 1198 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
     Metadata:
       handler_name : VideoHandler
     Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default)
     Metadata:
       handler_name : SoundHandler
Stream mapping:
   Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_vaapi))
   Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[hwupload @ 0x561a5ccc1540] A hardware device reference is required to upload frames to.
[Parsed_hwupload_1 @ 0x561a5cd4df80] Query format failed for 'Parsed_hwupload_1': Invalid argument
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

Reproduces how often: 100%

Versions

0.0.9~f50e330

Installation Method Used

Used Docker, as stated above.

Additional Information

Title of this issue comes from this SO post, which seems to be the closest to what I have here.

I have 2 AMD GPUs, both HEVC-capable and available as /dev/dri/renderD12{8/9}

martadinata666 commented 3 years ago

afaik you need to define the /dev/dri to container like jellyfin sample.

Josh5 commented 3 years ago

@martadinata666 is correct.

Take a look at the documentation here: https://docs.unmanic.app/docs/advanced/hardware_accelerated_encoding_vaapi

I'll be sure to remove your linked docs as they are also obsolete.

mardab commented 3 years ago

@martadinata666 excuse me, what jellyfin sample?

@Josh5 it took me a moment to notice a difference from "obsolete" documentation (speaking of which, screenshot on that page doesn't have "Enable HW Decoding" checkbox as well, should I have it on when working with VAAPI?)

Please do not close issue prematurely, that one additional line may have fixed detection, but not initialization, so in the end, nothing beside error message has changed (sample below). I believe fixing this may lead to a better documentation, so that no issues like this will appear in the future.

RUNNER:
Default Unmanic Process

COMMAND:

ffmpeg -hide_banner -loglevel info -strict -2 -init_hw_device vaapi=vaapi0:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device vaapi0 -i /library/OBS/2021-04-22 01-53-57.mkv -vf format=nv12|vaapi,hwupload -map 0:0 -map 0:1 -c:v:0 hevc_vaapi -c:a:0 copy -y /tmp/unmanic/unmanic_file_conversion-1631680267.072676/2021-04-22 01-53-57-1631680267.0726855-WORKING-1.mkv

LOG:
Input #0, matroska,webm, from '/library/OBS/2021-04-22 01-53-57.mkv':
   Metadata:
     ENCODER : Lavf58.45.100
   Duration: 00:00:02.43, start: 0.000000, bitrate: 275 kb/s
     Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1440x750 [SAR 1:1 DAR 48:25], 30 fps, 30 tbr, 1k tbn, 60 tbc (default)
     Metadata:
       DURATION : 00:00:02.433000000
     Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp (default)
     Metadata:
       title : simple_aac_recording
       DURATION : 00:00:02.325000000
Stream mapping:
   Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_vaapi))
   Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[hevc_vaapi @ 0x5592b4bbd3c0] No quality level set; using default (25).
[hevc_vaapi @ 0x5592b4bbd3c0] Driver does not support some wanted packed headers (wanted 0xd, found 0).
[hevc_vaapi @ 0x5592b4bbd3c0] Driver does not support packed sequence headers, but a global header is requested.
[hevc_vaapi @ 0x5592b4bbd3c0] No global header will be written: this may result in a stream which is not usable for some purposes (e.g. not muxable to some containers).
Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
Error initializing output stream 0:0 --
Conversion failed! 
martadinata666 commented 3 years ago

This is a sample docker with /dev/dri passed to container. Jellyfin Docs

Unmanic docs also cover this Unmanic Docs

docker run -ti --rm \ -e PUID=${PUID} \ -e PGID=${PGID} \ --device=/dev/dri \ -p 8888:8888 \ -v ${CONFIG_DIR}:/config \ -v ${LIBRARY_DIR}:/library \ -v ${CACHE_DIR}:/tmp/unmanic \ josh5/unmanic:latest

Notice the --device=/dev/dri

mardab commented 3 years ago

Thanks @martadinata666 , however as you can still see, issue somewhat remains, as I'm unable to process any file with VAAPI enabled.

martadinata666 commented 3 years ago

Maybe try another video? Pretty suspicious abt it. So imo either something todo with video or the hardware can't encode hevc. im using athlon 200ge and random videos from youtube convert using just fine hevc_vaapi.

ffmpeg -hide_banner -loglevel info -strict -2 -init_hw_device vaapi=vaapi0:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device vaapi0 -i /library/I'm Impressed For Only $80! - Logitech G435-xnThrTIVV_w.mp4 -max_muxing_queue_size 2048 -filter_hw_device vaapi0 -vf format=nv12|vaapi,hwupload -map 0:0 -c:v:0 hevc_vaapi -y /tmp/unmanic/unmanic_file_conversion-1631803811.913881/I'm Impressed For Only $80! - Logitech G435-xnThrTIVV_w-1631803811.913889-WORKING-1.mkv

Log

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/library/I'm Impressed For Only $80! - Logitech G435-xnThrTIVV_w.mp4':
   Metadata:
     major_brand : dash
     minor_version : 0
     compatible_brands: iso6avc1mp41
     creation_time : 2021-09-14T06:01:48.000000Z
   Duration: 00:11:44.27, start: 0.000000, bitrate: 1513 kb/s
     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x960 [SAR 1:1 DAR 2:1], 5 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
     Metadata:
       creation_time : 2021-09-14T06:01:48.000000Z
       handler_name : ISO Media file produced by Google Inc.
Stream mapping:
   Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_vaapi))
Press [q] to stop, [?] for help
[hevc_vaapi @ 0x561187392580] No quality level set; using default (25).
[hevc_vaapi @ 0x561187392580] Driver does not support some wanted packed headers (wanted 0xd, found 0x1).
Output #0, matroska, to '/tmp/unmanic/unmanic_file_conversion-1631803811.913881/I'm Impressed For Only $80! - Logitech G435-xnThrTIVV_w-1631803811.913889-WORKING-1.mkv':
   Metadata:
     major_brand : dash
     minor_version : 0
     compatible_brands: iso6avc1mp41
     encoder : Lavf58.45.100
     Stream #0:0(und): Video: hevc (hevc_vaapi) (Main), vaapi_vld, 1920x960 [SAR 1:1 DAR 2:1], q=-1--1, 29.97 fps, 1k tbn, 29.97 tbc (default)
     Metadata:
       creation_time : 2021-09-14T06:01:48.000000Z
       handler_name : ISO Media file produced by Google Inc.
       encoder : Lavc58.91.100 hevc_vaapi
frame= 46 fps=0.0 q=-0.0 size= 1kB time=00:00:01.50 bitrate= 4.6kbits/s speed=2.99x
frame= 116 fps=115 q=-0.0 size= 1kB time=00:00:03.83 bitrate= 1.8kbits/s speed=3.81x
frame= 186 fps=123 q=-0.0 size= 512kB time=00:00:06.17 bitrate= 679.3kbits/s speed=4.08x
frame= 256 fps=127 q=-0.0 size= 1536kB time=00:00:08.51 bitrate=1478.6kbits/s speed=4.22x
frame= 326 fps=129 q=-0.0 size= 1536kB time=00:00:10.84 bitrate=1160.3kbits/s speed= 4.3x
frame= 396 fps=131 q=-0.0 size= 2560kB time=00:00:13.18 bitrate=1591.0kbits/s speed=4.36x
frame= 466 fps=132 q=-0.0 size= 2560kB time=00:00:15.51 bitrate=1351.5k.....
Josh5 commented 3 years ago

Have you tested this since upgrading to the latest build of unmanic?

mardab commented 3 years ago

@martadinata666 same error for every file pulled by worker. @Josh5 just pulled new image and its v0.1.0~cdde886, completely different, though much faster UI, so it will take me some time to check it.

mardab commented 3 years ago

okay, it successfully pulled through ONE video before completely breaking on next one, but that's completely different issue. Once I'm done with that I'd like to help with rewriting docs to be working with new UI.