Skip to content

Commit

Permalink
format and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanelaf committed Aug 17, 2023
1 parent ef57a64 commit a1c331f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 37 deletions.
9 changes: 6 additions & 3 deletions src/probe/black_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ pub fn detect_black_frames(
if let Some(stream_duration) = stream.get_duration() {
end_from_duration = ((stream_duration - frame_duration) * 1000.0).round() as i64;
} else {
end_from_duration = ((results.len() as f32 - 1.0) / frame_rate * 1000.0).round() as i64;
end_from_duration =
((results.len() as f32 - 1.0) / frame_rate * 1000.0).round() as i64;
}
}
}
Expand All @@ -143,8 +144,10 @@ pub fn detect_black_frames(
}
if let Some(value) = entry_map.get("lavfi.black_end") {
if let Some(last_detect) = detected_black.last_mut() {
last_detect.end = ((value.parse::<f32>().unwrap() - frame_duration) * 1000.0).round() as i64;
let black_duration = last_detect.end - last_detect.start + (frame_duration * 1000.0).round() as i64;
last_detect.end =
((value.parse::<f32>().unwrap() - frame_duration) * 1000.0).round() as i64;
let black_duration =
last_detect.end - last_detect.start + (frame_duration * 1000.0).round() as i64;
if let Some(max) = max_duration {
if black_duration > max as i64 {
detected_black.pop();
Expand Down
2 changes: 1 addition & 1 deletion src/probe/deep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl DeepProbe {
video_indexes.clone(),
audio_indexes.clone(),
black_and_silence_parameters,
frame_duration
frame_duration,
);
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/probe/dualmono_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ pub fn detect_dualmono<S: ::std::hash::BuildHasher>(
if let AVMediaType::AVMEDIA_TYPE_VIDEO = context.get_stream_type(index as isize) {
let frame_rate = stream.get_frame_rate().to_float() as f64;
frame_duration = stream.get_frame_rate().invert().to_float() as f64;
end_from_duration = (((results.len() as f64 / audio_stream_qualif_number as f64) - 1.0) / frame_rate
* 1000.0).round() as i64;
end_from_duration = (((results.len() as f64 / audio_stream_qualif_number as f64) - 1.0)
/ frame_rate
* 1000.0)
.round() as i64;
}
}
}
Expand All @@ -195,7 +197,8 @@ pub fn detect_dualmono<S: ::std::hash::BuildHasher>(
}
if let Some(value) = entry_map.get("lavfi.aphasemeter.mono_end") {
if let Some(last_detect) = detected_dualmono.last_mut() {
last_detect.end = ((value.parse::<f64>().unwrap() - frame_duration) * 1000.0).round() as i64;
last_detect.end =
((value.parse::<f64>().unwrap() - frame_duration) * 1000.0).round() as i64;
}
}
if let Some(value) = entry_map.get("lavfi.aphasemeter.mono_duration") {
Expand All @@ -215,7 +218,8 @@ pub fn detect_dualmono<S: ::std::hash::BuildHasher>(
.as_mut()
.unwrap();
if let Some(last_detect) = detected_dualmono.last() {
let duration = last_detect.end - last_detect.start + (frame_duration * 1000.0).round() as i64;
let duration =
last_detect.end - last_detect.start + (frame_duration * 1000.0).round() as i64;
if let Some(max) = max_duration {
if duration > max as i64 {
detected_dualmono.pop();
Expand Down
12 changes: 8 additions & 4 deletions src/probe/silence_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ pub fn detect_silence<S: ::std::hash::BuildHasher>(
if let AVMediaType::AVMEDIA_TYPE_VIDEO = context.get_stream_type(index as isize) {
let frame_rate = stream.get_frame_rate().to_float() as f64;
frame_duration = stream.get_frame_rate().invert().to_float() as f64;
end_from_duration = (((results.len() as f64 / audio_indexes.clone().len() as f64) - 1.0) / frame_rate
* 1000.0).round() as i64;
end_from_duration =
(((results.len() as f64 / audio_indexes.clone().len() as f64) - 1.0) / frame_rate
* 1000.0)
.round() as i64;
}
}
}
Expand Down Expand Up @@ -142,7 +144,8 @@ pub fn detect_silence<S: ::std::hash::BuildHasher>(
}
if let Some(value) = entry_map.get("lavfi.silence_end") {
if let Some(last_detect) = detected_silence.last_mut() {
last_detect.end = ((value.parse::<f64>().unwrap() - frame_duration) * 1000.0).round() as i64;
last_detect.end =
((value.parse::<f64>().unwrap() - frame_duration) * 1000.0).round() as i64;
}
}
if let Some(value) = entry_map.get("lavfi.silence_duration") {
Expand All @@ -165,7 +168,8 @@ pub fn detect_silence<S: ::std::hash::BuildHasher>(
}
if let Some(max) = max_duration {
if let Some(last_detect) = detected_silence.last() {
let silence_duration = last_detect.end - last_detect.start + (frame_duration * 1000.0).round() as i64;
let silence_duration =
last_detect.end - last_detect.start + (frame_duration * 1000.0).round() as i64;
if silence_duration > max as i64 {
detected_silence.pop();
}
Expand Down
6 changes: 4 additions & 2 deletions src/probe/sine_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ pub fn detect_sine(
if let AVMediaType::AVMEDIA_TYPE_VIDEO = context.get_stream_type(index as isize) {
frame_rate = stream.get_frame_rate().to_float() as f64;
end_from_duration =
(((results.len() as f64 / audio_indexes.len() as f64) - 1.0) / frame_rate * 1000.0).round() as i64;
(((results.len() as f64 / audio_indexes.len() as f64) - 1.0) / frame_rate * 1000.0)
.round() as i64;
}
}
}
Expand Down Expand Up @@ -217,7 +218,8 @@ pub fn detect_sine(
sine.end = end_from_duration;
//check if sine is a 1000Hz => push and reset
if let Some(zero_crossing) = zero_cross.get(&audio_stream_key.clone()) {
let sine_duration = ((frame + 1.0) / frame_rate * 1000.0).round() as i64 - sine.start;
let sine_duration =
((frame + 1.0) / frame_rate * 1000.0).round() as i64 - sine.start;
if (zero_crossing / sine_duration as f64) == 2.0 {
detected_sine.push(sine);
last_starts.insert(audio_stream_key.clone(), None);
Expand Down
46 changes: 23 additions & 23 deletions tests/deep_probe.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"detected_black": [
{
"start": 0,
"end": 4960
"end": 4920
},
{
"start": 9960,
"end": 14960
"end": 14920
}
],
"detected_scene": [
Expand Down Expand Up @@ -63,15 +63,15 @@
"detected_silence": [
{
"start": 3000,
"end": 6000
"end": 5960
},
{
"start": 9000,
"end": 12000
"end": 11960
},
{
"start": 15000,
"end": 18000
"end": 17960
}
],
"detected_loudness": [
Expand All @@ -88,32 +88,32 @@
"detected_black_and_silence": [
{
"start": 3000,
"end": 4960
"end": 4920
},
{
"start": 9960,
"end": 12000
"end": 11960
}
],
"detected_sine": [
{
"channel": 1,
"end": 3000,
"end": 2960,
"start": 0
},
{
"channel": 1,
"end": 9000,
"end": 8960,
"start": 6000
},
{
"channel": 1,
"end": 15000,
"end": 14960,
"start": 12000
},
{
"channel": 1,
"end": 20000,
"end": 19960,
"start": 18000
}
]
Expand All @@ -131,7 +131,7 @@
"detected_silence": [
{
"start": 9000,
"end": 18000
"end": 17960
}
],
"detected_loudness": [
Expand All @@ -148,18 +148,18 @@
"detected_black_and_silence": [
{
"start": 9960,
"end": 14960
"end": 14920
}
],
"detected_sine": [
{
"channel": 1,
"end": 9000,
"end": 8960,
"start": 0
},
{
"channel": 1,
"end": 20000,
"end": 19960,
"start": 18000
}
]
Expand Down Expand Up @@ -219,19 +219,19 @@
"detected_dualmono": [
{
"start": 0,
"end": 20000
"end": 19960
}
],
"detected_silence": [],
"detected_sine": [
{
"channel": 1,
"end": 20000,
"end": 19960,
"start": 0
},
{
"channel": 2,
"end": 20000,
"end": 19960,
"start": 0
}
],
Expand Down Expand Up @@ -263,7 +263,7 @@
"detected_sine": [
{
"channel": 1,
"end": 20000,
"end": 19960,
"start": 0
}
],
Expand Down Expand Up @@ -292,14 +292,14 @@
"detected_dualmono": [
{
"start": 0,
"end": 20000
"end": 19960
}
],
"detected_silence": [],
"detected_sine": [
{
"channel": 1,
"end": 20000,
"end": 19960,
"start": 0
}
],
Expand Down Expand Up @@ -328,14 +328,14 @@
"detected_dualmono": [
{
"start": 0,
"end": 20000
"end": 19960
}
],
"detected_silence": [],
"detected_sine": [
{
"channel": 1,
"end": 20000,
"end": 19960,
"start": 0
}
],
Expand Down

0 comments on commit a1c331f

Please sign in to comment.