[FFmpeg-devel] [PATCH 10/13] lavc/videotoolboxenc: add concatentation properties

Rick Kern kernrj at gmail.com
Sun Apr 10 05:50:15 CEST 2016


Add frames_before and frames_after as hints that there will be frames before
or after the frames produced in this session. This may help with
concatenation issues like bit rate spikes.

Signed-off-by: Rick Kern <kernrj at gmail.com>
---
 libavcodec/videotoolboxenc.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index c9a60b7..ff914f7 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -79,6 +79,8 @@ typedef struct VTEncContext {
     int64_t entropy;
     int64_t keyframes_only;
     int64_t realtime;
+    int64_t frames_before;
+    int64_t frames_after;
 
     bool flushing;
     bool has_b_frames;
@@ -739,6 +741,30 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
         }
     }
 
+    if (vtctx->frames_before == 1) {
+        status = VTSessionSetProperty(vtctx->session,
+                                      kVTCompressionPropertyKey_MoreFramesBeforeStart,
+                                      kCFBooleanTrue);
+
+        if (status == kVTPropertyNotSupportedErr) {
+            av_log(avctx, AV_LOG_WARNING, "frames_before property is not supported on this device. Ignoring.\n");
+        } else if (status) {
+            av_log(avctx, AV_LOG_ERROR, "Error setting frames_before property: %d\n", status);
+        }
+    }
+
+    if (vtctx->frames_after == 1) {
+        status = VTSessionSetProperty(vtctx->session,
+                                      kVTCompressionPropertyKey_MoreFramesAfterEnd,
+                                      kCFBooleanTrue);
+
+        if (status == kVTPropertyNotSupportedErr) {
+            av_log(avctx, AV_LOG_WARNING, "frames_after property is not supported on this device. Ignoring.\n");
+        } else if (status) {
+            av_log(avctx, AV_LOG_ERROR, "Error setting frames_after property: %d\n", status);
+        }
+    }
+
     if (!vtctx->has_b_frames) {
         status = VTSessionSetProperty(vtctx->session,
                                       kVTCompressionPropertyKey_AllowFrameReordering,
@@ -1546,6 +1572,10 @@ static const AVOption options[] = {
     { "keyframes_only", "Output only I-frames", OFFSET(keyframes_only), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
     { "realtime", "Hint that encoding should happen in real-time if not faster (e.g. capturing from camera).",
         OFFSET(realtime), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
+    { "frames_before", "Other frames will come before the frames in this session. This helps smooth concatenation issues.",
+        OFFSET(frames_before), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
+    { "frames_after", "Other frames will come after the frames in this session. This helps smooth concatenation issues.",
+        OFFSET(frames_after), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
 
     { NULL },
 };
-- 
2.7.4



More information about the ffmpeg-devel mailing list