From 153f10f595fdae9060dbfbce1542cfa0ffb17b96 Mon Sep 17 00:00:00 2001 From: Daniel Morandini Date: Wed, 17 Apr 2024 14:46:23 +0200 Subject: [PATCH 1/3] Add reset_timestamps option --- lib/membrane_rtmp_plugin/rtmp/sink/sink.ex | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex b/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex index cb9014c6..6cfa04d7 100644 --- a/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex +++ b/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex @@ -52,6 +52,14 @@ defmodule Membrane.RTMP.Sink do description: """ A list of tracks, which will be sent. Can be `:audio`, `:video` or both. """ + ], + reset_timestamps: [ + spec: boolean(), + default: true, + description: """ + If enabled, this feature adjusts the timing of outgoing FLV packets so that they begin from zero. + Leaves it untouched otherwise. + """ ] @impl true @@ -89,7 +97,8 @@ defmodule Membrane.RTMP.Sink do # remaining pad are simply forwarded to the output. # Always on if a single track is connected forward_mode?: single_track?, - video_base_dts: nil + video_base_dts: nil, + reset_timestampts: options.reset_timestamps }) {[], state} @@ -303,15 +312,13 @@ defmodule Membrane.RTMP.Sink do end defp write_frame(state, Pad.ref(:video, 0), buffer) do - dts = buffer.dts || buffer.pts - pts = buffer.pts || buffer.dts - {base_dts, state} = Bunch.Map.get_updated!(state, :video_base_dts, &(&1 || dts)) + {{dts, pts}, state} = buffer_timings(buffer, state) case Native.write_video_frame( state.native, buffer.payload, - dts - base_dts, - pts - base_dts, + dts, + pts, buffer.metadata.h264.key_frame? ) do {:ok, native} -> @@ -321,4 +328,19 @@ defmodule Membrane.RTMP.Sink do raise "writing video frame failed with reason: #{inspect(reason)}" end end + + defp buffer_timings(buffer, state) do + dts = buffer.dts || buffer.pts + pts = buffer.pts || buffer.dts + correct_timings(dts, pts, state) + end + + defp correct_timings(dts, pts, state = %{reset_timestamps: false}) do + {{dts, pts}, state} + end + + defp correct_timings(dts, pts, state) do + {base_dts, state} = Bunch.Map.get_updated!(state, :video_base_dts, &(&1 || dts)) + {{dts - base_dts, pts - base_dts}, state} + end end From abdccb53af289e127a1bb81e5e6165ecc26b40e4 Mon Sep 17 00:00:00 2001 From: Daniel Morandini Date: Tue, 23 Apr 2024 09:58:38 +0200 Subject: [PATCH 2/3] Fix credo, merge origin/master --- lib/membrane_rtmp_plugin/rtmp/sink/sink.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex b/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex index 6cfa04d7..1e947c57 100644 --- a/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex +++ b/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex @@ -335,7 +335,7 @@ defmodule Membrane.RTMP.Sink do correct_timings(dts, pts, state) end - defp correct_timings(dts, pts, state = %{reset_timestamps: false}) do + defp correct_timings(dts, pts, %{reset_timestamps: false} = state) do {{dts, pts}, state} end From 5de8bfb4e61cc1a4e8ca38289a35be709141a465 Mon Sep 17 00:00:00 2001 From: Daniel Morandini Date: Tue, 23 Apr 2024 09:59:14 +0200 Subject: [PATCH 3/3] Bump version --- README.md | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 956abf23..a13d02d3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The package can be installed by adding `membrane_rtmp_plugin` to your list of de ```elixir def deps do [ - {:membrane_rtmp_plugin, "~> 0.23.3"} + {:membrane_rtmp_plugin, "~> 0.23.4"} ] end ``` diff --git a/mix.exs b/mix.exs index 010e186c..8a54ca7c 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Membrane.RTMP.Mixfile do use Mix.Project - @version "0.23.3" + @version "0.23.4" @github_url "https://github.com/membraneframework/membrane_rtmp_plugin" def project do