master-of-zen / Av1an

Cross-platform command-line AV1 / VP9 / HEVC / H264 encoding framework with per scene quality encoding
GNU General Public License v3.0
1.49k stars 152 forks source link

av1an Crash on 10bit input files #579

Open vibhoothi opened 2 years ago

vibhoothi commented 2 years ago

I was testing out av1an to extract shot-selection alone, it does pretty good and dumps it, but I noticed that, whenever I try to encode a video with 10bit in raw(y4m and also mkv), av1an panics after scene-cut detection,

logs:

``` mindfreeze@garuda /m/d/v/t/d/A/t/release (master) [1]> ./av1an -e x264 -i ~/awcy/media/av2-a5-270p/ParkJoy_480x270_50.y4m --keep --temp temp2 -o dark.mp4 Output file "dark.mp4" exists. Do you want to overwrite it? [Y/n]: y Scene detection INFO [av1an_core::settings] scenecut: found 1 scene(s) [with extra_splits (240 frames): 1 scene(s)] 00:00:00 [#########################################################################################################################################################] 100% 130/130 (3021.89 fps, eta 0s)Queue 1 Workers 1 Passes 1 Params: --preset slow --crf 25 00:00:00 [#############################################################################################################################] 100% 130/130 (20.56 fps, eta 0s, 1541.0 Kbps, est. 489.08 KiB) mindfreeze@garuda /m/d/v/t/d/A/t/release (master)> ./av1an -e x264 -i ~/awcy/media/av2-a5-270p/SparksElevator_480x270p_5994_10bit.y4m --keep --temp temp2 -o dark.mp4 Output file "dark.mp4" exists. Do you want to overwrite it? [Y/n]: y Scene detection INFO [av1an_core::settings] scenecut: found 1 scene(s) [with extra_splits (240 frames): 1 scene(s)] 00:00:00 [##########################################################################################################################################################] 100% 130/130 (404.55 fps, eta 0s)thread 'main' panicked at 'FFmpeg failed to segment: Output { status: ExitStatus( unix_wait_status( 256, ), ), stdout: "", stderr: "Passing a number to -vsync is deprecated, use a string argument as described in the manual.\nInput #0, yuv4mpegpipe, from '/home/mindfreeze/awcy/media/av2-a5-270p/SparksElevator_480x270p_5994_10bit.y4m':\n Duration: 00:00:02.17, start: 0.000000, bitrate: 186440 kb/s\n Stream #0:0: Video: rawvideo (Y3[11][10] / 0xA0B3359), yuv420p10le(progressive), 480x270, 59.94 fps, 59.94 tbr, 59.94 tbn\n[matroska @ 0x561a6a90d2c0] Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or\nIf you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)\nCould not write header for output file #0 (incorrect codec parameters ?): Invalid argument\nError initializing output stream 0:0 -- \nStream mapping:\n Stream #0:0 -> #0:0 (copy)\n Last message repeated 1 times\n", }', av1an-core/src/split.rs:52:3 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ```

I am debugging the actual cause, not sure if this is normal/expected,

Versions, av1an: current master, da8ccf11d45cd83511f7da201addc647a81346b5 VapourSynth: Current master d06204cab2e4fa0e352449f88d6f30c2d4ce54c9 ffmpeg: Latest nightly N-105763-gc523724c69-20220225

Sample input 10bit 270: https://media.xiph.org/video/aomctc/test_set/a5_270p/SparksElevator_480x270p_5994_10bit.y4m

vibhoothi commented 2 years ago

Right on further quick debugging, it seems it is a muxing non-standard y4m like 420p10, 422p12 etc is the culprit,

Command to reproduce locally as per https://github.com/master-of-zen/Av1an/blob/master/av1an-core/src/split.rs#L14-L52

ffmpeg -i ~/awcy/media/av2-a5-270p/SparksElevator_480x270p_5994_10bit.y4m -map 0:V:0 -an -c copy -avoid_negative_ts 1 -vsync 0 temp/0.mkv

As ffmpeg suggests, we could pacakge it in NUT or AVI, both can be muxed, but they are not playable as such, The problem with AVI is, [avi @ 0x148806530] yuv420p10le rawvideo cannot be written to avi, output file will be unreadable More info here: https://trac.ffmpeg.org/ticket/3545 Nut container was sucessful in muxing and playback via ffplay was okay, but chunks.json was empty, logs, not entierly sure what was happening:

``` ./target/release/av1an -e x264 -i target/release/MusicVideo_1080P-04b6.mkv --keep --temp temp2 -o dark.mp4 Scene detection INFO [av1an_core::settings] scenecut: found 4 scene(s) [with extra_splits (240 frames): 4 scene(s)] 00:00:04 [#####################################################] 100% 479/479 (97.51 fps, eta 0s)Queue 0 Workers 0 Passes 1 Params: --preset slow --crf 25 00:00:00 [#########################################################] 100% 479/479 (0 fps, eta 0s)thread '' panicked at 'assertion failed: self.total_chunks != 0', av1an-core/src/broker.rs:116:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any { .. }', av1an-core/src/settings.rs:1211:21 ```

if we make y4m again, y4m muxer require reencoding so -c copy should be removed, but it should be lossless. ffmpeg -hide_banner -y -i SparksElevator_480x270p_5994_10bit.y4m -strict -1 -map 0:V:0 -an -avoid_negative_ts 1 -f segment -segment_frames 26,35,100 split/%05d.y4m

but again we are not able to mux non standard y4m there, I am open for suggestions from others on this

Edit: Probably digging down deeper on why chunk became 0 for nut case might be the best bet as the streams can be decoded and transcoded

Edit2: ffmpeg -hide_banner -y -i SparksElevator_480x270p_5994_10bit.y4m -map 0:V:0 -an -avoid_negative_ts 1 -f segment -segment_format_options strict=experimental -segment_frames 26,35,100 split/%05d.y4m So when we add -segment_format_options strict=experimental it works locally and create streams, but it fails to the av1an encode for a. y4m b. nut c. mkv, all three having the issue of total_chunks!=0 issue.

TheThing commented 2 years ago

Just wanna follow this issue as I have a ton of yuv422 10bit source files to encode :)

lastrosade commented 2 years ago

I know that this isn't really a fix but you could simply compress it in the meantime ffmpeg -i 'https://media.xiph.org/video/aomctc/test_set/a5_270p/SparksElevator_480x270p_5994_10bit.y4m' -c:v ffvhuff 'SparksElevator_480x270p_5994_10bit.mkv'

master-of-zen commented 2 years ago

I can't reproduce the issue with current av1an git

vibhoothi commented 2 years ago

@master-of-zen were you using same commandline as i used and y4m10bit! ?

./av1an -e x264 -i ~/awcy/media/av2-a5-270p/SparksElevator_480x270p_5994_10bit.y4m --keep --temp temp2 -o dark.mp4

What is your ffmpeg version?

that’s really strange as for me ffmpeg under the hood cannot split into different chunks unless we have segment format options as experimental for mkv output.

master-of-zen commented 2 years ago

2022 02 27_19:04:06

FFmpeg 5.0, current arch version

vibhoothi commented 2 years ago

That is pretty strange issue for me, tried to do a clean build and it still fails,

Just as a note, I am building ffmpeg_static cargo build --features=ffmpeg_static --release as non-static is having problems for me ie. https://paste.debian.net/1232421/ So static build worked for me, not sure if that will be different.

master-of-zen commented 2 years ago

try git reset --hard and build --release, cargo update breaks av1an for me

redzic commented 2 years ago

@vibhoothi I suspect that this would be solved by using lsmash/ffms2, as it appears that you are using hybrid chunking which does not work as well. Can you try either running av1an in docker, or installing lsmash or ffms2?