Skip to content

Commit

Permalink
fix: rewrite the retrying of ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Sep 27, 2023
1 parent a13b4f6 commit c7a8b06
Showing 1 changed file with 71 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,46 +190,80 @@ export const PackageDeepScan: ExpectationWindowsHandler = {
let resultScenes: number[] = []
if (hasVideoStream) {
let hasGottenProgress = false
let isDone = false
currentProcess = scanMoreInfo(
sourceHandle,
ffProbeScan,
exp.endRequirement.version,
(progress) => {
hasGottenProgress = true
workInProgress._reportProgress(sourceVersionHash, 0.21 + 0.77 * progress)
},
worker.logger.category('scanMoreInfo')
)

setTimeout(() => {
if (!isDone && currentProcess && !hasGottenProgress) {
// If we haven't gotten any progress yet, we probably won't get any.

// 2023-09-20: There seems to be some bug in the FFMpeg scan where it won't output any progress
// if the scene detection is on.
// Let's abort and try again without scene detection:

currentProcess.cancel()

currentProcess = scanMoreInfo(
sourceHandle,
ffProbeScan,
{
...exp.endRequirement.version,
scenes: false, // no scene detection
},
(progress) => {
hasGottenProgress = true
workInProgress._reportProgress(sourceVersionHash, 0.21 + 0.77 * progress)
},
worker.logger.category('scanMoreInfo')
)
}
}, progressTimeout * 0.5)
currentProcess = new CancelablePromise<{
scenes: number[]
freezes: ScanAnomaly[]
blacks: ScanAnomaly[]
}>(async (resolve, reject, onCancel) => {
let isDone = false
let ignoreNextCancelError = false

const scanMoreInfoProcess = scanMoreInfo(
sourceHandle,
ffProbeScan,
exp.endRequirement.version,
(progress) => {
hasGottenProgress = true
workInProgress._reportProgress(sourceVersionHash, 0.21 + 0.77 * progress)
},
worker.logger.category('scanMoreInfo')
)
onCancel(() => {
scanMoreInfoProcess.cancel()
})

scanMoreInfoProcess.then(
(result) => {
isDone = true
resolve(result)
},
(error) => {
if (`${error}`.match(/cancelled/i) && ignoreNextCancelError) {
// ignore this
ignoreNextCancelError = false
} else {
reject(error)
}
}
)

// Guard against an edge case where we don't get any progress reports:
setTimeout(() => {
if (!isDone && currentProcess && !hasGottenProgress) {
// If we haven't gotten any progress yet, we probably won't get any.

// 2023-09-20: There seems to be some bug in the FFMpeg scan where it won't output any progress
// if the scene detection is on.
// Let's abort and try again without scene detection:

ignoreNextCancelError = true
currentProcess.cancel()

const scanMoreInfoProcessSecondTry = scanMoreInfo(
sourceHandle,
ffProbeScan,
{
...exp.endRequirement.version,
scenes: false, // no scene detection
},
(progress) => {
hasGottenProgress = true
workInProgress._reportProgress(sourceVersionHash, 0.21 + 0.77 * progress)
},
worker.logger.category('scanMoreInfo')
)

scanMoreInfoProcessSecondTry.then(
(result) => resolve(result),
(error) => reject(error)
)
}
}, progressTimeout * 0.5)
})

const result = await currentProcess
isDone = true

resultBlacks = result.blacks
resultFreezes = result.freezes
resultScenes = result.scenes
Expand Down

0 comments on commit c7a8b06

Please sign in to comment.