examples/metadata: cleanup and find best streams
This commit is contained in:
parent
549727b084
commit
13c9f8e5ab
@ -7,6 +7,19 @@ fn print_metadata(context: &ffmpeg::format::Context) {
|
||||
for (k, v) in context.metadata().iter() {
|
||||
println!("{}: {}", k, v);
|
||||
}
|
||||
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
|
||||
println!("Best video stream index: {}", stream.index());
|
||||
}
|
||||
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
|
||||
println!("Best audio stream index: {}", stream.index());
|
||||
}
|
||||
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
|
||||
println!("Best subtitle stream index: {}", stream.index());
|
||||
}
|
||||
|
||||
for stream in context.streams() {
|
||||
println!("stream index {}:", stream.index());
|
||||
println!("\ttime_base: {}", stream.time_base());
|
||||
@ -39,6 +52,7 @@ fn print_metadata(context: &ffmpeg::format::Context) {
|
||||
println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(decoder) = codec.decoder() {
|
||||
if let Ok(audio) = decoder.audio() {
|
||||
println!("\taudio.rate: {}", audio.rate());
|
||||
@ -55,13 +69,17 @@ fn print_metadata(context: &ffmpeg::format::Context) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Ok(()) = ffmpeg::init() {
|
||||
ffmpeg::init().unwrap();
|
||||
|
||||
if let Some(file) = env::args().nth(1) {
|
||||
let path = Path::new(&file);
|
||||
|
||||
match ffmpeg::format::open(&path) {
|
||||
Err(error) => println!("Error: {}", error),
|
||||
Ok(context) => print_metadata(&context),
|
||||
}
|
||||
} else { println!("Usage: metadata path/to/file") }
|
||||
Err(error) => println!("error: {}", error),
|
||||
}
|
||||
}
|
||||
else {
|
||||
println!("Usage: metadata <path>")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user