[FFmpeg-devel] [PATCH] lavc/rawenc: add internal class and option -rawvideo_align

Stefano Sabatini stefasab at gmail.com
Sat Jun 30 23:27:59 CEST 2012


The option is useful mostly for testing purposes.
---
 doc/encoders.texi   |   14 ++++++++++++++
 libavcodec/rawenc.c |   38 ++++++++++++++++++++++++++++++++------
 2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index a7a2761..c4c7ec3 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -591,4 +591,18 @@ ffmpeg -i foo.mpg -vcodec libx264 -x264opts keyint=123:min-keyint=20 -an out.mkv
 For more information about libx264 and the supported options see:
 @url{http://www.videolan.org/developers/x264.html}
 
+ at section rawvideo
+
+Raw video decoder.
+
+This decoder decodes rawvideo streams.
+
+ at subsection Options
+
+ at table @option
+ at item rawvideo_align @var{align}
+Specify the alignment to use to encode planar data, must be a positive
+integer. Default value is 1.
+ at end table
+
 @c man end VIDEO ENCODERS
diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c
index 44a3421..a04c742 100644
--- a/libavcodec/rawenc.c
+++ b/libavcodec/rawenc.c
@@ -27,12 +27,34 @@
 #include "avcodec.h"
 #include "raw.h"
 #include "internal.h"
-#include "libavutil/pixdesc.h"
+#include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+
+typedef struct RawVideoContext {
+    AVClass *av_class;
+    int align;
+    AVFrame coded_frame;
+} RawVideoContext;
+
+static const AVOption rawvideo_options[] = {
+{"rawvideo_align", "set assumend alignment", offsetof(RawVideoContext, align), AV_OPT_TYPE_INT, {.dbl = 1}, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_VIDEO_PARAM},
+{NULL}
+};
+
+static const AVClass rawvideo_class = {
+    .class_name = "rawvideo",
+    .item_name  = av_default_item_name,
+    .option     = rawvideo_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
 
 static av_cold int raw_init_encoder(AVCodecContext *avctx)
 {
-    avctx->coded_frame            = avctx->priv_data;
+    RawVideoContext *rawvideo = avctx->priv_data;
+
+    avctx->coded_frame = &rawvideo->coded_frame;
     avcodec_get_frame_defaults(avctx->coded_frame);
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
@@ -44,15 +66,18 @@ static av_cold int raw_init_encoder(AVCodecContext *avctx)
 static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
                       const AVFrame *frame, int *got_packet)
 {
-    int ret = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+    RawVideoContext *rawvideo = avctx->priv_data;
+    int ret = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height,
+                                       rawvideo->align);
 
     if (ret < 0)
         return ret;
 
     if ((ret = ff_alloc_packet2(avctx, pkt, ret)) < 0)
         return ret;
-    if ((ret = avpicture_layout((const AVPicture *)frame, avctx->pix_fmt, avctx->width,
-                                avctx->height, pkt->data, pkt->size)) < 0)
+    if ((ret = av_image_copy_to_buffer(pkt->data, pkt->size,
+                                       (const uint8_t * const*)frame->data, frame->linesize,
+                                       avctx->pix_fmt, avctx->width, avctx->height, rawvideo->align)) < 0)
         return ret;
 
     if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
@@ -70,8 +95,9 @@ AVCodec ff_rawvideo_encoder = {
     .name           = "rawvideo",
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = CODEC_ID_RAWVIDEO,
-    .priv_data_size = sizeof(AVFrame),
+    .priv_data_size = sizeof(RawVideoContext),
     .init           = raw_init_encoder,
     .encode2        = raw_encode,
     .long_name      = NULL_IF_CONFIG_SMALL("raw video"),
+    .priv_class     = &rawvideo_class,
 };
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list