master-of-zen / Av1an

Cross-platform command-line AV1 / VP9 / HEVC / H264 encoding framework with per scene quality encoding
GNU General Public License v3.0
1.4k stars 147 forks source link

Scene detection performance regression #852

Closed Uranite closed 2 weeks ago

Uranite commented 2 weeks ago

Scene detection speed has a performance regression because of commit https://github.com/master-of-zen/Av1an/commit/5184c0504e7d7af9a2a564558d9bf0c9bfd0474d This happens with any video (that I've ever tested at least) This issue is especially worse on high bitrate video How to reproduce:

  1. Run a test encode on a video with av1an commit https://github.com/master-of-zen/Av1an/commit/5184c0504e7d7af9a2a564558d9bf0c9bfd0474d, the encoder or the encoder parameters doesn't matter because we're only comparing the scene detection speed. Here is an example command that I used, av1an -i input.mkv -o output.mkv -e svt-av1, you can cancel the encode afterward if the scene detection is done
  2. Run a test encode on a video with av1an prior to commit https://github.com/master-of-zen/Av1an/commit/5184c0504e7d7af9a2a564558d9bf0c9bfd0474d. In this case I used av1an commit https://github.com/master-of-zen/Av1an/commit/a506a924f2c98dca7512eb0ba8daf0e68c51b42a
  3. Compare the speed of the scene detection, and you can see that av1an commit https://github.com/master-of-zen/Av1an/commit/5184c0504e7d7af9a2a564558d9bf0c9bfd0474d is slower at scene detection
trixoniisama commented 2 weeks ago

Can you provide data?

Uranite commented 2 weeks ago

Can you provide data?

On windows 11 command used: av1an -i testpubg.mkv -o testpubg-av1.mkv -e svt-av1 In a short 8 second test clip comprised of 501 frames, 60 fps 1080p video with average bitrate of 141 Mb/s av1an commit https://github.com/master-of-zen/Av1an/commit/a506a924f2c98dca7512eb0ba8daf0e68c51b42a image 182 fps for the scene detection which took only 2 seconds

av1an commit https://github.com/master-of-zen/Av1an/commit/5184c0504e7d7af9a2a564558d9bf0c9bfd0474d image I got 28 fps for the scene detection which took 17 seconds

this is the test clip that i used https://pixeldrain.com/u/96ND4jQt if you're planning to test on windows you can grab the windows build for a506a9 here https://github.com/Uranite/Av1an/actions/runs/9447421308

redzic commented 2 weeks ago

If I were to guess, the issue is almost certainly that decoder multi threading is not enabled with the new PR. I've faced a very similar issue with my project. With the libav* libraries, thread_count on the codec context should be set to 0 BEFORE calling avcodec_open2().

shssoichiro commented 2 weeks ago

@redzic since you seem to know this better--the rust ffmpeg api requires setting a type of threading, either Frame or Slice. Is Slice the recommended, and safe to use for all decoding? Or is Frame better and/or safer?

shssoichiro commented 2 weeks ago

Never mind, I tested and the very clear winner seems to be Frame threading.

shssoichiro commented 2 weeks ago

Thanks @Uranite , please let us know if you are still seeing any issues after the latest patch