Skip to content

Commit

Permalink
fix: support subtitles outside of range
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikvedvik committed Jan 11, 2024
1 parent ddcf8b4 commit 744afc0
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions services/transcode/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "|"))
Expand All @@ -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
Expand All @@ -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
}

0 comments on commit 744afc0

Please sign in to comment.