2

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?

李天宇
  • 21
  • 1
  • 3
  • 1
    There are quite a few preset available in ffmpeg which you can use to increase the encoding speed. Current presets in descending order of speed are: ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. Pl. refer to the below link https://trac.ffmpeg.org/wiki/Encode/H.264 for how to use the above present – shri Oct 26 '15 at 06:13
  • sorry if I didn't express well. I know ffmpeg's present and I know fast is really fast. But I wonder if there is a way to totally skip encoding(by some how compress or delete old 264 file) to get much more faster. – 李天宇 Oct 26 '15 at 06:56
  • 3
    You will have to re-encode – Roman R. Oct 26 '15 at 06:58
  • there might be different scaling options that are "faster" or "slower" but for downsampling, that might not matter as much – rogerdpack Oct 27 '15 at 00:17

1 Answers1

2

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

ARK
  • 649
  • 3
  • 14
  • HW encoders are not guaranteed to "greatly improve" the "speed of the pipeline" in general. Did you even compare x264 on CPU VS dxva2? – Harry Feb 27 '21 at 09:01