---
 configure              |  7 ++++++
 libavcodec/Makefile    |  1 +
 libavcodec/allcodecs.c |  1 +
 libavcodec/libx264.c   | 62 +++++++++++++++++++++++++++++++++++++++++++-------
 4 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/configure b/configure
index 9aa5135..69db95c 100755
--- a/configure
+++ b/configure
@@ -212,6 +212,7 @@ External library support:
   --enable-libvpx          enable VP8 and VP9 de/encoding via libvpx [no]
   --enable-libwavpack      enable wavpack encoding via libwavpack [no]
   --enable-libwebp         enable WebP encoding via libwebp [no]
+  --enable-libx262         enable MPEG2VIDEO encoding via x264 [no]
   --enable-libx264         enable H.264 encoding via x264 [no]
   --enable-libx265         enable HEVC encoding via x265 [no]
   --enable-libxavs         enable AVS encoding via xavs [no]
@@ -1187,6 +1188,7 @@ EXTERNAL_LIBRARY_LIST="
     libvpx
     libwavpack
     libwebp
+    libx262
     libx264
     libx265
     libxavs
@@ -4348,6 +4350,11 @@ enabled libvpx            && require_pkg_config "vpx >= 
1.3.0" vpx/vpx_codec.h v
 }
 enabled libwavpack        && require libwavpack wavpack/wavpack.h 
WavpackOpenFileOutput  -lwavpack
 enabled libwebp           && require_pkg_config libwebp webp/encode.h 
WebPGetEncoderVersion
+enabled libx262           && require_pkg_config x264 "stdint.h x264.h" 
x264_encoder_encode &&
+                             { check_cpp_condition x264.h "X264_MPEG2" ||
+                               die "ERROR: libx262 mpeg2 support not enabled"; 
} &&
+                             { check_cpp_condition x264.h "X264_BUILD >= 118" 
||
+                               die "ERROR: libx264 version must be >= 0.118."; 
}
 enabled libx264           && require_pkg_config x264 "stdint.h x264.h" 
x264_encoder_encode &&
                              { check_cpp_condition x264.h "X264_BUILD >= 118" 
||
                                die "ERROR: libx264 version must be >= 0.118."; 
}
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 61024d0..2760386 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -671,6 +671,7 @@ OBJS-$(CONFIG_LIBVPX_VP9_DECODER)         += libvpxdec.o 
libvpx.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER)         += libvpxenc.o libvpx.o
 OBJS-$(CONFIG_LIBWAVPACK_ENCODER)         += libwavpackenc.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)            += libwebpenc.o
+OBJS-$(CONFIG_LIBX262_ENCODER)            += libx264.o
 OBJS-$(CONFIG_LIBX264_ENCODER)            += libx264.o
 OBJS-$(CONFIG_LIBX265_ENCODER)            += libx265.o
 OBJS-$(CONFIG_LIBXAVS_ENCODER)            += libxavs.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a3f1550..9fdbe8f 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -473,6 +473,7 @@ void avcodec_register_all(void)
     REGISTER_ENCDEC (LIBVPX_VP9,        libvpx_vp9);
     REGISTER_ENCODER(LIBWAVPACK,        libwavpack);
     REGISTER_ENCODER(LIBWEBP,           libwebp);
+    REGISTER_ENCODER(LIBX262,           libx262);
     REGISTER_ENCODER(LIBX264,           libx264);
     REGISTER_ENCODER(LIBX265,           libx265);
     REGISTER_ENCODER(LIBXAVS,           libxavs);
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 7c502fd..74df070 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -319,11 +319,18 @@ static int convert_pix_fmt(enum AVPixelFormat pix_fmt)
         return AVERROR(EINVAL);\
     }
 
-static av_cold int X264_init(AVCodecContext *avctx)
+static av_always_inline int common_init(AVCodecContext *avctx, int mpeg2)
 {
     X264Context *x4 = avctx->priv_data;
 
+#if CONFIG_LIBX262_ENCODER
+    if (mpeg2) {
+        x4->params.b_mpeg2 = 1;
+        x264_param_default_mpeg2(&x4->params);
+    } else
+#else
     x264_param_default(&x4->params);
+#endif
 
     x4->params.b_deblocking_filter         = avctx->flags & 
CODEC_FLAG_LOOP_FILTER;
 
@@ -663,13 +670,6 @@ static const AVOption options[] = {
     { NULL },
 };
 
-static const AVClass class = {
-    .class_name = "libx264",
-    .item_name  = av_default_item_name,
-    .option     = options,
-    .version    = LIBAVUTIL_VERSION_INT,
-};
-
 static const AVCodecDefault x264_defaults[] = {
     { "b",                "0" },
     { "bf",               "-1" },
@@ -698,6 +698,20 @@ static const AVCodecDefault x264_defaults[] = {
     { NULL },
 };
 
+
+#if CONFIG_LIBX264_ENCODER
+static av_cold int X264_init(AVCodecContext *avctx)
+{
+    return common_init(avctx, 0);
+}
+
+static const AVClass class = {
+    .class_name = "libx264",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 AVCodec ff_libx264_encoder = {
     .name             = "libx264",
     .long_name        = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC 
/ MPEG-4 part 10"),
@@ -714,3 +728,35 @@ AVCodec ff_libx264_encoder = {
     .caps_internal    = FF_CODEC_CAP_INIT_THREADSAFE |
                         FF_CODEC_CAP_INIT_CLEANUP,
 };
+#endif
+
+#if CONFIG_LIBX262_ENCODER
+static av_cold int X262_init(AVCodecContext *avctx)
+{
+    return common_init(avctx, 1);
+}
+
+static const AVClass class = {
+    .class_name = "libx262",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_libx262_encoder = {
+    .name             = "libx262",
+    .long_name        = NULL_IF_CONFIG_SMALL("libx262 MPEG2VIDEO"),
+    .type             = AVMEDIA_TYPE_VIDEO,
+    .id               = AV_CODEC_ID_MPEG2VIDEO,
+    .priv_data_size   = sizeof(X264Context),
+    .init             = X262_init,
+    .encode2          = X264_frame,
+    .close            = X264_close,
+    .capabilities     = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS,
+    .priv_class       = &class,
+    .defaults         = x264_defaults,
+    .init_static_data = X264_init_static,
+    .caps_internal    = FF_CODEC_CAP_INIT_THREADSAFE |
+                        FF_CODEC_CAP_INIT_CLEANUP,
+};
+#endif
-- 
1.9.0

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to