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

@@ -43,8 +43,8 @@ func (g *generatorInfo) calculateFrameRate(videoStream *ffmpeg.FFProbeStream) er
numberOfFrames, _ := strconv.Atoi(videoStream.NbFrames)
if numberOfFrames == 0 && isValidFloat64(framerate) && g.VideoFile.Duration > 0 { // TODO: test
numberOfFrames = int(framerate * g.VideoFile.Duration)
if numberOfFrames == 0 && isValidFloat64(framerate) && g.VideoFile.VideoStreamDuration > 0 { // TODO: test
numberOfFrames = int(framerate * g.VideoFile.VideoStreamDuration)
}
// If we are missing the frame count or frame rate then seek through the file and extract the info with regex
@@ -68,7 +68,7 @@ func (g *generatorInfo) calculateFrameRate(videoStream *ffmpeg.FFProbeStream) er
"number of frames or framerate is 0. nb_frames <%s> framerate <%f> duration <%f>",
videoStream.NbFrames,
framerate,
g.VideoFile.Duration,
g.VideoFile.VideoStreamDuration,
)
}

View File

@@ -39,12 +39,12 @@ func NewSpriteGenerator(videoFile ffmpeg.VideoFile, videoChecksum string, imageO
chunkCount := rows * cols
// For files with small duration / low frame count try to seek using frame number intead of seconds
if videoFile.Duration < 5 || (0 < videoFile.FrameCount && videoFile.FrameCount <= int64(chunkCount)) { // some files can have FrameCount == 0, only use SlowSeek if duration < 5
if videoFile.Duration <= 0 {
s := fmt.Sprintf("video %s: duration(%.3f)/frame count(%d) invalid, skipping sprite creation", videoFile.Path, videoFile.Duration, videoFile.FrameCount)
if videoFile.VideoStreamDuration < 5 || (0 < videoFile.FrameCount && videoFile.FrameCount <= int64(chunkCount)) { // some files can have FrameCount == 0, only use SlowSeek if duration < 5
if videoFile.VideoStreamDuration <= 0 {
s := fmt.Sprintf("video %s: duration(%.3f)/frame count(%d) invalid, skipping sprite creation", videoFile.Path, videoFile.VideoStreamDuration, videoFile.FrameCount)
return nil, errors.New(s)
}
logger.Warnf("[generator] video %s too short (%.3fs, %d frames), using frame seeking", videoFile.Path, videoFile.Duration, videoFile.FrameCount)
logger.Warnf("[generator] video %s too short (%.3fs, %d frames), using frame seeking", videoFile.Path, videoFile.VideoStreamDuration, videoFile.FrameCount)
slowSeek = true
// do an actual frame count of the file ( number of frames = read frames)
ffprobe := GetInstance().FFProbe
@@ -102,7 +102,7 @@ func (g *SpriteGenerator) generateSpriteImage() error {
if !g.SlowSeek {
logger.Infof("[generator] generating sprite image for %s", g.Info.VideoFile.Path)
// generate `ChunkCount` thumbnails
stepSize := g.Info.VideoFile.Duration / float64(g.Info.ChunkCount)
stepSize := g.Info.VideoFile.VideoStreamDuration / float64(g.Info.ChunkCount)
for i := 0; i < g.Info.ChunkCount; i++ {
time := float64(i) * stepSize

View File

@@ -40,7 +40,7 @@ func (t *GeneratePreviewTask) Start(ctx context.Context) {
videoChecksum := t.Scene.GetHash(t.fileNamingAlgorithm)
if err := t.generateVideo(videoChecksum, videoFile.Duration); err != nil {
if err := t.generateVideo(videoChecksum, videoFile.VideoStreamDuration); err != nil {
logger.Errorf("error generating preview: %v", err)
logErrorOutput(err)
return