examples/metadata: cleanup and find best streams

This commit is contained in:
meh 2015-08-28 16:33:19 +02:00
parent 549727b084
commit 13c9f8e5ab

View File

@ -7,6 +7,19 @@ fn print_metadata(context: &ffmpeg::format::Context) {
for (k, v) in context.metadata().iter() { for (k, v) in context.metadata().iter() {
println!("{}: {}", k, v); 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() { for stream in context.streams() {
println!("stream index {}:", stream.index()); println!("stream index {}:", stream.index());
println!("\ttime_base: {}", stream.time_base()); println!("\ttime_base: {}", stream.time_base());
@ -22,9 +35,9 @@ fn print_metadata(context: &ffmpeg::format::Context) {
println!("\tid: {:?}", codec.id()); println!("\tid: {:?}", codec.id());
println!("\tbit_rate: {}", codec.bit_rate()); println!("\tbit_rate: {}", codec.bit_rate());
println!("\tdelay: {}", codec.delay()); println!("\tdelay: {}", codec.delay());
if let Ok(decoder) = codec.decoder() { if let Ok(decoder) = codec.decoder() {
if let Ok(video) = decoder.video() { if let Ok(video) = decoder.video() {
println!("\tvideo.width: {}", video.width()); println!("\tvideo.width: {}", video.width());
println!("\tvideo.height: {}", video.height()); println!("\tvideo.height: {}", video.height());
println!("\tvideo.format: {:?}", video.format()); println!("\tvideo.format: {:?}", video.format());
@ -37,10 +50,11 @@ fn print_metadata(context: &ffmpeg::format::Context) {
println!("\tvideo.chroma_location: {:?}", video.chroma_location()); println!("\tvideo.chroma_location: {:?}", video.chroma_location());
println!("\tvideo.references: {}", video.references()); println!("\tvideo.references: {}", video.references());
println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision()); println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
} }
} }
if let Ok(decoder) = codec.decoder() {
if let Ok(audio) = decoder.audio() { if let Ok(decoder) = codec.decoder() {
if let Ok(audio) = decoder.audio() {
println!("\taudio.rate: {}", audio.rate()); println!("\taudio.rate: {}", audio.rate());
println!("\taudio.channels: {}", audio.channels()); println!("\taudio.channels: {}", audio.channels());
println!("\taudio.format: {:?}", audio.format()); println!("\taudio.format: {:?}", audio.format());
@ -50,18 +64,22 @@ fn print_metadata(context: &ffmpeg::format::Context) {
println!("\taudio.max_rate: {}", audio.max_rate()); println!("\taudio.max_rate: {}", audio.max_rate());
println!("\taudio.frame_start: {:?}", audio.frame_start()); println!("\taudio.frame_start: {:?}", audio.frame_start());
} }
} }
} }
} }
fn main() { fn main() {
if let Ok(()) = ffmpeg::init() { ffmpeg::init().unwrap();
if let Some(file) = env::args().nth(1) {
let path = Path::new(&file); if let Some(file) = env::args().nth(1) {
match ffmpeg::format::open(&path) { let path = Path::new(&file);
Err(error) => println!("Error: {}", error),
Ok(context) => print_metadata(&context), match ffmpeg::format::open(&path) {
} Ok(context) => print_metadata(&context),
} else { println!("Usage: metadata path/to/file") } Err(error) => println!("error: {}", error),
}
}
else {
println!("Usage: metadata <path>")
} }
} }