diff --git a/lib/membrane_mp4/demuxer/isom.ex b/lib/membrane_mp4/demuxer/isom.ex index 26ea986..0dd03a3 100644 --- a/lib/membrane_mp4/demuxer/isom.ex +++ b/lib/membrane_mp4/demuxer/isom.ex @@ -40,7 +40,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do any_of( %Membrane.AAC{config: {:esds, _esds}}, %Membrane.H264{ - stream_structure: {:avc1, _dcr}, + stream_structure: {_avc, _dcr}, alignment: :au }, %Membrane.H265{ diff --git a/lib/membrane_mp4/muxer/isom.ex b/lib/membrane_mp4/muxer/isom.ex index 2e1169c..0c55c4b 100644 --- a/lib/membrane_mp4/muxer/isom.ex +++ b/lib/membrane_mp4/muxer/isom.ex @@ -17,7 +17,7 @@ defmodule Membrane.MP4.Muxer.ISOM do any_of( %Membrane.AAC{config: {:esds, _esds}}, %Membrane.H264{ - stream_structure: {:avc1, _dcr}, + stream_structure: {_avc, _dcr}, alignment: :au }, %Membrane.H265{ @@ -96,25 +96,28 @@ defmodule Membrane.MP4.Muxer.ISOM do @impl true def handle_stream_format( Pad.ref(:input, pad_ref) = pad, - stream_format, + %type{} = stream_format, ctx, state ) do - cond do + case ctx.pads[pad].stream_format do # Handle receiving the first stream format on the given pad - is_nil(ctx.pads[pad].stream_format) -> + nil -> update_in(state, [:pad_to_track, pad_ref], fn track_id -> Track.new(track_id, stream_format, state.chunk_duration) end) - # Handle receiving all but the first stream format on the given pad, - # when stream format is duplicated - ignore - ctx.pads[pad].stream_format == stream_format -> + # Handle receiving a stream format of the same type + %^type{} -> state # otherwise we can assume that output will be corrupted - true -> - raise "ISOM Muxer doesn't support variable parameters" + previos_format -> + raise """ + Unsupported stream_format change on pad #{inspect(pad_ref)}, \ + previous format: #{inspect(previos_format)} + new format: #{inspect(stream_format)} + """ end |> then(&{[], &1}) end diff --git a/test/fixtures/isom/ref_video_vp.mp4 b/test/fixtures/isom/ref_video_vp.mp4 new file mode 100644 index 0000000..b64747d Binary files /dev/null and b/test/fixtures/isom/ref_video_vp.mp4 differ diff --git a/test/membrane_mp4/muxer/isom/integration_test.exs b/test/membrane_mp4/muxer/isom/integration_test.exs index f3f74a8..0424798 100644 --- a/test/membrane_mp4/muxer/isom/integration_test.exs +++ b/test/membrane_mp4/muxer/isom/integration_test.exs @@ -62,6 +62,24 @@ defmodule Membrane.MP4.Muxer.ISOM.IntegrationTest do perform_test(pid, "video") end + test "variable parameters H264 track" do + prepare_test("video") + + structure = [ + child(:file, %Membrane.File.Source{location: "test/fixtures/in_video_vp.h264"}) + |> child(:parser, %Membrane.H264.Parser{ + generate_best_effort_timestamps: %{framerate: {30, 1}}, + output_stream_structure: :avc3 + }) + |> child(:muxer, %Membrane.MP4.Muxer.ISOM{chunk_duration: Time.seconds(1)}) + |> child(:sink, %Membrane.File.Sink{location: out_path_for("video_vp")}) + ] + + pid = Pipeline.start_link_supervised!(spec: structure) + + perform_test(pid, "video_vp") + end + test "single H265 track" do prepare_test("video_hevc") @@ -210,58 +228,4 @@ defmodule Membrane.MP4.Muxer.ISOM.IntegrationTest do perform_test(pid, "two_tracks_fast_start") end end - - describe "When fed a variable parameter h264 stream, Muxer.ISOM should" do - test "raise when stream format's inband_parameters are not used" do - structure = [ - child(:file, %Membrane.File.Source{location: "test/fixtures/in_video_vp.h264"}) - |> child(:parser, %Membrane.H264.Parser{ - generate_best_effort_timestamps: %{framerate: {30, 1}}, - output_stream_structure: :avc1 - }) - |> child(:muxer, %Membrane.MP4.Muxer.ISOM{ - chunk_duration: Time.seconds(1), - fast_start: true - }) - |> child(:sink, Membrane.Fake.Sink.Buffers) - ] - - {:ok, _supervisor_pid, pid} = Pipeline.start(spec: structure) - monitor_ref = Process.monitor(pid) - - assert_receive {:DOWN, ^monitor_ref, :process, ^pid, - {:membrane_child_crash, :muxer, - {%RuntimeError{ - message: "ISOM Muxer doesn't support variable parameters" - }, _stacktrace}}}, - 1_000 - end - end - - describe "ctts table" do - test "should not be stored when dts and pts values are equal" do - prepare_test("video") - - structure = [ - child(:file, %Membrane.File.Source{location: "test/fixtures/in_video.h264"}) - |> child(:parser, %Membrane.H264.Parser{ - generate_best_effort_timestamps: %{framerate: {30, 1}, add_dts_offset: false}, - output_stream_structure: :avc1 - }) - |> child(:muxer, %Membrane.MP4.Muxer.ISOM{chunk_duration: Time.seconds(1)}) - |> child(:sink, %Membrane.File.Sink{location: out_path_for("video")}) - ] - - pid = Pipeline.start_link_supervised!(spec: structure) - - assert_end_of_stream(pid, :sink, :input) - refute_sink_buffer(pid, :sink, _buffer, 0) - - assert :ok == Pipeline.terminate(pid) - - assert {parsed_out, <<>>} = out_path_for("video") |> File.read!() |> Container.parse!() - assert Container.get_box(parsed_out, [:moov, :trak, :mdia, :minf, :stbl, :stts]) - refute Container.get_box(parsed_out, [:moov, :trak, :mdia, :minf, :stbl, :ctts]) - end - end end