From beda797c2cbd393eb65d81e503419835da06d5a4 Mon Sep 17 00:00:00 2001 From: Josh Allmann Date: Fri, 6 Sep 2024 03:55:51 +0000 Subject: [PATCH] Also set metadata when reopening only the muxer under nvenc. --- ffmpeg/encoder.c | 2 ++ ffmpeg/ffmpeg_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++ ffmpeg/nvidia_test.go | 5 +++++ 3 files changed, 51 insertions(+) diff --git a/ffmpeg/encoder.c b/ffmpeg/encoder.c index c930b1362b..0620ff02e2 100755 --- a/ffmpeg/encoder.c +++ b/ffmpeg/encoder.c @@ -326,6 +326,8 @@ int reopen_output(struct output_ctx *octx, struct input_ctx *ictx) ret = avio_open(&octx->oc->pb, octx->fname, AVIO_FLAG_WRITE); if (ret < 0) LPMS_ERR(reopen_out_err, "Error re-opening output file"); } + + if (octx->metadata) av_dict_copy(&octx->oc->metadata, octx->metadata, 0); ret = avformat_write_header(octx->oc, &octx->muxer->opts); if (ret < 0) LPMS_ERR(reopen_out_err, "Error re-writing header"); diff --git a/ffmpeg/ffmpeg_test.go b/ffmpeg/ffmpeg_test.go index 14bdd67da9..1b3f1e6280 100644 --- a/ffmpeg/ffmpeg_test.go +++ b/ffmpeg/ffmpeg_test.go @@ -1759,6 +1759,50 @@ func TestTranscoder_FormatOptions(t *testing.T) { } } +func TestTranscoder_Metadata(t *testing.T) { + runTestTranscoder_Metadata(t, Software) +} + +func runTestTranscoder_Metadata(t *testing.T, accel Acceleration) { + // check that metadata is there in all segments + run, dir := setupTest(t) + defer os.RemoveAll(dir) + + err := RTMPToHLS("../transcoder/test.ts", dir+"/in.m3u8", dir+"/in_%d.ts", "2", 0) + if err != nil { + t.Error(err) + } + tc := NewTranscoder() + defer tc.StopTranscoder() + for i := 0; i < 4; i++ { + in := &TranscodeOptionsIn{ + Fname: fmt.Sprintf("%s/in_%d.ts", dir, i), + Accel: accel, + } + out := []TranscodeOptions{{ + Accel: accel, + Oname: fmt.Sprintf("%s/out_%d.ts", dir, i), + Profile: P144p30fps16x9, + Metadata: map[string]string{ + "service_name": fmt.Sprintf("lpms-test-%d", i), + }, + }} + _, err := tc.Transcode(in, out) + if err != nil { + t.Error(err) + } + } + + cmd := ` + ffprobe -hide_banner -i out_1.ts + ffprobe -i out_0.ts 2>&1 | grep 'service_name : lpms-test-0' + ffprobe -i out_1.ts 2>&1 | grep 'service_name : lpms-test-1' + ffprobe -i out_2.ts 2>&1 | grep 'service_name : lpms-test-2' + ffprobe -i out_3.ts 2>&1 | grep 'service_name : lpms-test-3' + ` + run(cmd) +} + func TestTranscoder_IgnoreUnknown(t *testing.T) { run, dir := setupTest(t) defer os.RemoveAll(dir) diff --git a/ffmpeg/nvidia_test.go b/ffmpeg/nvidia_test.go index 86c0f76a88..0206c98285 100755 --- a/ffmpeg/nvidia_test.go +++ b/ffmpeg/nvidia_test.go @@ -801,3 +801,8 @@ func TestNvidia_DiscontinuityAudioSegment(t *testing.T) { func TestNvidia_Rotation(t *testing.T) { runRotationTests(t, Nvidia) } + +func TestNvidia_Metadata(t *testing.T) { + // with nvenc we reopen the outputs so exercise that + runTestTranscoder_Metadata(t, Nvidia) +}