Skip to content

Enable color parameters in NVENC test on FFmpeg 4 and 6 #1140

@Dan-Flores

Description

@Dan-Flores

Investigate why FFmpeg 4 and 6 fail with non-default color space and range.
The test_nvenc_against_ffmpeg_cli test is currently skipped on FFmpeg 4 and FFmpeg 6 when colorspace and color_range are set to values besides the default BT.601 and tv .

The code below demonstrates that the color parameters are set on the codec context, and the encoded video has the correct metadata. The error may be caused by other steps in the test.

Details
import subprocess
import torch
import json
from torchcodec.encoders import VideoEncoder

# Create test frames and encode with specific color parameters
frames = torch.randint(0, 256, (5, 3, 256, 256), dtype=torch.uint8).to("cuda")
encoder = VideoEncoder(frames=frames, frame_rate=30)

encoder.to_file(
    dest="/tmp/test_video.mp4",
    codec="h264_nvenc",
    extra_options={
        "colorspace": "bt709",
        "color_range": "pc",
    }
)

result = subprocess.run(
        [
          "ffprobe",
          "-v",
          "error",
          "-select_streams",
          "v:0",
          "-show_entries",
          "stream=color_space,color_range,pix_fmt",
          "-of",
          "json",
          "/tmp/test_video.mp4"
        ],
        capture_output = True,
        text = True,
        check = True)

metadata = json.loads(result.stdout)["streams"][0]
print(json.dumps(metadata, indent=2))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions