1extern crate ffmpeg;
2
3use std::env;
4
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) {
9 Ok(ictx) => {
10 println!("Nb chapters: {}", ictx.nb_chapters());
11
12 for chapter in ictx.chapters() {
13 println!("chapter id {}:", chapter.id());
14 println!("\ttime_base: {}", chapter.time_base());
15 println!("\tstart: {}", chapter.start());
16 println!("\tend: {}", chapter.end());
17
18 for (k, v) in chapter.metadata().iter() {
19 println!("\t{}: {}", k, v);
20 }
21 }
22
23 let mut octx =
24 ffmpeg::format::output(&"test.mkv".to_owned()).expect("Couldn't open test file");
25
26 for chapter in ictx.chapters() {
27 let title = match chapter.metadata().get("title") {
28 Some(title) => String::from(title),
29 None => String::new(),
30 };
31
32 match octx.add_chapter(
33 chapter.id(),
34 chapter.time_base(),
35 chapter.start(),
36 chapter.end(),
37 &title,
38 ) {
39 Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()),
40 Err(error) => {
41 println!("Error adding chapter with id: {} - {}", chapter.id(), error)
42 }
43 }
44 }
45
46 println!("\nOuput: nb chapters: {}", octx.nb_chapters());
47 for chapter in octx.chapters() {
48 println!("chapter id {}:", chapter.id());
49 println!("\ttime_base: {}", chapter.time_base());
50 println!("\tstart: {}", chapter.start());
51 println!("\tend: {}", chapter.end());
52 for (k, v) in chapter.metadata().iter() {
53 println!("\t{}: {}", k, v);
54 }
55 }
56 }
57
58 Err(error) => println!("error: {}", error),
59 }
60}