feat(transcode): optimize video proxy quality and fix videotoolbox first-frame blocking (#426)

- Fix first-frame macroblocking on VideoToolbox hardware acceleration by avoiding -maxrate/-bufsize which triggers Apple's DataRateLimits initial rate controller starvation, applying target -b:v instead.
- Optimize software encoding (libx264) quality by adjusting CRF from 26 to 23.
- Disable B-frames (-bf 0) for libx264 proxies to ensure zero-latency frame stepping (JKL) and scrubbing, matching Frame.io review proxy standards.
- Update unit tests to verify the new encoder configurations and bitrate calculation logic.
This commit is contained in:
Yiling-J
2026-09-24 17:16:02 +08:00
committed by GitHub
parent 0d6671c3e1
commit 55637bc9a8
3 changed files with 61 additions and 27 deletions
+14 -11
View File
@@ -1312,7 +1312,7 @@ describe('TranscodeService', () => {
const encoder = await transcodeService.selectH264Encoder('auto', 'darwin')
expect(encoder.name).toBe('h264_videotoolbox')
expect(encoder.presetArgs).toEqual(['-q:v', '74'])
expect(encoder.presetArgs).toEqual([])
})
it('selectH264Encoder should select h264_nvenc on linux when available', async () => {
@@ -1448,10 +1448,10 @@ describe('TranscodeService', () => {
const encoder = await transcodeService.selectH264Encoder('auto', 'linux')
expect(encoder.name).toBe('libx264')
expect(encoder.presetArgs).toEqual(['-preset', 'fast', '-crf', '26'])
expect(encoder.presetArgs).toEqual(['-preset', 'fast', '-crf', '23', '-bf', '0'])
})
it('transcodeVideo with hardwareAcceleration off should use libx264, preset fast, crf 26, maxrate, and yuv420p', async () => {
it('transcodeVideo with hardwareAcceleration off should use libx264, preset fast, crf 23, -bf 0, maxrate, and yuv420p', async () => {
vi.mocked(execFile).mockImplementation(
(
_cmd: unknown,
@@ -1487,7 +1487,9 @@ describe('TranscodeService', () => {
'-preset',
'fast',
'-crf',
'26',
'23',
'-bf',
'0',
'-maxrate',
'720k',
'-bufsize',
@@ -1499,7 +1501,7 @@ describe('TranscodeService', () => {
)
})
it('transcodeVideo with hardwareAcceleration auto and videotoolbox should use -q:v 74 and -maxrate', async () => {
it('transcodeVideo with hardwareAcceleration auto and videotoolbox should use -b:v and no maxrate', async () => {
vi.spyOn(transcodeService, 'selectH264Encoder').mockResolvedValue(
H264_ENCODER_CONFIGS.h264_videotoolbox,
)
@@ -1536,17 +1538,16 @@ describe('TranscodeService', () => {
expect.arrayContaining([
'-c:v',
'h264_videotoolbox',
'-q:v',
'74',
'-maxrate',
'-b:v',
'720k',
'-bufsize',
'1440k',
'-pix_fmt',
'yuv420p',
]),
expect.any(Function),
)
const callArgs = vi.mocked(child_process.execFile).mock.calls[0][1] as string[]
expect(callArgs).not.toContain('-maxrate')
expect(callArgs).not.toContain('-bufsize')
})
it('transcodeVideo with hardwareAcceleration auto and nvenc should use -preset p4, -rc:v vbr, -cq:v 26, -b:v 0, and -maxrate', async () => {
@@ -1695,7 +1696,9 @@ describe('TranscodeService', () => {
'-preset',
'fast',
'-crf',
'26',
'23',
'-bf',
'0',
'-b:v',
'1500k',
'-pix_fmt',