1
2extern crate mpegts;
3
4use std::io::BufReader;
5use std::fs::File;
6use std::process;
7use std::env;
8
9use mpegts::parser::packet::parse_next_packets;
10use mpegts::writer::packet::write_packets;
11use mpegts::writer::continuity_counter::ContinuityCounter;
12
13fn main() {
14
15 if env::args().count() != 4 {
16 println!("ERROR: missing filepath argument.");
17 println!("usage:");
18 println!(" dump [input1.ts] [input2.ts] [output.ts]");
19 process::exit(0x0f00);
20 }
21
22 let source1_path = env::args().nth(1).unwrap();
23
24 let mut sources = vec![
25 env::args().nth(2).unwrap()
26 ];
27
28 let output_path = env::args().nth(3).unwrap();
29
30 let mut output_file = File::create(output_path).unwrap();
31
32 let file = File::open(source1_path).unwrap();
33 let mut stream = BufReader::new(file);
34
35 let mut cc = ContinuityCounter{streams: vec![]};
36 let mut count = 0;
37 loop {
38 match parse_next_packets(&mut stream) {
39 Ok(packets) => {
40 write_packets(&mut output_file, &packets, &mut cc);
41 count += packets.len();
42
43 print!("{:?} \r", count);
44 },
45 Err(_msg) => {
46 match sources.pop() {
47 Some(source) => {
48 let file = File::open(source).unwrap();
49 stream = BufReader::new(file);
50 },
51 None => {
52 println!("No more source");
53 return;
54 },
55 }
56 }
57 }
58 }
59}