Skip to content

Bug: FFmpeg pipeline crashes in Phase 3 (H.265) due to invalid '-tune film' argument #20

@maulik-mk

Description

@maulik-mk

Description :
The video processing worker crashes during the Phase_3_H265_SDR and Phase_4_H265_HDR encoding phases. The crash is caused by the FFmpeg command failing with an Invalid argument (-22) error.

Root Cause :
In src/infrastructure/ffmpeg/encoding/flags.ts, the -tune film flag is hardcoded for all video encodes in the videoEncoderFlags function. While the libx264 (AVC) encoder supports this tuning parameter, the libx265 (HEVC) encoder rejects it in our current FFmpeg build, causing an immediate fatal crash during initialization.

Steps to Reproduce :

  1. Upload a source video to trigger the worker pipeline.
  2. The worker successfully completes Phase_1_Audio and Phase_2_H264_SDR.
  3. The worker attempts to start Phase_3_H265_SDR.
  4. The pipeline throws a TranscodeError and the job fails.

Error Logs :

[libx265 @ 0x562091282180] Error setting preset/tune slow/film.
[vost#0:0/libx265 @ 0x5620912f4180] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
[fc#0 @ 0x562091273740] Task finished with error code: -22 (Invalid argument)

Proposed Fix :
Update the videoEncoderFlags function in src/infrastructure/ffmpeg/encoding/flags.ts to conditionally apply the -tune film parameter only when the codec is libx264.

Affected File : src/infrastructure/ffmpeg/encoding/flags.ts

Possible Code Change :

// Replace:
'-preset', variant.preset,
'-tune', 'film',

// With:
'-preset', variant.preset,
...(codec === 'libx264' ? ['-tune', 'film'] : []),

Acceptance Criteria :

  • Worker successfully completes all H.264, H.265 SDR, and H.265 HDR encoding phases without -22 crashes
  • libx264 variants correctly retain the film tuning parameter in their FFmpeg command string

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions