feat: implement duration validation check after encoding to ensure file integrity
This commit is contained in:
@@ -231,12 +231,32 @@ func (m *Manager) runEncoder(job db.Job) error {
|
|||||||
return fmt.Errorf("ffmpeg error: %v, last output: %s", err, lastErrLine)
|
return fmt.Errorf("ffmpeg error: %v, last output: %s", err, lastErrLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate
|
// Validate format integrity
|
||||||
if err := m.encoder.ValidateFile(tempOutPath); err != nil {
|
if err := m.encoder.ValidateFile(tempOutPath); err != nil {
|
||||||
os.Remove(tempOutPath)
|
os.Remove(tempOutPath)
|
||||||
return fmt.Errorf("validation failed: %w", err)
|
return fmt.Errorf("validation failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate duration (ensure it wasn't cut short)
|
||||||
|
if duration > 0 {
|
||||||
|
outDuration, err := m.encoder.ProbeDuration(tempOutPath)
|
||||||
|
if err != nil {
|
||||||
|
os.Remove(tempOutPath)
|
||||||
|
return fmt.Errorf("failed to probe output duration: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow up to 5 seconds of difference (sometimes containers/padding vary slightly)
|
||||||
|
diff := duration - outDuration
|
||||||
|
if diff < 0 {
|
||||||
|
diff = -diff
|
||||||
|
}
|
||||||
|
|
||||||
|
if diff > 5.0 {
|
||||||
|
os.Remove(tempOutPath)
|
||||||
|
return fmt.Errorf("duration mismatch: original is %.2fs, encoded is %.2fs", duration, outDuration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate sizes
|
// Calculate sizes
|
||||||
outInfo, err := os.Stat(tempOutPath)
|
outInfo, err := os.Stat(tempOutPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user