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
28 28
29#include "avcodec.h"29#include "avcodec.h"
30#include "codec_internal.h"30#include "codec_internal.h"
31#include "get_bits.h"
32#include "libavutil/imgutils.h"31#include "libavutil/imgutils.h"
33#include "thread.h"32#include "thread.h"
34 33
@@ -65,7 +64,7 @@ static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame, · 30 unmodified lines
65{64{
66 uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20;65 uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20;
67 uint64_t packet_size = (uint64_t)avpkt->size * 8;66 uint64_t packet_size = (uint64_t)avpkt->size * 8;
68 GetBitContext bc;67 uint8_t *src;
69 uint16_t *y, *u, *v;68 uint16_t *y, *u, *v;
70 int ret, i, j;69 int ret, i, j;
71 70
@@ -79,20 +78,18 @@ static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame, · 7 unmodified lines
79 if (avctx->width % 2)78 if (avctx->width % 2)
80 return AVERROR_PATCHWELCOME;79 return AVERROR_PATCHWELCOME;
81 80
82 ret = init_get_bits(&bc, avpkt->data, avctx->width * avctx->height * 20);81 src = avpkt->data;
83 if (ret)
84 return ret;
85
86 for (i = 0; i < avctx->height; i++) {82 for (i = 0; i < avctx->height; i++) {
87 y = (uint16_t*)(frame->data[0] + i * frame->linesize[0]);83 y = (uint16_t*)(frame->data[0] + i * frame->linesize[0]);
88 u = (uint16_t*)(frame->data[1] + i * frame->linesize[1]);84 u = (uint16_t*)(frame->data[1] + i * frame->linesize[1]);
89 v = (uint16_t*)(frame->data[2] + i * frame->linesize[2]);85 v = (uint16_t*)(frame->data[2] + i * frame->linesize[2]);
90 86
91 for (j = 0; j < avctx->width; j += 2) {87 for (j = 0; j < avctx->width; j += 2) {
92 *u++ = get_bits(&bc, 10);88 *u++ = (src[0] << 2) | (src[1] >> 6);
93 *y++ = get_bits(&bc, 10);89 *v++ = ((src[2] << 6) | (src[3] >> 2)) & 0x3ff;
94 *v++ = get_bits(&bc, 10);90 *y++ = ((src[1] << 4) | (src[2] >> 4)) & 0x3ff;
95 *y++ = get_bits(&bc, 10);91 *y++ = ((src[3] << 8) | (src[4])) & 0x3ff;
92 src += 5;
96 }93 }
97 }94 }
98 95

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