pub fn parse_next_packets<R: Read>(
stream: &mut R,
) -> Result<Vec<Packet>, String>Examples found in repository?
examples/dump.rs (line 26)
11fn main() {
12
13 if env::args().count() != 2 {
14 println!("ERROR: missing filepath argument.");
15 println!("usage:");
16 println!(" dump [filepath.ts]");
17 process::exit(0x0f00);
18 }
19
20 let path = env::args().last().unwrap();
21
22 let file = File::open(path).unwrap();
23 let mut stream = BufReader::new(file);
24
25 loop {
26 let packets = parse_next_packets(&mut stream).unwrap();
27
28 for packet in packets {
29 // println!("{}", packet);
30 println!("{:?}", packet);
31 }
32 }
33}More examples
examples/concat.rs (line 38)
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}examples/pcr_measure.rs (line 34)
15fn main() {
16
17 if env::args().count() != 2 {
18 println!("ERROR: missing filepath argument.");
19 println!("usage:");
20 println!(" pcr_measure [filepath.ts]");
21 process::exit(0x0f00);
22 }
23
24 let path = env::args().last().unwrap();
25
26 let file = File::open(path).unwrap();
27 let mut stream = BufReader::new(file);
28
29 let mut ts_packet_count = 0;
30
31 let mut continuity_pcr = ContinuityPcr{streams: vec![]};
32
33 loop {
34 let packets = parse_next_packets(&mut stream).unwrap();
35
36 for packet in packets {
37 if packet.program_id == 0 {
38 continue;
39 }
40 if packet.adaptation_field.is_some() {
41 let af = packet.adaptation_field.unwrap();
42 if af.pcr.is_some() {
43 let pcr = af.pcr.unwrap();
44
45 let new_pcr = pcr.get();
46 let new_pcr_index = (ts_packet_count * TS_PACKET_SIZE) + 10;
47
48 match continuity_pcr.get(packet.program_id) {
49 None => {},
50 Some(pcr_stream) => {
51 let instant_bitrate = ((new_pcr_index as i64 - pcr_stream.index as i64) * 8 * SYSTEM_CLOCK_FREQUENCY as i64) as f64 / (new_pcr as i64 - pcr_stream.pcr as i64) as f64;
52
53 println!("{} bitrate = {:?}", packet.program_id, instant_bitrate as i64);
54 },
55 }
56
57 continuity_pcr.update(packet.program_id, new_pcr, new_pcr_index);
58 }
59 }
60
61 ts_packet_count += 1;
62 }
63 }
64}