diff --git a/services/transcode/merge.go b/services/transcode/merge.go index bfd6524e..a7afa93b 100644 --- a/services/transcode/merge.go +++ b/services/transcode/merge.go @@ -293,16 +293,10 @@ func MergeSubtitles(input common.MergeInput, progressCallback ffmpeg.ProgressCal } for _, f := range files { - info, err := os.Stat(f) + err = ensureValidSrtFile(f) if err != nil { return nil, err } - if info.Size() == 0 { - err = os.WriteFile(f, []byte("1\n00:00:00,000 --> 00:00:00,000\n"), os.ModePerm) - if err != nil { - return nil, err - } - } } concatStr := fmt.Sprintf("concat:%s", strings.Join(files, "|")) @@ -323,6 +317,11 @@ func MergeSubtitles(input common.MergeInput, progressCallback ffmpeg.ProgressCal return nil, err } + err = ensureValidSrtFile(outputFilePath) + if err != nil { + return nil, err + } + outputPath, err := paths.Parse(outputFilePath) if err != nil { return nil, err @@ -332,3 +331,18 @@ func MergeSubtitles(input common.MergeInput, progressCallback ffmpeg.ProgressCal Path: outputPath, }, err } + +func ensureValidSrtFile(f string) error { + info, err := os.Stat(f) + if err != nil { + return err + } + if info.Size() == 0 { + err = os.WriteFile(f, []byte("1\n00:00:00,000 --> 00:00:00,000\n"), os.ModePerm) + if err != nil { + return err + } + } + + return nil +}