More ffmpeg merge fixes

This commit is contained in:
bytedream 2022-02-21 15:05:45 +01:00
parent 3dfc69e2d9
commit 685dbc622e

View file

@ -123,17 +123,19 @@ func mergeSegmentsFFmpeg(context context.Context, tempDir string, outputFile str
if err != nil { if err != nil {
return err return err
} }
f, err := os.CreateTemp("", "*.txt") f, err := os.Create(filepath.Join(tempDir, "list.txt"))
if err != nil { if err != nil {
return err return err
} }
defer os.Remove(f.Name()) // -1 is the list.txt file
for i := 0; i < len(dir); i++ { for i := 0; i < len(dir)-1; i++ {
fmt.Fprintf(f, "file '%s.ts'\n", filepath.Join(tempDir, strconv.Itoa(i))) fmt.Fprintf(f, "file '%s.ts'\n", filepath.Join(tempDir, strconv.Itoa(i)))
} }
f.Close()
// predefined options ... custom options ... predefined output filename // predefined options ... custom options ... predefined output filename
command := []string{ command := []string{
"-y",
"-f", "concat", "-f", "concat",
"-safe", "0", "-safe", "0",
"-i", f.Name(), "-i", f.Name(),
@ -153,14 +155,21 @@ func mergeSegmentsFFmpeg(context context.Context, tempDir string, outputFile str
return err return err
} }
cmdChan := make(chan error) cmdChan := make(chan error, 1)
go func() { go func() {
cmdChan <- cmd.Wait() cmdChan <- cmd.Wait()
}() }()
select { select {
case <-cmdChan: case err = <-cmdChan:
return fmt.Errorf(errBuf.String()) if err != nil {
if errBuf.Len() > 0 {
return fmt.Errorf(errBuf.String())
} else {
return err
}
}
return nil
case <-context.Done(): case <-context.Done():
cmd.Process.Kill() cmd.Process.Kill()
return context.Err() return context.Err()