From 17a4e418a221669926ec66ccf2390b6b1df1bd9e Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 3 Apr 2024 22:46:31 +0200 Subject: [PATCH 1/3] Fix watch status repository register --- back/src/Kyoo.Core/CoreModule.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/back/src/Kyoo.Core/CoreModule.cs b/back/src/Kyoo.Core/CoreModule.cs index 05d3a36c0..8fbfd36cc 100644 --- a/back/src/Kyoo.Core/CoreModule.cs +++ b/back/src/Kyoo.Core/CoreModule.cs @@ -57,7 +57,10 @@ public static void ConfigureKyoo(this WebApplicationBuilder builder) builder.Services.AddRepository(); builder.Services.AddRepository(); builder.Services.AddScoped(x => x.GetRequiredService()); - builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(x => + x.GetRequiredService() + ); builder.Services.AddScoped(); builder.Services.AddScoped(); } From 3abdb0a4c412de8d6a1807ea2dcddb7bc59388b5 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 3 Apr 2024 22:47:00 +0200 Subject: [PATCH 2/3] Fix videostream handle flags --- transcoder/src/videostream.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transcoder/src/videostream.go b/transcoder/src/videostream.go index 9edab552a..6c1522845 100644 --- a/transcoder/src/videostream.go +++ b/transcoder/src/videostream.go @@ -20,7 +20,7 @@ func NewVideoStream(file *FileStream, quality Quality) *VideoStream { func (vs *VideoStream) getFlags() Flags { if vs.quality == Original { - return VideoF & Transmux + return VideoF | Transmux } return VideoF } From 7c9bb11d14e6734e84fdd486131e3bc61ef36968 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 3 Apr 2024 23:42:46 +0200 Subject: [PATCH 3/3] Fix small segments cut at beginning of transcode blocks --- transcoder/src/stream.go | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/transcoder/src/stream.go b/transcoder/src/stream.go index c1d8f0dd4..0b59b8d73 100644 --- a/transcoder/src/stream.go +++ b/transcoder/src/stream.go @@ -160,25 +160,32 @@ func (ts *Stream) run(start int32) error { start_ref := float64(0) start_segment := start if start != 0 { + // we always take on segment before the current one, for different reasons for audio/video: + // - Audio: we need context before the starting point, without that ffmpeg doesnt know what to do and leave ~100ms of silence + // - Video: if a segment is really short (between 20 and 100ms), the padding given in the else block bellow is not enough and + // the previous segment is played another time. the -segment_times is way more precise so it does not do the same with this one + start_segment = start - 1 if ts.handle.getFlags()&AudioF != 0 { - // when segmenting audio, we need -ss to have the context before the start time - // without it, the cut loses a bit of audio (audio gap of ~100ms) - start_segment = start - 1 - } - // the param for the -ss takes the keyframe before the specificed time - // (if the specified time is a keyframe, it either takes that keyframe or the one before) - // to prevent this weird behavior, we specify a bit after the keyframe that interest us - if start_segment+1 == length { - start_ref = (ts.file.Keyframes.Get(start_segment) + float64(ts.file.Info.Duration)) / 2 + start_ref = ts.file.Keyframes.Get(start_segment) } else { - start_ref = (ts.file.Keyframes.Get(start_segment) + ts.file.Keyframes.Get(start_segment+1)) / 2 + // the param for the -ss takes the keyframe before the specificed time + // (if the specified time is a keyframe, it either takes that keyframe or the one before) + // to prevent this weird behavior, we specify a bit after the keyframe that interest us + + // this can't be used with audio since we need to have context before the start-time + // without this context, the cut loses a bit of audio (audio gap of ~100ms) + if start_segment+1 == length { + start_ref = (ts.file.Keyframes.Get(start_segment) + float64(ts.file.Info.Duration)) / 2 + } else { + start_ref = (ts.file.Keyframes.Get(start_segment) + ts.file.Keyframes.Get(start_segment+1)) / 2 + } } } end_padding := int32(1) if end == length { end_padding = 0 } - segments := ts.file.Keyframes.Slice(start+1, end+end_padding) + segments := ts.file.Keyframes.Slice(start_segment+1, end+end_padding) if len(segments) == 0 { // we can't leave that empty else ffmpeg errors out. segments = []float64{9999999} @@ -194,7 +201,9 @@ func (ts *Stream) run(start int32) error { "-nostats", "-hide_banner", "-loglevel", "warning", } - args = append(args, Settings.HwAccel.DecodeFlags...) + if ts.handle.getFlags()&VideoF != 0 { + args = append(args, Settings.HwAccel.DecodeFlags...) + } if start_ref != 0 { if ts.handle.getFlags()&VideoF != 0 { @@ -237,7 +246,10 @@ func (ts *Stream) run(start int32) error { args = append(args, "-f", "segment", // needed for rounding issues when forcing keyframes - "-segment_time_delta", "0.2", + // recommanded value is 1/(2*frame_rate), which for a 24fps is ~0.021 + // we take a little bit more than that to be extra safe but too much can be harmfull + // when segments are short (can make the video repeat itself) + "-segment_time_delta", "0.05", "-segment_format", "mpegts", "-segment_times", toSegmentStr(Map(segments, func(seg float64, _ int) float64 { // segment_times want durations, not timestamps so we must substract the -ss param @@ -247,7 +259,7 @@ func (ts *Stream) run(start int32) error { })), "-segment_list_type", "flat", "-segment_list", "pipe:1", - "-segment_start_number", fmt.Sprint(start), + "-segment_start_number", fmt.Sprint(start_segment), outpath, )