[FFmpeg-devel] [PATCH 12/13] lavc/videotoolboxenc: Support pixel aspect ratio

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


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

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 0a79ee0..72743b5 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -765,6 +765,60 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
         }
     }
 
+    if (avctx->sample_aspect_ratio.num != 0) {
+        CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,
+                                         kCFNumberIntType,
+                                         &avctx->sample_aspect_ratio.num);
+
+        CFNumberRef den = CFNumberCreate(kCFAllocatorDefault,
+                                         kCFNumberIntType,
+                                         &avctx->sample_aspect_ratio.den);
+
+        CFMutableDictionaryRef par = CFDictionaryCreateMutable(
+                                         kCFAllocatorDefault,
+                                         20,
+                                         &kCFCopyStringDictionaryKeyCallBacks,
+                                         &kCFTypeDictionaryValueCallBacks);
+
+        if (!par || !num || !den) {
+            if (par) CFRelease(par);
+            if (num) CFRelease(num);
+            if (den) CFRelease(den);
+
+            return AVERROR(ENOMEM);
+        }
+
+        CFDictionarySetValue(
+            par,
+            kCMFormatDescriptionKey_PixelAspectRatioHorizontalSpacing,
+            num);
+
+        CFDictionarySetValue(
+            par,
+            kCMFormatDescriptionKey_PixelAspectRatioVerticalSpacing,
+            den);
+
+        status = VTSessionSetProperty(vtctx->session,
+                                      kVTCompressionPropertyKey_PixelAspectRatio,
+                                      par);
+
+        CFRelease(par);
+        CFRelease(num);
+        CFRelease(den);
+
+        if (status) {
+            av_log(
+                   avctx,
+                   AV_LOG_ERROR,
+                   "Error setting pixel aspect ratio to %d:%d: %d.\n",
+                   avctx->sample_aspect_ratio.num,
+                   avctx->sample_aspect_ratio.den,
+                   status);
+
+            return AVERROR_EXTERNAL;
+        }
+    }
+
     if (!vtctx->has_b_frames) {
         status = VTSessionSetProperty(vtctx->session,
                                       kVTCompressionPropertyKey_AllowFrameReordering,
-- 
2.7.4



More information about the ffmpeg-devel mailing list