Skip to content

Commit ac6a3ba

Browse files
committed
Retry Mac VideoToolbox before CPU fallback
When segmented GPU encoding fails on macOS, retry the same h264_videotoolbox encoder without segmentation before falling back to libx264. This avoids dropping directly to CPU for VideoToolbox segmentation failures.
1 parent 9c26517 commit ac6a3ba

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

Mac/src/main/main.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,9 +2198,36 @@ async function transcodeJob(job, options, outputDirectory, capabilities, reserve
21982198
const startedAt = Date.now();
21992199

22002200
try {
2201-
const segmented = options.enableSegmentation
2202-
? await transcodeSegmentedJob(job, options, outputPath, duration, capabilities, encoder, startedAt, mediaInfo)
2203-
: false;
2201+
let segmented = false;
2202+
if (options.enableSegmentation) {
2203+
try {
2204+
segmented = await transcodeSegmentedJob(job, options, outputPath, duration, capabilities, encoder, startedAt, mediaInfo);
2205+
} catch (error) {
2206+
if (cancelRequested || encoder === "libx264" || options.processingDevice === "cpu") {
2207+
throw error;
2208+
}
2209+
2210+
if (fs.existsSync(outputPath)) {
2211+
fs.rmSync(outputPath, { force: true });
2212+
}
2213+
2214+
emitJobUpdate({
2215+
id: job.id,
2216+
status: "processing",
2217+
progress: 0,
2218+
duration,
2219+
outputPath,
2220+
startedAt,
2221+
...buildTimingPayload(startedAt, duration, 0),
2222+
estimatedRemainingMs: null,
2223+
...getEncodingPayload(encoder),
2224+
message: `GPU segmented unavailable, retrying ${encoder}`
2225+
});
2226+
2227+
await runFfmpegJob(job, options, outputPath, duration, capabilities, encoder, startedAt, mediaInfo);
2228+
segmented = true;
2229+
}
2230+
}
22042231

22052232
if (!segmented) {
22062233
await runFfmpegJob(job, options, outputPath, duration, capabilities, encoder, startedAt, mediaInfo);

0 commit comments

Comments
 (0)