Skip to content

Commit e606a7f

Browse files
committed
Fix short videos with length below 1 second
1 parent 79081d5 commit e606a7f

8 files changed

+76
-19
lines changed

lib/compositor_utils.ex

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ defmodule RecordingConverter.Compositor do
1414

1515
@avatar_threshold_ns 1_000_000_000
1616

17+
@spec avatar_threshold_ns() :: non_neg_integer()
18+
def avatar_threshold_ns() do
19+
@avatar_threshold_ns
20+
end
21+
1722
@spec server_setup(binary) :: :start_locally | {:start_locally, String.t()}
1823
def server_setup(compositor_path) do
1924
compositor_path = compositor_path

lib/report_parser.ex

+24-18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ defmodule RecordingConverter.ReportParser do
1313
bucket_name
1414
|> get_report(report_path)
1515
|> Map.fetch!("tracks")
16+
|> Enum.reject(fn {_key, track} ->
17+
calculate_duration_in_ns(track) < Compositor.avatar_threshold_ns()
18+
end)
1619
|> Enum.map(fn {key, value} -> Map.put(value, :id, key) end)
1720
end
1821

@@ -31,24 +34,7 @@ defmodule RecordingConverter.ReportParser do
3134

3235
@spec calculate_track_end(map(), non_neg_integer()) :: non_neg_integer()
3336
def calculate_track_end(track, offset) do
34-
clock_rate_ms = div(track["clock_rate"], 1_000)
35-
36-
end_timestamp = track["end_timestamp"]
37-
start_timestamp = track["start_timestamp"]
38-
39-
timestamp_difference =
40-
if end_timestamp < start_timestamp do
41-
end_timestamp + @max_timestamp_value - start_timestamp
42-
else
43-
end_timestamp - start_timestamp
44-
end
45-
46-
difference_in_milliseconds = div(timestamp_difference, clock_rate_ms)
47-
48-
duration =
49-
(difference_in_milliseconds - @delta_timestamp_milliseconds)
50-
|> Membrane.Time.milliseconds()
51-
|> Membrane.Time.as_nanoseconds(:round)
37+
duration = calculate_duration_in_ns(track)
5238

5339
offset + duration
5440
end
@@ -139,6 +125,26 @@ defmodule RecordingConverter.ReportParser do
139125
{audio_end_timestamp, video_end_timestamp}
140126
end
141127

128+
defp calculate_duration_in_ns(track) do
129+
clock_rate_ms = div(track["clock_rate"], 1_000)
130+
131+
end_timestamp = track["end_timestamp"]
132+
start_timestamp = track["start_timestamp"]
133+
134+
timestamp_difference =
135+
if end_timestamp < start_timestamp do
136+
end_timestamp + @max_timestamp_value - start_timestamp
137+
else
138+
end_timestamp - start_timestamp
139+
end
140+
141+
difference_in_milliseconds = div(timestamp_difference, clock_rate_ms)
142+
143+
(difference_in_milliseconds - @delta_timestamp_milliseconds)
144+
|> Membrane.Time.milliseconds()
145+
|> Membrane.Time.as_nanoseconds(:round)
146+
end
147+
142148
defp calculate_end_timestamp(tracks) do
143149
if Enum.count(tracks) > 0 do
144150
{_atom, _video_track, timestamp} = Enum.at(tracks, -1)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"tracks": {
3+
"853ec649-88a9-4629-991d-f8e2b17f93f7.msr": {
4+
"offset": 0,
5+
"type": "video",
6+
"encoding": "H264",
7+
"metadata": null,
8+
"clock_rate": 90000,
9+
"start_timestamp": 2620484184,
10+
"end_timestamp": 2620691744,
11+
"origin": 1
12+
},
13+
"87b2a39e-b62a-48b4-bc37-135da9c4d0d1.msr": {
14+
"offset": 10000000000,
15+
"type": "video",
16+
"encoding": "H264",
17+
"metadata": null,
18+
"clock_rate": 90000,
19+
"start_timestamp": 493739605,
20+
"end_timestamp": 493951365,
21+
"origin": 1
22+
},
23+
"8d49170b-d6d3-497d-ba5c-ba2837247b3c.msr": {
24+
"offset": 100000000,
25+
"type": "video",
26+
"encoding": "H264",
27+
"metadata": null,
28+
"clock_rate": 90000,
29+
"start_timestamp": 2356366771,
30+
"end_timestamp": 2356455401,
31+
"origin": 1
32+
},
33+
"9cfd9266-2256-406b-b9a1-03383243d1d8.msr": {
34+
"offset": 1000000,
35+
"type": "video",
36+
"encoding": "H264",
37+
"metadata": null,
38+
"clock_rate": 90000,
39+
"start_timestamp": 3020099711,
40+
"end_timestamp": 3020120681,
41+
"origin": 1
42+
}
43+
},
44+
"recording_id": "74"
45+
}

test/pipeline_test.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ defmodule RecordingConverter.PipelineTest do
6060
requests: 16,
6161
factor: 1
6262
},
63-
%{type: "peers-before-recording-started", requests: 15, factor: 1}
63+
%{type: "peers-before-recording-started", requests: 15, factor: 1},
64+
%{type: "short_videos", requests: 6, factor: 1}
6465
]
6566

6667
for test <- tests do

0 commit comments

Comments
 (0)