]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libopenh264enc.c
avformat/avio: Add Metacube support
[ffmpeg] / libavcodec / libopenh264enc.c
index 4c57fa1c89aa16fe2224b2abb53afc5ffd7be21f..54babc3e975d8bc2ebbbb065ac44040cbcd33a46 100644 (file)
@@ -48,7 +48,10 @@ typedef struct SVCContext {
     int max_nal_size;
     int skip_frames;
     int skipped;
-    int cabac;
+#if FF_API_OPENH264_CABAC
+    int cabac;                      // deprecated
+#endif
+    int coder;
 
     // rate control mode
     int rc_mode;
@@ -83,7 +86,15 @@ static const AVOption options[] = {
 #undef PROFILE
     { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
     { "allow_skip_frames", "allow skipping frames to hit the target bitrate", OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
-    { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
+#if FF_API_OPENH264_CABAC
+    { "cabac", "Enable cabac(deprecated, use coder)", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE|DEPRECATED },
+#endif
+    { "coder", "Coder type",  OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, "coder" },
+        { "default",          NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX, VE, "coder" },
+        { "cavlc",            NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 },  INT_MIN, INT_MAX, VE, "coder" },
+        { "cabac",            NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 },  INT_MIN, INT_MAX, VE, "coder" },
+        { "vlc",              NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 },  INT_MIN, INT_MAX, VE, "coder" },
+        { "ac",               NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 },  INT_MIN, INT_MAX, VE, "coder" },
 
     { "rc_mode", "Select rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = RC_QUALITY_MODE }, RC_OFF_MODE, RC_TIMESTAMP_MODE, VE, "rc_mode" },
         { "off",       "bit rate control off",                                                 0, AV_OPT_TYPE_CONST, { .i64 = RC_OFF_MODE },         0, 0, VE, "rc_mode" },
@@ -145,14 +156,16 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 
     (*s->encoder)->GetDefaultParams(s->encoder, &param);
 
-#if FF_API_CODER_TYPE
-FF_DISABLE_DEPRECATION_WARNINGS
-    if (!s->cabac)
-        s->cabac = avctx->coder_type == FF_CODER_TYPE_AC;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
-    param.fMaxFrameRate              = 1/av_q2d(avctx->time_base);
+    if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
+        param.fMaxFrameRate = av_q2d(avctx->framerate);
+    } else {
+        if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Could not set framerate for libopenh264enc: integer overflow\n");
+            return AVERROR(EINVAL);
+        }
+        param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1);
+    }
     param.iPicWidth                  = avctx->width;
     param.iPicHeight                 = avctx->height;
     param.iTargetBitrate             = avctx->bit_rate > 0 ? avctx->bit_rate : TARGET_BITRATE_DEFAULT;
@@ -197,12 +210,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
             break;
         }
 
-    if (s->profile == FF_PROFILE_UNKNOWN)
-        s->profile = !s->cabac ? FF_PROFILE_H264_CONSTRAINED_BASELINE :
+    if (s->profile == FF_PROFILE_UNKNOWN && s->coder >= 0)
+        s->profile = s->coder == 0 ? FF_PROFILE_H264_CONSTRAINED_BASELINE :
 #if OPENH264_VER_AT_LEAST(1, 8)
-                                 FF_PROFILE_H264_HIGH;
+                                     FF_PROFILE_H264_HIGH;
 #else
-                                 FF_PROFILE_H264_MAIN;
+                                     FF_PROFILE_H264_MAIN;
 #endif
 
     switch (s->profile) {
@@ -415,7 +428,7 @@ static const AVCodecDefault svc_enc_defaults[] = {
     { NULL },
 };
 
-AVCodec ff_libopenh264_encoder = {
+const AVCodec ff_libopenh264_encoder = {
     .name           = "libopenh264",
     .long_name      = NULL_IF_CONFIG_SMALL("OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -424,8 +437,9 @@ AVCodec ff_libopenh264_encoder = {
     .init           = svc_encode_init,
     .encode2        = svc_encode_frame,
     .close          = svc_encode_close,
-    .capabilities   = AV_CODEC_CAP_AUTO_THREADS,
-    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
+    .capabilities   = AV_CODEC_CAP_OTHER_THREADS,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP |
+                      FF_CODEC_CAP_AUTO_THREADS,
     .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
                                                     AV_PIX_FMT_NONE },
     .defaults       = svc_enc_defaults,