cutcutcodec.core.analysis.video.quality.vmaf_official.to_yuvfile

cutcutcodec.core.analysis.video.quality.vmaf_official.to_yuvfile(frames: Tensor | Iterable[Tensor]) Path[source]

Write the frame into a standard full range .yuv file in yuv444p16le pixel format.

Parameters

frameslist[torch.Tensor]

A (or several) video frame, assumed to be in yuv (YpPbPr) format, with \((y', p_b, p_r) \in [0, 1] \times \left[-\frac{1}{2}, \frac{1}{2}\right]^2\).

Returns

filenamepathlib.Path

The filename to the yuv file.

Examples

>>> import pathlib
>>> import subprocess
>>> import torch
>>> from cutcutcodec.core.analysis.video.quality.vmaf import to_yuvfile
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
>>> frame = torch.rand((720, 1080, 3))
>>> frame[:, :, 1:] -= 0.5
>>> yuvfile = to_yuvfile(frame)
>>> _ = subprocess.run(
...     [
...         "ffmpeg", "-y", "-f", "rawvideo",
...         "-s", "1080x720", "-pix_fmt", "yuv444p16le", "-color_range", "pc",
...         "-i", str(yuvfile),
...         "-c:v", "libaom-av1", "-crf", "0",
...         "/tmp/tmp.avif",
...     ],
...     check=True, capture_output=True
... )
>>> yuvfile.unlink()
>>> with ContainerInputFFMPEG("/tmp/tmp.avif") as container:
...     frame_bis = container.out_streams[0].snapshot(0, (720, 1080))
...
>>> pathlib.Path("/tmp/tmp.avif").unlink()
>>> assert torch.allclose(frame, frame_bis, atol=1e-3)
>>>