[FFmpeg-devel] [PATCH] avcodec/mediacodecdec: propagate SAR to h/w frames

Aman Gupta ffmpeg at tmm1.net
Tue Mar 20 01:33:43 EET 2018


From: Aman Gupta <aman at tmm1.net>

Allows consumers who are converting hardware buffers
to OpenGL textures to render the frames at the intended
display resolution.
---
 libavcodec/mediacodecdec_common.c | 13 +++++++++++++
 libavcodec/mediacodecdec_common.h |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c
index 635ee73486..437bffcd7c 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -205,6 +205,7 @@ static int mediacodec_wrap_hw_buffer(AVCodecContext *avctx,
     frame->width = avctx->width;
     frame->height = avctx->height;
     frame->format = avctx->pix_fmt;
+    frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
 
     if (avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
         frame->pts = av_rescale_q(info->presentationTimeUs,
@@ -414,6 +415,18 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte
     width = s->crop_right + 1 - s->crop_left;
     height = s->crop_bottom + 1 - s->crop_top;
 
+    AMEDIAFORMAT_GET_INT32(s->display_width,  "display-width",  0);
+    AMEDIAFORMAT_GET_INT32(s->display_height, "display-height", 0);
+
+    if (s->display_width && s->display_height) {
+        AVRational sar = av_div_q(
+            (AVRational){ s->display_width, s->display_height },
+            (AVRational){ width, height });
+        ff_set_sar(avctx, sar);
+    } else {
+        ff_set_sar(avctx, (AVRational){0,1});
+    }
+
     av_log(avctx, AV_LOG_INFO,
         "Output crop parameters top=%d bottom=%d left=%d right=%d, "
         "resulting dimensions width=%d height=%d\n",
diff --git a/libavcodec/mediacodecdec_common.h b/libavcodec/mediacodecdec_common.h
index 4f3b4f9fa5..023d4c5fa7 100644
--- a/libavcodec/mediacodecdec_common.h
+++ b/libavcodec/mediacodecdec_common.h
@@ -61,6 +61,8 @@ typedef struct MediaCodecDecContext {
     int crop_bottom;
     int crop_left;
     int crop_right;
+    int display_width;
+    int display_height;
 
     uint64_t output_buffer_count;
 
-- 
2.14.2



More information about the ffmpeg-devel mailing list