rust-av / grav1synth

Grain Synth analyzer and editor for AV1 files
MIT License
52 stars 3 forks source link

CapacityError in grain.rs #11

Open sonic41592 opened 1 year ago

sonic41592 commented 1 year ago

Hello, I get a CapacityError when trying to run this on a video I encoded with SVT-AV1. This will be an amazing tool if I can get it working properly, I've been very disappointed that SVT-AV1 doesn't have external denoising, and this will work perfectly to achieve the same thing.

RUST_BACKTRACE=full grav1synth inspect --output out.txt S01E01.mkv [libdav1d @ 0x55d9b85e6100] libdav1d 0.9.2 [libdav1d @ 0x55d9b87f46c0] libdav1d 0.9.2 thread 'main' panicked at 'called Result::unwrap() on an Err value: CapacityError: insufficient capacity', src/parser/grain.rs:170:26 stack backtrace: 0: 0x55d9b651c974 - std::backtrace_rs::backtrace::libunwind::trace::hf4179216f2af7039 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x55d9b651c974 - std::backtrace_rs::backtrace::trace_unsynchronized::hfa14eb12e4b8ce4f at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x55d9b651c974 - std::sys_common::backtrace::_print_fmt::hc81cbee2043ec868 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/sys_common/backtrace.rs:65:5 3: 0x55d9b651c974 - ::fmt::h7b2be2009a6bcba2 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/sys_common/backtrace.rs:44:22 4: 0x55d9b63c3ede - core::fmt::write::hccee7882499b620f at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/core/src/fmt/mod.rs:1209:17 5: 0x55d9b64ff245 - std::io::Write::write_fmt::h69e1f37bb24a9f49 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/io/mod.rs:1682:15 6: 0x55d9b651c735 - std::sys_common::backtrace::_print::h86df92192f156e4c at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/sys_common/backtrace.rs:47:5 7: 0x55d9b651c735 - std::sys_common::backtrace::print::h3b76d5113eea7ae3 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/sys_common/backtrace.rs:34:9 8: 0x55d9b6508cbf - std::panicking::default_hook::{{closure}}::h634bc187e8e58de8 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:267:22 9: 0x55d9b6508975 - std::panicking::default_hook::h262aef5e4abfc826 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:286:9 10: 0x55d9b650927f - std::panicking::rust_panic_with_hook::hedb8a8e4067bf251 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:688:13 11: 0x55d9b651cc84 - std::panicking::begin_panic_handler::{{closure}}::hf501de419c9dcde3 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:579:13 12: 0x55d9b651caac - std::sys_common::backtrace::rust_end_short_backtrace::h8542e72ad556a307 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/sys_common/backtrace.rs:137:18 13: 0x55d9b6508e32 - rust_begin_unwind at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:575:5 14: 0x55d9b63381d3 - core::panicking::panic_fmt::h1688e859668ba1d0 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/core/src/panicking.rs:65:14 15: 0x55d9b63384a3 - core::result::unwrap_failed::h9f204f08b8ff9323 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/core/src/result.rs:1791:5 16: 0x55d9b6409849 - grav1synth::parser::grain::film_grainparams::h16b105321cfcbdd2 17: 0x55d9b64032b5 - grav1synth::parser::frame::<impl grav1synth::parser::BitstreamParser<>>::parse_frame_header::hc0fc0a2ebc706c90 18: 0x55d9b641c116 - grav1synth::main::heea484d139b3a3b5 19: 0x55d9b63ea1c3 - std::sys_common::backtrace::rust_begin_short_backtrace::hae45523b8e7b83a7 20: 0x55d9b63ea4ed - std::rt::lang_start::{{closure}}::hb87baa42a4512f12 21: 0x55d9b64fe3f9 - core::ops::function::impls::<impl core::ops::function::FnOnce for &F>::call_once::h37feed43940ccfab at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/core/src/ops/function.rs:286:13 22: 0x55d9b64fe3f9 - std::panicking::try::do_call::h8fe1ed7bdb58d0f5 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:483:40 23: 0x55d9b64fe3f9 - std::panicking::try::h87c3f91ef362d0ca at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:447:19 24: 0x55d9b64fe3f9 - std::panic::catch_unwind::hd6a68686ac8f53ed at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panic.rs:137:14 25: 0x55d9b64fe3f9 - std::rt::lang_start_internal::{{closure}}::hdc22961783632ef0 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/rt.rs:148:48 26: 0x55d9b64fe3f9 - std::panicking::try::do_call::h92fd045c6d8aed83 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:483:40 27: 0x55d9b64fe3f9 - std::panicking::try::haa1526bc83feb2c9 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panicking.rs:447:19 28: 0x55d9b64fe3f9 - std::panic::catch_unwind::hb3d0e1586c57c804 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/panic.rs:137:14 29: 0x55d9b64fe3f9 - std::rt::lang_start_internal::hed890805d128cbd3 at /build/rustc-ujz1Py/rustc-1.66.1+dfsg0ubuntu1/library/std/src/rt.rs:148:20 30: 0x55d9b643b705 - main 31: 0x7fa162dc4d90 - 32: 0x7fa162dc4e40 - __libc_start_main 33: 0x55d9b6340d45 - _start 34: 0x0 -

sonic41592 commented 1 year ago

After some testing, this error seems to be caused by 10bit color depth video, since an identically encoded 8bit video works just fine

sonic41592 commented 1 year ago

I did some more testing, and I believe SVT-AV1 temporal filtering is causing the error. Encoding with the option 'enable-tf=0' solves the error. With temporal filtering enabled, using grav1synth inspect works for the first couple thousand frames before erroring. I think the film_grain_params is being given an improperly parsed BitInput for those frames, causing junk data until num_y_points exceeds it's maximum value of 14, causing the error. Interestingly, using presets 6-13 work just fine as well.