diff --git a/src/probe/deep.rs b/src/probe/deep.rs index ae087e1..b0567f9 100644 --- a/src/probe/deep.rs +++ b/src/probe/deep.rs @@ -116,6 +116,7 @@ pub struct SineResult { pub struct StreamProbeResult { stream_index: usize, count_packets: usize, + total_packets_duration: i64, min_packet_size: i32, max_packet_size: i32, pub color_space: Option, @@ -243,6 +244,11 @@ impl fmt::Display for DeepProbeResult { for (index, stream) in self.streams.iter().enumerate() { writeln!(f, "\n{:30} : {:?}", "Stream Index", index)?; writeln!(f, "{:30} : {:?}", "Number of packets", stream.count_packets)?; + writeln!( + f, + "{:30} : {:?}", + "Total packets duration", stream.total_packets_duration + )?; writeln!( f, "{:30} : {:?}", @@ -315,6 +321,7 @@ impl StreamProbeResult { StreamProbeResult { stream_index: 0, count_packets: 0, + total_packets_duration: 0, color_space: None, color_range: None, color_primaries: None, @@ -418,9 +425,11 @@ impl DeepProbe { unsafe { let stream_index = (*packet.packet).stream_index as usize; let packet_size = (*packet.packet).size; + let packet_duration = (*packet.packet).duration; deep_orders.streams[stream_index].stream_index = stream_index; deep_orders.streams[stream_index].count_packets += 1; + deep_orders.streams[stream_index].total_packets_duration += packet_duration; deep_orders.streams[stream_index].min_packet_size = cmp::min( packet_size, deep_orders.streams[stream_index].min_packet_size, @@ -429,36 +438,6 @@ impl DeepProbe { packet_size, deep_orders.streams[stream_index].max_packet_size, ); - - if context.get_stream_type(stream_index as isize) == AVMediaType::AVMEDIA_TYPE_VIDEO { - if let Ok(stream) = Stream::new(context.get_stream(stream_index as isize)) { - deep_orders.streams[stream_index].color_space = stream.get_color_space(); - deep_orders.streams[stream_index].color_range = stream.get_color_range(); - deep_orders.streams[stream_index].color_primaries = stream.get_color_primaries(); - deep_orders.streams[stream_index].color_trc = stream.get_color_trc(); - deep_orders.streams[stream_index].color_matrix = stream.get_color_matrix(); - deep_orders.video_details.frame_duration = stream.get_frame_rate().invert().to_float(); - deep_orders.video_details.frame_rate = stream.get_frame_rate().to_float(); - deep_orders.video_details.time_base = stream.get_time_base().to_float(); - deep_orders.video_details.stream_duration = stream.get_duration(); - deep_orders.video_details.stream_frames = stream.get_nb_frames(); - deep_orders.video_details.bits_raw_sample = stream.get_bits_per_raw_sample(); - deep_orders.video_details.metadata_width = stream.get_width(); - deep_orders.video_details.metadata_height = stream.get_height(); - deep_orders.video_details.aspect_ratio = stream.get_picture_aspect_ratio(); - } - } - if context.get_stream_type(stream_index as isize) == AVMediaType::AVMEDIA_TYPE_AUDIO { - if let Ok(stream) = Stream::new(context.get_stream(stream_index as isize)) { - let audio_stream_details: AudioDetails = AudioDetails { - stream_index: stream_index as i32, - stream_duration: stream.get_duration(), - sample_rate: stream.get_sample_rate(), - nb_samples: (*packet.packet).duration as i32, - }; - deep_orders.audio_details.push(audio_stream_details); - } - } } } @@ -467,10 +446,37 @@ impl DeepProbe { if context.get_stream_type(stream_index as isize) == AVMediaType::AVMEDIA_TYPE_VIDEO { deep_orders.video_indexes.push(stream_index); input_id = format!("video_input_{}", stream_index); + if let Ok(stream) = Stream::new(context.get_stream(stream_index as isize)) { + deep_orders.streams[stream_index as usize].color_space = stream.get_color_space(); + deep_orders.streams[stream_index as usize].color_range = stream.get_color_range(); + deep_orders.streams[stream_index as usize].color_primaries = stream.get_color_primaries(); + deep_orders.streams[stream_index as usize].color_trc = stream.get_color_trc(); + deep_orders.streams[stream_index as usize].color_matrix = stream.get_color_matrix(); + deep_orders.video_details.frame_duration = stream.get_frame_rate().invert().to_float(); + deep_orders.video_details.frame_rate = stream.get_frame_rate().to_float(); + deep_orders.video_details.time_base = stream.get_time_base().to_float(); + deep_orders.video_details.stream_duration = stream.get_duration(); + deep_orders.video_details.stream_frames = stream.get_nb_frames(); + deep_orders.video_details.bits_raw_sample = stream.get_bits_per_raw_sample(); + deep_orders.video_details.metadata_width = stream.get_width(); + deep_orders.video_details.metadata_height = stream.get_height(); + deep_orders.video_details.aspect_ratio = stream.get_picture_aspect_ratio(); + } } if context.get_stream_type(stream_index as isize) == AVMediaType::AVMEDIA_TYPE_AUDIO { deep_orders.audio_indexes.push(stream_index); input_id = format!("audio_input_{}", stream_index); + if let Ok(stream) = Stream::new(context.get_stream(stream_index as isize)) { + let avg_pkt_duration = deep_orders.streams[stream_index as usize].total_packets_duration + / deep_orders.streams[stream_index as usize].count_packets as i64; + let audio_stream_details: AudioDetails = AudioDetails { + stream_index: stream_index as i32, + stream_duration: stream.get_duration(), + sample_rate: stream.get_sample_rate(), + nb_samples: avg_pkt_duration as i32, + }; + deep_orders.audio_details.push(audio_stream_details); + } } if context.get_stream_type(stream_index as isize) == AVMediaType::AVMEDIA_TYPE_SUBTITLE { input_id = format!("subtitle_input_{}", stream_index); diff --git a/tests/deep_probe.json b/tests/deep_probe.json index b2de8b0..e030eb1 100644 --- a/tests/deep_probe.json +++ b/tests/deep_probe.json @@ -6,6 +6,7 @@ { "stream_index": 0, "count_packets": 500, + "total_packets_duration": 500, "min_packet_size": 834, "max_packet_size": 75729, "color_space": "YUV", @@ -64,6 +65,7 @@ { "stream_index": 1, "count_packets": 500, + "total_packets_duration": 960000, "min_packet_size": 3840, "max_packet_size": 3840, "color_space": null, @@ -138,6 +140,7 @@ { "stream_index": 2, "count_packets": 500, + "total_packets_duration": 960000, "min_packet_size": 3840, "max_packet_size": 3840, "color_space": null, @@ -190,6 +193,7 @@ { "stream_index": 3, "count_packets": 500, + "total_packets_duration": 960000, "min_packet_size": 30720, "max_packet_size": 30720, "color_space": null, @@ -228,6 +232,7 @@ { "stream_index": 4, "count_packets": 500, + "total_packets_duration": 960000, "min_packet_size": 7680, "max_packet_size": 7680, "color_space": null, @@ -276,6 +281,7 @@ { "stream_index": 5, "count_packets": 500, + "total_packets_duration": 960000, "min_packet_size": 7680, "max_packet_size": 7680, "color_space": null, @@ -314,6 +320,7 @@ { "stream_index": 6, "count_packets": 500, + "total_packets_duration": 960000, "min_packet_size": 3840, "max_packet_size": 3840, "color_space": null, @@ -356,6 +363,7 @@ { "stream_index": 7, "count_packets": 500, + "total_packets_duration": 960000, "min_packet_size": 3840, "max_packet_size": 3840, "color_space": null,