Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added yuvj420p format for to_ndarray #583

Merged
merged 1 commit into from Feb 21, 2020

Conversation

mastak
Copy link
Contributor

@mastak mastak commented Dec 19, 2019

yuvj420p has the same shape as yuv420p. The difference in color ranges:

@mastak
Copy link
Contributor Author

mastak commented Dec 20, 2019

Script with comparing pyav vs native ffmpeg run as subprocess:

requirements:

Install imageio-ffmpeg, for run ffmpeg as a subprocess and read raw data (https://github.com/imageio/imageio-ffmpeg/blob/master/imageio_ffmpeg/_io.py#L63)

pip install git+https://github.com/imageio/imageio-ffmpeg.git@53b1533382ec6502e2e02a3640898603a03fc00f
import av
import numpy as np
from imageio_ffmpeg import read_frames
from av.datasets import fate


def av_arrays(path_):
    return [frame.to_ndarray(format='yuvj420p') for frame in av.open(path_).decode(video=0)]


def ffmpeg_arrays(path_):
    gen = read_frames(path=path_, pix_fmt='yuvj420p', bits_per_pixel=12)
    meta = next(gen)
    data = list(gen)
    yuv = np.frombuffer(b''.join(data), dtype='uint8')
    w, h = meta['size']
    return yuv.reshape(-1, int(h * 1.5), w)

path = fate('h264/interlaced_crop.mp4')
av_frames = av_arrays(path)
ffmpeg_frames = ffmpeg_arrays(path)

for av_frame, ffmpeg_frame in zip(av_frames, ffmpeg_frames):
    assert np.array_equal(av_frame, ffmpeg_frame)

@jlaine
Copy link
Collaborator

jlaine commented Feb 21, 2020

This looks good to me, let's go!

@jlaine jlaine merged commit 028b742 into PyAV-Org:develop Feb 21, 2020
@mastak mastak deleted the feature/yuvj420p branch October 25, 2022 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants