Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Why does FFmpeg decode a raw video in the YUV420 planar 8 bits pixel format, when it's also encoding the video using the same YUV420p pixel format?

I've ran a couple benchmark tests encoding only raw YUV420p video using the MPEG2 encoder on a FreeScale PowerPC using the following settings:

ffmpeg -f rawvideo -pix_fmt yuv420p -s cif -r 25 -i YUV420p_cif.yuv -vcodec mpeg2video -pix_fmt yuv420p -r 25 -g 25 -s cif -b:v 1024k Output.mp4

The video sequence is 15 minutes long. I found out the entire proces uses:

  • 3.9% of time reading the file;
  • 3.7% of time decoding;
  • 91.2% of time encoding;
  • 0.7% of time muxing + writing the file;
  • 0.5% of time is initializing / closing ffmpeg

The total process was done in 382 seconds (58.9 fps), so decoding took 14.1 seconds in total. That seems a lot to me!

Since the encoding process is using the YUV420p pixel format, why does FFmpeg needs 3.7% of the time decoding the raw YUV420p to the same format?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

In order to encode the video, you will still have to get each frame's data in an internal format, from where it can be fed to the encoder.

AVFrame is used for representing frames internally, and it can take any pixel format you want – you just have to allocate it correctly.

And this is why decoding takes CPU time, even if your input and output pixel formats are the same: You need to allocate memory for each frame, read it (even if it's raw data), and then pass on this frame to the encoder. An example of how the encoding and decoding is handled can be seen here.

share|improve this answer
    
I thought YUV420p was the internal format. When I input a raw YUV422 video, it takes like 30 seconds, making like twice the decoding time as YUV420. So, I actually want to know in what form or type the internal data is described then, if it is not subsampled/planar. –  Nick van Tilborg Mar 19 '13 at 17:13
1  
Scratch that – each frame can take a different pixel format. What you're seeing is the overhead used for allocating the data and reading it from the file. –  slhck Mar 19 '13 at 18:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.