ultravideo/kvazaar

Huge performance drop in last 7 months

jozefchutka opened this issue · 1 comments

I have recently updated kvazaar dependency from aab6aa9 to a909ddd and experiencing 4-5x slower encoding performance.

I am using wasm build of ffmpeg with kvazaar as an encoder.

Build steps:

LIB_PATH=modules/kvazaar
CONF_FLAGS=(
  --prefix=$BUILD_DIR
  --host=i686-gnu
  --enable-static
  --disable-shared
  --with-pic
)
(cd $LIB_PATH && \
  emconfigure ./autogen.sh && \
  emconfigure ./configure "${CONF_FLAGS[@]}")
emmake make -C $LIB_PATH clean
emmake make -C $LIB_PATH -j
emmake make -C $LIB_PATH install

Performance comparision.

ffmpeg -i ... -acodec libmp3lame -vcodec libkvazaar -f matroska out.mkv

it takes around 45 seconds to compile

00:21.909Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input/bbb_h264_1280x720_30fps_aac_stereo_30s_4MB.mp4':
00:21.909  Metadata:
00:21.911    major_brand     : isom
00:21.911    minor_version   : 512
00:21.912    compatible_brands: isomiso2avc1mp41
00:21.912    title           : Big Buck Bunny, Sunflower version
00:21.913    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
00:21.914    composer        : Sacha Goedegebure
00:21.917    encoder         : Lavf59.9.102
00:21.917    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
00:21.918    genre           : Animation
00:21.918  Duration: 00:00:30.00, start: 0.000000, bitrate: 1305 kb/s
00:21.920  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 1166 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
00:21.921    Metadata:
00:21.921      handler_name    : GPAC ISO Video Handler
00:21.922      vendor_id       : [0][0][0][0]
00:21.923  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
00:21.924    Metadata:
00:21.924      handler_name    : GPAC ISO Audio Handler
00:21.925      vendor_id       : [0][0][0][0]
00:21.944Stream mapping:
00:21.945  Stream #0:0 -> #0:0 (h264 (native) -> hevc (libkvazaar))
00:21.946  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
00:23.090Available: no SIMD optimizations
00:23.091In use: no SIMD optimizations
00:23.093--owf=auto value set to 2.
00:23.093--threads=auto value set to 4.
00:23.167Output #0, matroska, to 'out.mkv':
00:23.167  Metadata:
00:23.169    major_brand     : isom
00:23.170    minor_version   : 512
00:23.170    compatible_brands: isomiso2avc1mp41
00:23.172    title           : Big Buck Bunny, Sunflower version
00:23.172    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
00:23.173    composer        : Sacha Goedegebure
00:23.174    genre           : Animation
00:23.176    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
00:23.176    encoder         : Lavf60.13.100
00:23.178  Stream #0:0(und): Video: hevc, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 1k tbn (default)
00:23.182    Metadata:
00:23.183      handler_name    : GPAC ISO Video Handler
00:23.184      vendor_id       : [0][0][0][0]
00:23.184      encoder         : Lavc60.26.100 libkvazaar
00:23.185  Stream #0:1(und): Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp (default)
00:23.188    Metadata:
00:23.194      handler_name    : GPAC ISO Audio Handler
00:23.199      vendor_id       : [0][0][0][0]
00:23.201      encoder         : Lavc60.26.100 libmp3lame
00:23.260frame=    0 fps=0.0 q=0.0 size=       1kB time=00:00:00.16 bitrate=  62.2kbits/s speed=0.219x    
00:23.262frame=    0 fps=0.0 q=0.0 size=       1kB time=00:00:00.19 bitrate=  54.5kbits/s speed=0.147x    
00:23.945frame=    1 fps=0.5 q=21.0 size=       1kB time=00:00:00.26 bitrate=  39.7kbits/s speed=0.133x    
00:24.631frame=    4 fps=1.5 q=25.0 size=       1kB time=00:00:00.33 bitrate=  31.2kbits/s speed=0.126x    
00:25.426frame=    7 fps=2.0 q=24.0 size=       1kB time=00:00:00.43 bitrate=  24.3kbits/s speed=0.125x    
...
01:05.426frame=  144 fps=3.3 q=25.0 size=     768kB time=00:00:04.87 bitrate=1291.1kbits/s speed=0.112x    
01:06.486frame=  147 fps=3.3 q=24.0 size=     768kB time=00:00:04.87 bitrate=1291.1kbits/s speed=0.109x    
01:06.937[out#0/matroska @ 0x2adaa40] video:1098kB audio:79kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.341814%
01:06.942frame=  150 fps=3.3 q=25.0 Lsize=    1181kB time=00:00:04.99 bitrate=1936.9kbits/s speed=0.111x    
01:06.951readFile(out.mkv) -> Blob (1.2M)

while it used to be 10 seconds:

00:14.745Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input/bbb_h264_1280x720_30fps_aac_stereo_30s_4MB.mp4':
00:14.745  Metadata:
00:14.747    major_brand     : isom
00:14.749    minor_version   : 512
00:14.749    compatible_brands: isomiso2avc1mp41
00:14.749    title           : Big Buck Bunny, Sunflower version
00:14.750    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
00:14.756    composer        : Sacha Goedegebure
00:14.761    encoder         : Lavf59.9.102
00:14.769    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
00:14.769    genre           : Animation
00:14.770  Duration: 00:00:30.00, start: 0.000000, bitrate: 1305 kb/s
00:14.778  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 1166 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
00:14.779    Metadata:
00:14.780      handler_name    : GPAC ISO Video Handler
00:14.785      vendor_id       : [0][0][0][0]
00:14.785  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
00:14.789    Metadata:
00:14.792      handler_name    : GPAC ISO Audio Handler
00:14.795      vendor_id       : [0][0][0][0]
00:14.835Stream mapping:
00:14.836  Stream #0:0 -> #0:0 (h264 (native) -> hevc (libkvazaar))
00:14.838  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
00:15.777Available: no SIMD optimizations
00:15.782In use: no SIMD optimizations
00:15.782--owf=auto value set to 2.
00:15.783--threads=auto value set to 4.
00:15.853Output #0, matroska, to 'out.mkv':
00:15.858  Metadata:
00:15.858    major_brand     : isom
00:15.859    minor_version   : 512
00:15.859    compatible_brands: isomiso2avc1mp41
00:15.860    title           : Big Buck Bunny, Sunflower version
00:15.860    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
00:15.860    composer        : Sacha Goedegebure
00:15.861    genre           : Animation
00:15.861    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
00:15.861    encoder         : Lavf60.13.100
00:15.865  Stream #0:0(und): Video: hevc, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 1k tbn (default)
00:15.865    Metadata:
00:15.865      handler_name    : GPAC ISO Video Handler
00:15.866      vendor_id       : [0][0][0][0]
00:15.866      encoder         : Lavc60.26.100 libkvazaar
00:15.867  Stream #0:1(und): Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp (default)
00:15.867    Metadata:
00:15.868      handler_name    : GPAC ISO Audio Handler
00:15.868      vendor_id       : [0][0][0][0]
00:15.869      encoder         : Lavc60.26.100 libmp3lame
00:15.978frame=    0 fps=0.0 q=0.0 size=       1kB time=00:00:00.16 bitrate=  62.2kbits/s speed=0.268x    
00:15.983frame=    0 fps=0.0 q=0.0 size=       1kB time=00:00:00.19 bitrate=  54.5kbits/s speed=0.169x    
00:16.495frame=    9 fps=5.4 q=23.0 size=       1kB time=00:00:00.50 bitrate=  20.8kbits/s speed=0.305x    
...
00:23.288frame=  135 fps= 16 q=24.0 size=     768kB time=00:00:04.68 bitrate=1344.0kbits/s speed=0.554x    
00:23.817frame=  144 fps= 16 q=25.0 size=     768kB time=00:00:04.87 bitrate=1291.1kbits/s speed=0.543x    
00:24.090[out#0/matroska @ 0x2aeccc0] video:1098kB audio:79kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.341814%
00:24.094frame=  150 fps= 16 q=25.0 Lsize=    1181kB time=00:00:04.99 bitrate=1936.9kbits/s speed=0.54x    

The same drop in performance can be observed when using custom params like -bf 0 -kvazaar-params preset=ultrafast - 20 sec. vs 4 sec.

The version bisect aab6aa9...ultravideo:kvazaar:a909dd doesn't show anything obvious but I might be missing something.

What is the recommended way forward? Are there any compile time flags introduced to take into consideration, or runtime parameters? Is this a bug or the new version has the algo complexity increased so its no match to an older version?

The issue was actually on my side. Probably related to the build optimization arguments