[FFmpeg-devel] [PATCH 1/4] avcodec/bitpacked_enc: add support for uyvy422 encoding

James Almer jamrial at gmail.com
Sat May 6 20:37:56 EEST 2023


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/bitpacked_enc.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/libavcodec/bitpacked_enc.c b/libavcodec/bitpacked_enc.c
index 3c4e11293d..cbca38006b 100644
--- a/libavcodec/bitpacked_enc.c
+++ b/libavcodec/bitpacked_enc.c
@@ -25,12 +25,36 @@
 #include "encode.h"
 #include "internal.h"
 #include "put_bits.h"
+#include "libavutil/imgutils.h"
 #include "libavutil/pixdesc.h"
 
 struct BitpackedContext {
     int (*encode)(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame);
 };
 
+static int encode_uyvy422(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame)
+{
+    int ret = av_image_get_buffer_size(frame->format,
+                                       frame->width, frame->height, 1);
+
+    if (ret < 0)
+        return ret;
+
+    ret = ff_get_encode_buffer(avctx, pkt, ret, 0);
+    if (ret < 0)
+        return ret;
+
+    ret = av_image_copy_to_buffer(pkt->data, pkt->size,
+                                  (const uint8_t **)frame->data, frame->linesize,
+                                  frame->format,
+                                  frame->width, frame->height, 1);
+
+    if (ret < 0)
+        return ret;
+
+    return 0;
+}
+
 static int encode_yuv422p10(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame)
 {
     const int buf_size = avctx->height * avctx->width * avctx->bits_per_coded_sample / 8;
@@ -85,7 +109,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     if (avctx->pix_fmt == AV_PIX_FMT_YUV422P10)
         s->encode = encode_yuv422p10;
     else
-        return AVERROR(EINVAL);
+        s->encode = encode_uyvy422;
 
     return 0;
 }
@@ -115,5 +139,6 @@ const FFCodec ff_bitpacked_encoder = {
     .init           = encode_init,
     FF_CODEC_ENCODE_CB(encode_frame),
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV422P10,
+                                                    AV_PIX_FMT_UYVY422,
                                                     AV_PIX_FMT_NONE },
 };
-- 
2.40.1



More information about the ffmpeg-devel mailing list