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