mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
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:
@@ -19,15 +19,20 @@ type VideoFile struct {
|
||||
AudioStream *FFProbeStream
|
||||
VideoStream *FFProbeStream
|
||||
|
||||
Path string
|
||||
Title string
|
||||
Comment string
|
||||
Container string
|
||||
Duration float64
|
||||
StartTime float64
|
||||
Bitrate int64
|
||||
Size int64
|
||||
CreationTime time.Time
|
||||
Path string
|
||||
Title string
|
||||
Comment string
|
||||
Container string
|
||||
// FileDuration is the declared (meta-data) duration of the *file*.
|
||||
// In most cases (sprites, previews, etc.) we actually care about the duration of the video stream specifically,
|
||||
// because those two can differ slightly (e.g. audio stream longer than the video stream, making the whole file
|
||||
// longer).
|
||||
FileDuration float64
|
||||
VideoStreamDuration float64
|
||||
StartTime float64
|
||||
Bitrate int64
|
||||
Size int64
|
||||
CreationTime time.Time
|
||||
|
||||
VideoCodec string
|
||||
VideoBitrate int64
|
||||
@@ -127,7 +132,7 @@ func parse(filePath string, probeJSON *FFProbeJSON) (*VideoFile, error) {
|
||||
|
||||
result.Container = probeJSON.Format.FormatName
|
||||
duration, _ := strconv.ParseFloat(probeJSON.Format.Duration, 64)
|
||||
result.Duration = math.Round(duration*100) / 100
|
||||
result.FileDuration = math.Round(duration*100) / 100
|
||||
fileStat, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
statErr := fmt.Errorf("error statting file <%s>: %w", filePath, err)
|
||||
@@ -178,6 +183,11 @@ func parse(filePath string, probeJSON *FFProbeJSON) (*VideoFile, error) {
|
||||
result.Width = videoStream.Width
|
||||
result.Height = videoStream.Height
|
||||
}
|
||||
result.VideoStreamDuration, err = strconv.ParseFloat(videoStream.Duration, 64)
|
||||
if err != nil {
|
||||
// Revert to the historical behaviour, which is still correct in the vast majority of cases.
|
||||
result.VideoStreamDuration = result.FileDuration
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -49,7 +49,7 @@ func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file
|
||||
AudioCodec: videoFile.AudioCodec,
|
||||
Width: videoFile.Width,
|
||||
Height: videoFile.Height,
|
||||
Duration: videoFile.Duration,
|
||||
Duration: videoFile.FileDuration,
|
||||
FrameRate: videoFile.FrameRate,
|
||||
BitRate: videoFile.Bitrate,
|
||||
Interactive: interactive,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user