diff --git a/doc/content/hls_output.md b/doc/content/hls_output.md index bd322cfdd6..dbf0491433 100644 --- a/doc/content/hls_output.md +++ b/doc/content/hls_output.md @@ -73,8 +73,9 @@ not recommended for listener-facing setup but can be useful to sync up with a ca HLS outputs supports metadata in two ways: -- Through a `timed_id3` metadata logical stream with `mpegts` and `mp4` formats +- Through a `timed_id3` metadata logical stream with the `mpegts` format. - Through regular ID3 frames, as requested by the [HLS specifications](https://datatracker.ietf.org/doc/html/rfc8216#section-3.4) for `adts`, `mp3`, `ac3` and `eac3` formats. +- There is currently no support for in-stream metadata for the `mp4` format. Metadata parameters are passed through the record methods of the streams' encoders. Here's an example diff --git a/src/core/encoder/encoders/ffmpeg_encoder_common.ml b/src/core/encoder/encoders/ffmpeg_encoder_common.ml index 299f5ca401..c40a42e858 100644 --- a/src/core/encoder/encoders/ffmpeg_encoder_common.ml +++ b/src/core/encoder/encoders/ffmpeg_encoder_common.ml @@ -212,8 +212,8 @@ let encoder ~pos ~mk_streams ffmpeg meta = let init ?id3_enabled ?id3_version () = let encoder = !encoder in match Option.map Av.Format.get_output_name encoder.format with - | Some "mpegts" | Some "mp4" -> - if id3_enabled = Some true then ( + | Some "mpegts" -> + if id3_enabled <> Some false then ( let id3_version = Option.value ~default:3 id3_version in let time_base = Ffmpeg_utils.liq_audio_sample_time_base () in let stream = diff --git a/tests/streams/hls_id3v2.liq b/tests/streams/hls_id3v2.liq index 7a984bf3a2..6ce7959b7f 100644 --- a/tests/streams/hls_id3v2.liq +++ b/tests/streams/hls_id3v2.liq @@ -17,8 +17,9 @@ output.file.hls( tmp_dir, [ ("aac", %ffmpeg(format="adts",%audio(codec="aac")).{id3_version = 3}), - ("ts_with_meta", %ffmpeg(format="mpegts",%audio(codec="aac")).{id3 = true, id3_version = 4}), - ("ts", %ffmpeg(format="mpegts",%audio(codec="aac"))) + ("ts_with_meta", %ffmpeg(format="mpegts",%audio(codec="aac")).{id3_version = 4}), + ("ts", %ffmpeg(format="mpegts",%audio(codec="aac")).{ id3=false }), + ("mp4", %ffmpeg(format="mp4",frag_duration=10,movflags="+dash+skip_sidx+skip_trailer+frag_custom",%audio(codec="aac"))) ], s ) @@ -26,19 +27,21 @@ output.file.hls( to_check = ref({ aac = null(), ts_with_meta = null(), - ts = null() + ts = null(), + mp4 = null() }) def check_done() = - let { aac, ts_with_meta, ts } = to_check() + let { aac, ts_with_meta, ts, mp4 } = to_check() if null.defined(ts) then test.fail("ts shouldn't have metadata!") end + if null.defined(mp4) then test.fail("mp4 should have metadata but it's not supported by the demuxer yet.") end if null.defined(aac) and null.defined(ts_with_meta) then aac = null.get(aac) ts_with_meta = null.get(ts_with_meta) - if aac["title"] == "test title" and ts_with_meta["title"] == "test title" and - aac["album"] == "foolol" and ts_with_meta["album"] == "foolol" then + if aac["title"] == "test title" and aac["album"] == "foolol" and + ts_with_meta["title"] == "test title" and ts_with_meta["album"] == "foolol" then test.pass() end end @@ -77,4 +80,15 @@ end) output.dummy(fallible=true, ts) -clock.assign_new(sync="none",[s, aac, ts_with_meta, ts]) +mp4 = input.hls("#{tmp_dir}/mp4.m3u8") + +mp4 = source.on_metadata(mp4, fun (m) -> begin + if m["title"] != "" then + to_check := to_check().{ mp4 = m } + end + check_done() +end) + +output.dummy(fallible=true, mp4) + +clock.assign_new(sync="none",[s, aac, ts_with_meta, ts, mp4])