when I use ffmpeg to scale a H264 video. It seems that the video is decoded to the raw graph then scaled then encoded again. But if the speed is very critical,is there a faster way if I specify a “good" ratio like 2:1, as if I want to pick up one pixel in every four?
I know a bit how h264 works, 8*8/4*4 pixels are coded as a group,so it's not easy to pick up 1/4 pixels in its range. But is there a way to merge 4 group into one quickly?
When you use ffmpeg for scaling purpose, there is no way you can avoid re-encoding to any part of the video. For scale operation, ffmpeg works in pipeline fashion as below:
Decoder ----> Scaler -----> Encoder
Scaler does scale operation only after a completely decoded frame is available to it. Since every packet passes through this pipeline, encoder receives video frames in decompressed (YUV format) form only. So, every YUV frame gets re-encoded after scale operation. I guess it clarifies why there is no way to avoid re-encoding.
The scaling ratio do play a role in complexity. I guess scale ratio 2:1 is OK, scale ratio affects the number of taps (filter coefficients) used in scale algorithm. Also, the scaling algorithm that you may choose add another layer of complexity. Least complex scaling algorithm in ffmpeg is "fast_bilinear". But be aware of the video quality trade-off.
Of course, encoding speed is another factor to consider. It seems you know fairly about it. One thing, see if you can make use of HW decoder & encoder that may be available in your system. If HW codec is available, it greatly improves the speed of this entire pipeline. You can try with -hwaccel dxva2 option for ffmpeg