RustAudio / rodio

Rust audio playback library
Apache License 2.0
1.66k stars 214 forks source link

Specific mp4a codec panics rodio #581

Closed apolunar closed 3 weeks ago

apolunar commented 1 month ago

Audio streams downloaded from YouTube fail to play in rodio, likely as a result of the codec, although it plays fine in VLC.

Here's the panic:

thread 'main' panicked at src/main.rs:31:59:
called `Result::unwrap()` on an `Err` value: IoError("end of stream")
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/result.rs:1649:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/result.rs:1073:23
   4: rustube_demo::main::{{closure}}
             at ./src/main.rs:31:17
   5: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/park.rs:281:63
   6: tokio::runtime::coop::with_budget
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/coop.rs:107:5
   7: tokio::runtime::coop::budget
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/coop.rs:73:5
   8: tokio::runtime::park::CachedParkThread::block_on
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/park.rs:281:31
   9: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/context/blocking.rs:66:9
  10: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  11: tokio::runtime::context::runtime::enter_runtime
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/context/runtime.rs:65:16
  12: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  13: tokio::runtime::runtime::Runtime::block_on
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/runtime.rs:349:45
  14: rustube_demo::main
             at ./src/main.rs:33:5
  15: core::ops::function::FnOnce::call_once
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This is the result of ffprobe:

libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'eLhSxOAaWmg.mp3':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Google
  Duration: 00:03:00.35, start: 0.000000, bitrate: 130 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 360x360 [SAR 1:1 DAR 1:1], 31 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]

The main.rs contains the "play audio" example.

apolunar commented 1 month ago

What's even stranger is that Symphonia plays it without issue. Looking into this atm.

apolunar commented 1 month ago

Seems like a duplicate of #577 I now realize, however, I'll continue to add updates here as upstream seems to be working? Unsure if the referenced codec is the same, as I'm not very familiar with audio codecs. My panic seems to be a result of this line: let mut probed = get_probe().format(&hint, mss, &format_opts, &metadata_opts)?; I've done the "scientific" process of adding breakpoints on the surrounding lines and it always panics on that line. Currently working on a fix for this.

dvdsk commented 1 month ago

Currently working on a fix for this.

Thank you very very much :+1:

What I remember from #577 the issue there was seek being very inaccurate, not the decoder crashing. The seek was off for a few seconds.

Unsure if the referenced codec is the same, as I'm not very familiar with audio codecs.

I investigated the difference as part of #577, eliminating any difference didnt fix the seek inaccuracy. Did you try updating the rodio symphonia dependency to the latest version? Maybe that fixes it?

apolunar commented 1 month ago

Ok, so it turned out to be really dumb, but still took a stupid long time to debug :pensive: (as most things of this nature do) symphonia-play breaks out of the decode loop when it encounters IoError(Custom { kind: UnexpectedEof, error: "end of stream" }) THAT'S IT. Well, in addition to selecting a track Symphonia can actually decode! If I had to do this again in the future, I would start by adding the debug statements in the working example and non-working example to find the difference (though I'm not sure that would've made it any faster), but this was a helpful experience as I don't have much experience in rust or audio codecs :+1:

I've created a pull request #582 where we can continue looking into this. This is my first(!) contribution to open source, so any guidance is much appreciated!

dvdsk commented 3 weeks ago

closed by #582