Vaigard
Vaigard

Reputation: 11

FFMPEG API: decode MPEG to YUV frames and change these frames

I need save all frames from MPEG4 or H.264 video to YUV-frames using C++ library. For example, in .yuv, .y4m or .y format. Then I need read these frames like a digital files and change some samples (Y-value). How can I do it without convert to RGB?

And how store values of AVFrame->data? Where store Y-, U- and V-values?

Thanks and sorry for my English=)

Upvotes: 0

Views: 1542

Answers (1)

szatmary
szatmary

Reputation: 31120

If you use libav* to decode, you will receive the frames in their native colorspace (usually YUV 420) But it is what ever was chosen at encode time. Assuming you are in YUV420 or convert to YUV420 y: AVFrame->data[0], u: AVFrame->data[1], v: AVFrame->data[2]

For Y, 1 byte per pixel AVFrame->data[0][(x*AVFrame->linesize[0]) + y] For U and V its 4 pixles per byte (quarter resolution of Y plane). So AVFrame->data[1][(x/2*AVFrame->linesize[1]) + y/2], AVFrame->data[2][(x/2*AVFrame->linesize[2]) + y/2]

Upvotes: 1

Related Questions