History

avcodec/bitpacked_dec: optimize bitpacked_decode_yuv422p10

Rework the code a bit to speed up the 10-bit bitpacked decoding routine. This is probably about as fast as I can get it without switching to assembly language. Demonstratable with: ./ffmpeg -f lavfi -i "smptehdbars=size=3840x2160" -c bitpacked -f image2 -frames:v 1 source.yuv ./ffmpeg -f bitpacked -pix_fmt yuv422p10le -s 3840x2160 -c:v bitpacked -i source.yuv -pix_fmt yuv422p10le out.yuv On my development system, it went from 80ms for a 2160p frame down to 20ms (i.e. a 4X speedup). Good enough for now, I hope... Comments from Marton: Originally on my system better performance could be achieved by simply switching to the cached bitstream reader, but for Devin it was slower than his direct byte operations. I changed the order of writing output from u/y/v/y to u/v/y/y, and that made the code faster than the cached bitstream reader on my system as well. TIMER measurement of the decode loop on Ryzen 5 3600 with command line: ./ffmpeg -stream_loop 256 -threads 1 -f bitpacked -pix_fmt yuv422p10le -s 3840x2160 -c:v bitpacked -i source.yuv -pix_fmt yuv422p10le -f null none -loglevel error Before: 823204127 decicycles in YUV, 256 runs, 0 skips After: 315070524 decicycles in YUV, 256 runs, 0 skips

Devin Heitmueller committed 3 years ago

Commit b2c82b21 parent 059ea1d1 file · +7 −10Browse files

Unified · Split

libavcodec/bitpacked_dec.c+7−10
@@ -28,7 +28,6 @@ · 27 unmodified lines
2828
2929 #include "avcodec.h"
3030 #include "codec_internal.h"
31−#include "get_bits.h"
3231 #include "libavutil/imgutils.h"
3332 #include "thread.h"
3433
@@ -65,7 +64,7 @@ static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame, · 30 unmodified lines
6564 {
6665 uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20;
6766 uint64_t packet_size = (uint64_t)avpkt->size * 8;
68− GetBitContext bc;
67+ uint8_t *src;
6968 uint16_t *y, *u, *v;
7069 int ret, i, j;
7170
@@ -79,20 +78,18 @@ static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame, · 7 unmodified lines
7978 if (avctx->width % 2)
8079 return AVERROR_PATCHWELCOME;
8180
82− ret = init_get_bits(&bc, avpkt->data, avctx->width * avctx->height * 20);
83− if (ret)
84− return ret;
85−
81+ src = avpkt->data;
8682 for (i = 0; i < avctx->height; i++) {
8783 y = (uint16_t*)(frame->data[0] + i * frame->linesize[0]);
8884 u = (uint16_t*)(frame->data[1] + i * frame->linesize[1]);
8985 v = (uint16_t*)(frame->data[2] + i * frame->linesize[2]);
9086
9187 for (j = 0; j < avctx->width; j += 2) {
92− *u++ = get_bits(&bc, 10);
93− *y++ = get_bits(&bc, 10);
94− *v++ = get_bits(&bc, 10);
95− *y++ = get_bits(&bc, 10);
88+ *u++ = (src[0] << 2) | (src[1] >> 6);
89+ *v++ = ((src[2] << 6) | (src[3] >> 2)) & 0x3ff;
90+ *y++ = ((src[1] << 4) | (src[2] >> 4)) & 0x3ff;
91+ *y++ = ((src[3] << 8) | (src[4])) & 0x3ff;
92+ src += 5;
9693 }
9794 }
9895

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t