Fix a few cases where ffmpeg produces no output (#3161)

* Treat no output from ffmpeg as an error condition
* Distinguish file vs. video duration, and use later where appropriate
* Check for empty file in generateFile

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
alexandra-3
2022-11-21 16:21:27 +10:00
committed by GitHub
parent 045ba55def
commit abc9ec648a
6 changed files with 44 additions and 20 deletions

View File

@@ -83,6 +83,16 @@ func (g Generator) generateFile(lockCtx *fsutil.LockContext, p Paths, pattern st
return err
}
// check if generated empty file
stat, err := os.Stat(tmpFn)
if err != nil {
return fmt.Errorf("error getting file stat: %w", err)
}
if stat.Size() == 0 {
return fmt.Errorf("ffmpeg command produced no output")
}
if err := fsutil.SafeMove(tmpFn, output); err != nil {
return fmt.Errorf("moving %s to %s", tmpFn, output)
}
@@ -142,5 +152,9 @@ func (g Generator) generateOutput(lockCtx *fsutil.LockContext, args []string) ([
return nil, fmt.Errorf("error running ffmpeg command <%s>: %w", strings.Join(args, " "), err)
}
if stdout.Len() == 0 {
return nil, fmt.Errorf("ffmpeg command produced no output: <%s>", strings.Join(args, " "))
}
return stdout.Bytes(), nil
}