![Tadas Barzdžius](/assets/img/avatar_default.png)
* Add avformat_close_input call to clean up AVFormantContext * Format code with rustfmt * Fix clippy lint double_parens * Fix clippy lint deref_addrof * Fix clippy lint identity_conversion * Fix clippy lint match_ref_pats * Fix clippy lint cast_lossless * Fix clippy lint cmp_null * Fix clippy lint clone_on_ref_ptr * Fix clippy lint map_clone * Fix clippy lint needless_borrow * Fix clippy lint needless_pass_by_value * Fix clippy lints for examples * Fix clippy lint unused_io_amount * Fix clippy lint new_without_default * Ignore inline_always clippy lint * Add vim temp files to .gitignore
61 lines
2.1 KiB
Rust
61 lines
2.1 KiB
Rust
extern crate ffmpeg;
|
|
|
|
use std::env;
|
|
|
|
fn main() {
|
|
ffmpeg::init().unwrap();
|
|
|
|
match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) {
|
|
Ok(ictx) => {
|
|
println!("Nb chapters: {}", ictx.nb_chapters());
|
|
|
|
for chapter in ictx.chapters() {
|
|
println!("chapter id {}:", chapter.id());
|
|
println!("\ttime_base: {}", chapter.time_base());
|
|
println!("\tstart: {}", chapter.start());
|
|
println!("\tend: {}", chapter.end());
|
|
|
|
for (k, v) in chapter.metadata().iter() {
|
|
println!("\t{}: {}", k, v);
|
|
}
|
|
}
|
|
|
|
let mut octx =
|
|
ffmpeg::format::output(&"test.mkv".to_owned()).expect("Couldn't open test file");
|
|
|
|
for chapter in ictx.chapters() {
|
|
let title = match chapter.metadata().get("title") {
|
|
Some(title) => String::from(title),
|
|
None => String::new(),
|
|
};
|
|
|
|
match octx.add_chapter(
|
|
chapter.id(),
|
|
chapter.time_base(),
|
|
chapter.start(),
|
|
chapter.end(),
|
|
&title,
|
|
) {
|
|
Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()),
|
|
Err(error) => {
|
|
println!("Error adding chapter with id: {} - {}", chapter.id(), error)
|
|
}
|
|
}
|
|
}
|
|
|
|
println!("\nOuput: nb chapters: {}", octx.nb_chapters());
|
|
for chapter in octx.chapters() {
|
|
println!("chapter id {}:", chapter.id());
|
|
println!("\ttime_base: {}", chapter.time_base());
|
|
println!("\tstart: {}", chapter.start());
|
|
println!("\tend: {}", chapter.end());
|
|
for (k, v) in chapter.metadata().iter() {
|
|
println!("\t{}: {}", k, v);
|
|
}
|
|
}
|
|
}
|
|
|
|
Err(error) => println!("error: {}", error),
|
|
}
|
|
}
|