nschlia / ffmpegfs

FUSE-based transcoding filesystem with video support from many formats to FLAC, MP4, TS, WebM, OGG, MP3, HLS, and others.
https://nschlia.github.io/ffmpegfs/
GNU General Public License v3.0
198 stars 14 forks source link

VP9 hardware decoding causes a crash #92

Closed nschlia closed 2 years ago

nschlia commented 2 years ago

Appears that Youtube style VP9 videos can cause FFmpegfs to crash. Happens because the decoder returns errors when it starts decoding, this is too late to fall back to software. When decodeded by software, the file plays fine.

Okt 11 20:32:51 ffmpegfs[6967]: INFO   : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Transcoding to hls.
Okt 11 20:32:51 ffmpegfs[6967]: INFO   : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Decoder 'vp9' requests vaapi for device type vaapi.
Okt 11 20:32:51 ffmpegfs[6967]: INFO   : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Hardware decoder frame buffering VAAPI enabled.
Okt 11 20:32:51 ffmpegfs[6967]: INFO   : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Hardware encoder frame buffering VAAPI enabled.
Okt 11 20:32:51 ffmpegfs[6967]: INFO   : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Starting HLS segment no. 1.
Okt 11 20:32:51 ffmpegfs[6967]: INFO   : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Hardware encoder acceleration enabled. Codec 'h264_vaapi'.
Okt 11 20:32:51 ffmpegfs[6967]: INFO   : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Encoder 'h264_vaapi' requests vaapi for device type vaapi.
Okt 11 20:32:51 ffmpegfs[6967]: ERROR  : [vp9 @ 0x7fe910016080] No support for codec vp9 profile 0.
Okt 11 20:32:51 ffmpegfs[6967]: ERROR  : [vp9 @ 0x7fe910016080] Failed setup for format vaapi: hwaccel initialisation returned error.
Okt 11 20:32:51 ffmpegfs[6967]: ERROR  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Unable to decode this file using hardware acceleration. Expected format 'vaapi' not supported.
Okt 11 20:32:51 ffmpegfs[6967]: ERROR  : [vp9 @ 0x7fe910016080] Failed to initialize decoder for 1920x1080 @ 0

This causes several "Resource not available" errors, and FFmpegfs finally crashes.

It should be checked before trying to decode in hardware if the profile is available.

nschlia commented 2 years ago

That logfile part again at TRACE level:

2021-10-12 07:12:48 DEBUG  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Deinterlacing initialised with filters 'yadif=mode=send_frame:parity=auto:deint=all'.
2021-10-12 07:12:48 TRACE  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Setting threads to auto for codec aac.
2021-10-12 07:12:48 DEBUG  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Opened audio output codec AAC (Advanced Audio Coding) for stream #1.
2021-10-12 07:12:48 DEBUG  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Audio out: aac@128.0 kbps 2 Channels 44.100 kHz [08:54.592]
2021-10-12 07:12:48 DEBUG  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Video out: h264@1.20 Mbps [08:54.534]
2021-10-12 07:12:48 DEBUG  : [/root/test/cache/ffmpegfs//mnt/ffmpegfs/tmp//mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v.000001.ts.cache.ts] Writing cache file.
2021-10-12 07:12:48 TRACE  : [/root/test/cache/ffmpegfs//mnt/ffmpegfs/tmp//mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v.000001.ts.cache.ts] Mapping cache file.
2021-10-12 07:12:48 TRACE  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Processing metadata.
2021-10-12 07:12:48 TRACE  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Profile format option -movflags +faststart.
2021-10-12 07:12:48 TRACE  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Profile format option -frag_duration 1000000.
2021-10-12 07:12:48 TRACE  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Profile format option -movflags +empty_moov.
2021-10-12 07:12:48 DEBUG  : [mpegts @ 0x7f87f405a7c0] service 1 using PCR in pid=256, pcr_period=67ms
2021-10-12 07:12:48 DEBUG  : muxrate VBR,
2021-10-12 07:12:48 DEBUG  : sdt every 500 ms, pat/pmt every 100 m
2021-10-12 07:12:48 DEBUG  :
2021-10-12 07:12:48 DEBUG  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Pre-buffering up to 102400 bytes.
2021-10-12 07:12:48 DEBUG  : [vp9 @ 0x7f87f41444c0] Format vaapi chosen by get_format().
2021-10-12 07:12:48 DEBUG  : [vp9 @ 0x7f87f41444c0] Format vaapi requires hwaccel initialisation.
2021-10-12 07:12:48 ERROR  : [vp9 @ 0x7f87f41444c0] No support for codec vp9 profile 0.
2021-10-12 07:12:48 ERROR  : [vp9 @ 0x7f87f41444c0] Failed setup for format vaapi: hwaccel initialisation returned error.
2021-10-12 07:12:48 DEBUG  : [vp9 @ 0x7f87f41444c0] Format vaapi not usable, retrying get_format() without it.
2021-10-12 07:12:48 ERROR  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Unable to decode this file using hardware acceleration. Expected format 'vaapi' not supported.
2021-10-12 07:12:48 ERROR  : [vp9 @ 0x7f87f41444c0] Failed to initialize decoder for 1920x1080 @ 0
2021-10-12 07:12:48 ERROR  : [/mnt/multimedia/video/Musik/Miley Cyrus & Metallica/Live on the Stern Show/Miley Cyrus & Metallica - Nothing Else Matters.m4v] Could not send video packet at PTS=0 to decoder (error 'Operation not permitted').

Note the hint "Format vaapi not usable, retrying get_format() without it."

nschlia commented 2 years ago

Big trouble. "No support for codec vp9 profile 0." literally means my HW decoder on that machine does not support vp9 profile 0. It does not support it-

Other machines happily decode the file. The problem is that the FFmpeg API checks for profile 0 support after starting to process the file. Several audio packets have already been processed at that stage, then it encounters the first video frame and shies away from decoding it...

I probably will have to actively check the support before actually starting the transcoder.

nschlia commented 2 years ago

Crash now fixed, but the file does not decode, of course. Need to find a solution how to fall back to software in such cases.