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());
|
||||
@ -22,9 +35,9 @@ fn print_metadata(context: &ffmpeg::format::Context) {
|
||||
println!("\tid: {:?}", codec.id());
|
||||
println!("\tbit_rate: {}", codec.bit_rate());
|
||||
println!("\tdelay: {}", codec.delay());
|
||||
|
||||
if let Ok(decoder) = codec.decoder() {
|
||||
if let Ok(video) = decoder.video() {
|
||||
|
||||
if let Ok(decoder) = codec.decoder() {
|
||||
if let Ok(video) = decoder.video() {
|
||||
println!("\tvideo.width: {}", video.width());
|
||||
println!("\tvideo.height: {}", video.height());
|
||||
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.references: {}", video.references());
|
||||
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.channels: {}", audio.channels());
|
||||
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.frame_start: {:?}", audio.frame_start());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Ok(()) = ffmpeg::init() {
|
||||
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") }
|
||||
ffmpeg::init().unwrap();
|
||||
|
||||
if let Some(file) = env::args().nth(1) {
|
||||
let path = Path::new(&file);
|
||||
|
||||
match ffmpeg::format::open(&path) {
|
||||
Ok(context) => print_metadata(&context),
|
||||
Err(error) => println!("error: {}", error),
|
||||
}
|
||||
}
|
||||
else {
|
||||
println!("Usage: metadata <path>")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user