Open NightlySide opened 2 years ago
In your code you're calling Decoder::new_aac(buf)
, but for m4a you need to call Decoder::new_mpeg4(buf, size)
. Check out the m4a example
This is the next thing I tried with the folllowing code :
let file = File::open(path).expect("error opening file");
let metadata = file.metadata().unwrap();
let size = metadata.len();
let buf = BufReader::new(file);
let decoder = redlux::Decoder::new_mpeg4(buf, size).unwrap();
let output_stream = OutputStream::try_default();
let (_stream, handle) = output_stream.expect("Error creating output stream");
let sink = Sink::try_new(&handle).expect("Error creating sink");
println!("Total duraction: {:?}", decoder.total_duration());
sink.append(decoder);
println!("Playing");
sink.play();
sink.set_volume(1.0);
sink.sleep_until_end();
println!("End of track");
I'm facing another error : thread 'main' panicked at 'called
Result::unwrap()on an
Errvalue: FileHeaderError', src/main.rs:23:57 note: run with
RUST_BACKTRACE=1environment variable to display a backtrace
. When i rerun my program with RUST_BACKTRACE=1 I got the following :
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: FileHeaderError', src/main.rs:23:57
stack backtrace:
0: rust_begin_unwind
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
1: core::panicking::panic_fmt
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
2: core::result::unwrap_failed
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/result.rs:1616:5
3: core::result::Result<T,E>::unwrap
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/result.rs:1298:23
4: ytdl_test::play::{{closure}}
at ./src/main.rs:23:19
5: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/future/mod.rs:80:19
6: ytdl_test::main::{{closure}}
at ./src/main.rs:14:5
7: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/future/mod.rs:80:19
8: tokio::park::thread::CachedParkThread::block_on::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/park/thread.rs:263:54
9: tokio::coop::with_budget::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:102:9
10: std::thread::local::LocalKey<T>::try_with
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/thread/local.rs:399:16
11: std::thread::local::LocalKey<T>::with
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/thread/local.rs:375:9
12: tokio::coop::with_budget
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:95:5
13: tokio::coop::budget
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:72:5
14: tokio::park::thread::CachedParkThread::block_on
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/park/thread.rs:263:31
15: tokio::runtime::enter::Enter::block_on
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/enter.rs:151:13
16: tokio::runtime::thread_pool::ThreadPool::block_on
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/thread_pool/mod.rs:77:9
17: tokio::runtime::Runtime::block_on
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/mod.rs:463:43
18: ytdl_test::main
at ./src/main.rs:14:5
19: core::ops::function::FnOnce::call_once
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
The file is the one in the link and it plays with vlc
Which line is line 23?
I'm getting a 403 error from the link, could you upload it here directly as a zip?
Yes, sorry there is the file : videoplayback.zip
And the line 23 is the one where I'm creating the decoder :
let decoder = redlux::Decoder::new_mpeg4(buf, size).unwrap();
I'd be glad to take the look at your project source code but I don't understand at least half of what's written 😅
@NightlySide Nice choice of song! ffprobe
says the file is 4m24s, but QuickTime Player says it's 9m09s, so I think whatever causes that might be the issue. If the problem is with fdk-aac, it's not something that can be fixed here
The error actually comes from read_sample
here:
https://github.com/probablykasper/redlux/blob/4b4ac14c470963988cbe1a6fbdd829bf2cf7e139/src/lib.rs#L163
Err(IoError(Error { kind: UnexpectedEof, message: "failed to fill whole buffer" }))
So it seems like an issue with the mp4 crate. I tried updating to mp4 0.9, but then that issue started happening for all m4a files (https://github.com/alfg/mp4-rust/issues/68)
Hello! I'm glad you liked the song 😅
What bums me is the fact that this file is what come directly from youtube when making a request to their player API.. Maybe it's just their fault 😦 I don't really want to use a third party software besides my Rust code (or else I could just use ffmpeg for that)
Do you suggest I should open an issue there? (Thanks again :) )
EDIT: well I didn't see you opened a new issue, i will keep an eye on it if the ticket status changes
I've run into this before as well, I don't know if it's an encoding or decoding issue, but some decoders handle it fine while others don't
Okay.. I tried to follow the execution path in the MP4 crate, I'm pretty sure it's a decoding issue as other decoders seem to read the file
I'm hoping the maintainers of the MP4 crate have an idea for this issue
@NightlySide Do you know if this issue happens with more recent versions of the mp4
crate?
Hello, I want to say thank you first for this great crate.
I followed the examples and manage to play an AAC file without any problem. However when trying to play an .m4a (using the MPEG-4 AAC codec) from youtube-dl (example : https://bit.ly/3JKrlRL) playing the sink automatically goes to the end without playing the song.. What did I do wrong ?
Thank you in advance
PS: here is the following code i'm using