I found using vp9 to encode videos with alpha channel is very slow, even if added -deadline realtime -speed 8

533 views
Skip to first unread message

ouhe...@mail.ustc.edu.cn

unread,
Aug 26, 2021, 12:57:27 PM8/26/21
to webm-d...@webmproject.org
I want to use vp9 encoder to encode video with alpha channel (argb -> webm, through ffmpeg) in real time (less than 30ms/frame), but I found that even if the -deadline realtime -speed 8 parameter is added, the speed is improved Still not obvious.

After that, I used 
# perf record -e cpu-clock -g 
to test the following three instructions:

1.ffmpeg -f rawvideo -pix_fmt argb -s 720x1280 -i input.rgba -pix_fmt yuva420p -threads 2 -deadline realtime -speed 8 output.webm

2.ffmpeg -f rawvideo -pix_fmt argb -s 720x1280 -i input.rgba -pix_fmt yuv420p -threads 2 -deadline realtime -speed 8 output.webm

3.ffmpeg -f rawvideo -pix_fmt argb -s 720x1280 -i input.rgba -pix_fmt yuv420p -threads 2 output.webm

I found that when I added the -deadline realtime -speed 8 attribute, the normal (ie yuv420p) would not call the vp9_diamond_search_sad_avx() and vp9_optimize_b() functions. But when I encode a video with an alpha channel (ie yuva420p), the above two functions will still be called.

I observed the source code of libvpx-vp9 and found that difference were generated when the vp9_encode_sb_row() function judged if cpi->sf.use_nonrd_pick_mode (line 5832 in vp9_encodeframe.c). cpi->sf.use_nonrd_pick_mode is set to 1 when speed>=5, so encode_nonrd_sb_row() is called in vp9_encode_sb_row(). Otherwise, encode_rd_sb_row() will be called, and finally vp9_optimize_b() and vp9_diamond_search_sad_avx() will be called.

So my guess is that the encoding of the alpha channel may not be processed for the -deadline and -speed parameters. Attached is the result I obtained through perf

Thanks for reading
yuv420p_realtime_8.svg
yuv420p.svg
yuva420p_realtime_8.svg

James Zern

unread,
Aug 27, 2021, 2:44:45 PM8/27/21
to WebM Discussion
Hi,

Yes you're correct. Currently the alpha encoder duplicates the yuv encoder's configuration and deadline, but doesn't set the same codec controls:

If you're able to build ffmpeg you can set the CPU_USED value to match in that block.
 

Thanks for reading

--
You received this message because you are subscribed to the Google Groups "WebM Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webm-discuss...@webmproject.org.
To view this discussion on the web visit https://groups.google.com/a/webmproject.org/d/msgid/webm-discuss/2e58f5cb.1c6c6.17b808a1799.Coremail.ouhengyu%40mail.ustc.edu.cn.

James Zern

unread,
Sep 2, 2021, 1:21:26 PM9/2/21
to WebM Discussion
On Fri, Aug 27, 2021 at 11:44 AM James Zern <jz...@google.com> wrote:
Hi,

On Thu, Aug 26, 2021 at 9:57 AM ouhengyu via WebM Discussion <webm-d...@webmproject.org> wrote:
I want to use vp9 encoder to encode video with alpha channel (argb -> webm, through ffmpeg) in real time (less than 30ms/frame), but I found that even if the -deadline realtime -speed 8 parameter is added, the speed is improved Still not obvious.

After that, I used 
# perf record -e cpu-clock -g 
to test the following three instructions:

1.ffmpeg -f rawvideo -pix_fmt argb -s 720x1280 -i input.rgba -pix_fmt yuva420p -threads 2 -deadline realtime -speed 8 output.webm

2.ffmpeg -f rawvideo -pix_fmt argb -s 720x1280 -i input.rgba -pix_fmt yuv420p -threads 2 -deadline realtime -speed 8 output.webm

3.ffmpeg -f rawvideo -pix_fmt argb -s 720x1280 -i input.rgba -pix_fmt yuv420p -threads 2 output.webm

I found that when I added the -deadline realtime -speed 8 attribute, the normal (ie yuv420p) would not call the vp9_diamond_search_sad_avx() and vp9_optimize_b() functions. But when I encode a video with an alpha channel (ie yuva420p), the above two functions will still be called.

I observed the source code of libvpx-vp9 and found that difference were generated when the vp9_encode_sb_row() function judged if cpi->sf.use_nonrd_pick_mode (line 5832 in vp9_encodeframe.c). cpi->sf.use_nonrd_pick_mode is set to 1 when speed>=5, so encode_nonrd_sb_row() is called in vp9_encode_sb_row(). Otherwise, encode_rd_sb_row() will be called, and finally vp9_optimize_b() and vp9_diamond_search_sad_avx() will be called.

So my guess is that the encoding of the alpha channel may not be processed for the -deadline and -speed parameters. Attached is the result I obtained through perf

Yes you're correct. Currently the alpha encoder duplicates the yuv encoder's configuration and deadline, but doesn't set the same codec controls:

If you're able to build ffmpeg you can set the CPU_USED value to match in that block.

Reply all
Reply to author
Forward
0 new messages