[FFmpeg-cvslog] libavformat/mux: Add ff_choose_chroma_location()

Michael Niedermayer git at videolan.org
Fri May 22 15:46:49 CEST 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri May 22 13:42:24 2015 +0200| [a45cf639e6fb8c86aff91a00970060cd0be401c9] | committer: Michael Niedermayer

libavformat/mux: Add ff_choose_chroma_location()

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a45cf639e6fb8c86aff91a00970060cd0be401c9
---

 libavformat/internal.h |    5 +++++
 libavformat/mux.c      |   30 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index d665cbd..f90df90 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -411,6 +411,11 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags);
 AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precision);
 
 /**
+ * Chooses a timebase for muxing the specified stream.
+ */
+enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream *st);
+
+/**
  * Generate standard extradata for AVC-Intra based on width/height and field
  * order.
  */
diff --git a/libavformat/mux.c b/libavformat/mux.c
index a39c534..f99dbd9 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -115,6 +115,36 @@ AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precisio
     return q;
 }
 
+enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream *st)
+{
+    AVCodecContext *avctx = st->codec;
+    const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+
+    if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED)
+        return avctx->chroma_sample_location;
+
+    if (pix_desc) {
+        if (pix_desc->log2_chroma_h == 0) {
+            return AVCHROMA_LOC_TOPLEFT;
+        } else if (pix_desc->log2_chroma_w == 1 && pix_desc->log2_chroma_h == 1) {
+            if (avctx->field_order == AV_FIELD_UNKNOWN || avctx->field_order == AV_FIELD_PROGRESSIVE) {
+                switch (avctx->codec_id) {
+                case AV_CODEC_ID_MJPEG:
+                case AV_CODEC_ID_MPEG1VIDEO: return AVCHROMA_LOC_CENTER;
+                }
+            }
+            if (avctx->field_order == AV_FIELD_UNKNOWN || avctx->field_order != AV_FIELD_PROGRESSIVE) {
+                switch (avctx->codec_id) {
+                case AV_CODEC_ID_MPEG2VIDEO: return AVCHROMA_LOC_LEFT;
+                }
+            }
+        }
+    }
+
+    return AVCHROMA_LOC_UNSPECIFIED;
+
+}
+
 int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
                                    const char *format, const char *filename)
 {



More information about the ffmpeg-cvslog mailing list