Skip to content

Commit 2c439e6

Browse files
mat-hekvarsill
andauthored
Support AVC3 (#113)
* support AVC3 * address CR * Update lib/membrane_mp4/muxer/isom.ex Co-authored-by: Łukasz Kita <lukasz.kita0@gmail.com> * bump version --------- Co-authored-by: Łukasz Kita <lukasz.kita0@gmail.com>
1 parent 235566f commit 2c439e6

File tree

6 files changed

+44
-40
lines changed

6 files changed

+44
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The package can be installed by adding `membrane_mp4_plugin` to your list of dep
1212
```elixir
1313
defp deps do
1414
[
15-
{:membrane_mp4_plugin, "~> 0.35.1"}
15+
{:membrane_mp4_plugin, "~> 0.35.2"}
1616
]
1717
end
1818
```

lib/membrane_mp4/demuxer/isom.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do
4040
any_of(
4141
%Membrane.AAC{config: {:esds, _esds}},
4242
%Membrane.H264{
43-
stream_structure: {:avc1, _dcr},
43+
stream_structure: {_avc, _dcr},
4444
alignment: :au
4545
},
4646
%Membrane.H265{

lib/membrane_mp4/muxer/isom.ex

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Membrane.MP4.Muxer.ISOM do
1717
any_of(
1818
%Membrane.AAC{config: {:esds, _esds}},
1919
%Membrane.H264{
20-
stream_structure: {:avc1, _dcr},
20+
stream_structure: {_avc, _dcr},
2121
alignment: :au
2222
},
2323
%Membrane.H265{
@@ -100,21 +100,34 @@ defmodule Membrane.MP4.Muxer.ISOM do
100100
ctx,
101101
state
102102
) do
103-
cond do
103+
case {ctx.pads[pad].stream_format, stream_format} do
104104
# Handle receiving the first stream format on the given pad
105-
is_nil(ctx.pads[pad].stream_format) ->
105+
{nil, new_format} ->
106106
update_in(state, [:pad_to_track, pad_ref], fn track_id ->
107-
Track.new(track_id, stream_format, state.chunk_duration)
107+
Track.new(track_id, new_format, state.chunk_duration)
108108
end)
109109

110-
# Handle receiving all but the first stream format on the given pad,
111-
# when stream format is duplicated - ignore
112-
ctx.pads[pad].stream_format == stream_format ->
110+
# If the stream format is identical or remains H264 AVC3 or H265 HEV1,
111+
# we can be reasonably sure that the stream can still be appended
112+
# to the same MP4
113+
{stream_format, stream_format} ->
113114
state
114115

115-
# otherwise we can assume that output will be corrupted
116-
true ->
117-
raise "ISOM Muxer doesn't support variable parameters"
116+
{%Membrane.H264{stream_structure: {:avc3, _dcr1}},
117+
%Membrane.H264{stream_structure: {:avc3, _dcr2}}} ->
118+
state
119+
120+
{%Membrane.H265{stream_structure: {:hev1, _dcr1}},
121+
%Membrane.H265{stream_structure: {:hev1, _dcr2}}} ->
122+
state
123+
124+
# Otherwise we can assume that output will be corrupted
125+
{prev_format, new_format} ->
126+
raise """
127+
Unsupported stream_format change on pad #{inspect(pad_ref)}, \
128+
previous format: #{inspect(prev_format)}
129+
new format: #{inspect(new_format)}
130+
"""
118131
end
119132
|> then(&{[], &1})
120133
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Membrane.MP4.Plugin.MixProject do
22
use Mix.Project
33

4-
@version "0.35.1"
4+
@version "0.35.2"
55
@github_url "https://github.com/membraneframework/membrane_mp4_plugin"
66

77
def project do
181 KB
Binary file not shown.

test/membrane_mp4/muxer/isom/integration_test.exs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ defmodule Membrane.MP4.Muxer.ISOM.IntegrationTest do
6262
perform_test(pid, "video")
6363
end
6464

65+
test "variable parameters H264 track" do
66+
prepare_test("video")
67+
68+
structure = [
69+
child(:file, %Membrane.File.Source{location: "test/fixtures/in_video_vp.h264"})
70+
|> child(:parser, %Membrane.H264.Parser{
71+
generate_best_effort_timestamps: %{framerate: {30, 1}},
72+
output_stream_structure: :avc3
73+
})
74+
|> child(:muxer, %Membrane.MP4.Muxer.ISOM{chunk_duration: Time.seconds(1)})
75+
|> child(:sink, %Membrane.File.Sink{location: out_path_for("video_vp")})
76+
]
77+
78+
pid = Pipeline.start_link_supervised!(spec: structure)
79+
80+
perform_test(pid, "video_vp")
81+
end
82+
6583
test "single H265 track" do
6684
prepare_test("video_hevc")
6785

@@ -211,33 +229,6 @@ defmodule Membrane.MP4.Muxer.ISOM.IntegrationTest do
211229
end
212230
end
213231

214-
describe "When fed a variable parameter h264 stream, Muxer.ISOM should" do
215-
test "raise when stream format's inband_parameters are not used" do
216-
structure = [
217-
child(:file, %Membrane.File.Source{location: "test/fixtures/in_video_vp.h264"})
218-
|> child(:parser, %Membrane.H264.Parser{
219-
generate_best_effort_timestamps: %{framerate: {30, 1}},
220-
output_stream_structure: :avc1
221-
})
222-
|> child(:muxer, %Membrane.MP4.Muxer.ISOM{
223-
chunk_duration: Time.seconds(1),
224-
fast_start: true
225-
})
226-
|> child(:sink, Membrane.Fake.Sink.Buffers)
227-
]
228-
229-
{:ok, _supervisor_pid, pid} = Pipeline.start(spec: structure)
230-
monitor_ref = Process.monitor(pid)
231-
232-
assert_receive {:DOWN, ^monitor_ref, :process, ^pid,
233-
{:membrane_child_crash, :muxer,
234-
{%RuntimeError{
235-
message: "ISOM Muxer doesn't support variable parameters"
236-
}, _stacktrace}}},
237-
1_000
238-
end
239-
end
240-
241232
describe "ctts table" do
242233
test "should not be stored when dts and pts values are equal" do
243234
prepare_test("video")

0 commit comments

Comments
 (0)