You've already forked rust-ffmpeg
mirror of
https://github.com/encounter/rust-ffmpeg.git
synced 2026-03-30 11:37:01 -07:00
97 lines
3.4 KiB
Rust
97 lines
3.4 KiB
Rust
use std::{env, fs::File};
|
|
|
|
fn main() {
|
|
env_logger::init();
|
|
ffmpeg::init().unwrap();
|
|
|
|
let file = File::open(&env::args().nth(1).expect("missing file")).unwrap();
|
|
match ffmpeg::format::io::input(file) {
|
|
Ok(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());
|
|
}
|
|
|
|
println!(
|
|
"duration (seconds): {:?}",
|
|
context
|
|
.duration()
|
|
.map(|d| d as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE))
|
|
);
|
|
|
|
for stream in context.streams() {
|
|
println!("stream index {}:", stream.index());
|
|
println!("\ttime_base: {:?}", stream.time_base());
|
|
println!("\tstart_time: {:?}", stream.start_time());
|
|
println!("\tduration (stream timebase): {:?}", stream.duration());
|
|
println!(
|
|
"\tduration (seconds): {:?}",
|
|
stream
|
|
.time_base()
|
|
.zip(stream.duration())
|
|
.map(|(tb, d)| d as f64 * f64::from(tb))
|
|
);
|
|
println!("\tframes: {}", stream.frames());
|
|
println!("\tdisposition: {:?}", stream.disposition());
|
|
println!("\tdiscard: {:?}", stream.discard());
|
|
println!("\tframe rate: {}", stream.frame_rate());
|
|
|
|
let codec_par = stream.parameters();
|
|
println!("\tmedium: {:?}", codec_par.medium());
|
|
println!("\tid: {:?}", codec_par.id());
|
|
|
|
let dec = stream.decoder().expect("Unable to open decoder");
|
|
|
|
if codec_par.medium() == ffmpeg::media::Type::Video {
|
|
if let Ok(video) = dec.video() {
|
|
println!("\tbit_rate: {}", video.bit_rate());
|
|
println!("\tmax_rate: {}", video.max_bit_rate());
|
|
println!("\tdelay: {}", video.delay());
|
|
println!("\tvideo.width: {}", video.width());
|
|
println!("\tvideo.height: {}", video.height());
|
|
println!("\tvideo.format: {:?}", video.format());
|
|
println!("\tvideo.has_b_frames: {}", video.has_b_frames());
|
|
println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
|
|
println!("\tvideo.color_space: {:?}", video.color_space());
|
|
println!("\tvideo.color_range: {:?}", video.color_range());
|
|
println!("\tvideo.color_primaries: {:?}", video.color_primaries());
|
|
println!(
|
|
"\tvideo.color_transfer_characteristic: {:?}",
|
|
video.color_transfer_characteristic()
|
|
);
|
|
println!("\tvideo.chroma_location: {:?}", video.chroma_location());
|
|
println!("\tvideo.references: {}", video.references());
|
|
println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
|
|
}
|
|
}
|
|
else if codec_par.medium() == ffmpeg::media::Type::Audio {
|
|
if let Ok(audio) = dec.audio() {
|
|
println!("\tbit_rate: {}", audio.bit_rate());
|
|
println!("\tmax_rate: {}", audio.max_bit_rate());
|
|
println!("\tdelay: {}", audio.delay());
|
|
println!("\taudio.sample_rate: {}", audio.sample_rate());
|
|
println!("\taudio.channels: {}", audio.channels());
|
|
println!("\taudio.format: {:?}", audio.format());
|
|
println!("\taudio.frames: {}", audio.frames());
|
|
println!("\taudio.align: {}", audio.align());
|
|
println!("\taudio.channel_layout: {:?}", audio.channel_layout());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Err(error) => println!("error: {}", error),
|
|
}
|
|
}
|