summaryrefslogtreecommitdiff
path: root/libavformat/yuv4mpegenc.c
diff options
context:
space:
mode:
authorWang Cao <doubleecao@gmail.com>2018-06-28 16:32:01 +0800
committerMichael Niedermayer <michael@niedermayer.cc>2018-06-30 00:41:35 +0200
commit5a99e00023c057555697c73b2119f378b019c5fa (patch)
tree347378aad30892d24304552aa07894713de74096 /libavformat/yuv4mpegenc.c
parent27662ed681cbc74e9492cecf86ead8946679fd23 (diff)
downloadffmpeg-5a99e00023c057555697c73b2119f378b019c5fa.tar.gz
libavformat/yuv4mpeg: Add color range support for Y4M Add color_range support in Y4M.
Set pixel format and color_range for YUVJ pixel formats. Also set color_range based on AVFormatContext. Signed-off-by: Wang Cao <wangcao@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/yuv4mpegenc.c')
-rw-r--r--libavformat/yuv4mpegenc.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c
index 44f40bbad9..e84dbf9568 100644
--- a/libavformat/yuv4mpegenc.c
+++ b/libavformat/yuv4mpegenc.c
@@ -33,6 +33,7 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
int raten, rated, aspectn, aspectd, n;
char inter;
const char *colorspace = "";
+ const char *colorrange = "";
int field_order;
st = s->streams[0];
@@ -57,6 +58,17 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
FF_ENABLE_DEPRECATION_WARNINGS
#endif
+ switch(st->codecpar->color_range) {
+ case AVCOL_RANGE_MPEG:
+ colorrange = " XCOLORRANGE=LIMITED";
+ break;
+ case AVCOL_RANGE_JPEG:
+ colorrange = " XCOLORRANGE=FULL";
+ break;
+ default:
+ break;
+ }
+
switch (field_order) {
case AV_FIELD_TB:
case AV_FIELD_TT: inter = 't'; break;
@@ -84,6 +96,18 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
case AV_PIX_FMT_YUV411P:
colorspace = " C411 XYSCSS=411";
break;
+ case AV_PIX_FMT_YUVJ420P:
+ colorspace = " C420jpeg XYSCSS=420JPEG";
+ colorrange = " XCOLORRANGE=FULL";
+ break;
+ case AV_PIX_FMT_YUVJ422P:
+ colorspace = " C422 XYSCSS=422";
+ colorrange = " XCOLORRANGE=FULL";
+ break;
+ case AV_PIX_FMT_YUVJ444P:
+ colorspace = " C444 XYSCSS=444";
+ colorrange = " XCOLORRANGE=FULL";
+ break;
case AV_PIX_FMT_YUV420P:
switch (st->codecpar->chroma_location) {
case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; break;
@@ -145,13 +169,14 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
}
/* construct stream header, if this is the first frame */
- n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
+ n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s%s\n",
Y4M_MAGIC, width, height, raten, rated, inter,
- aspectn, aspectd, colorspace);
+ aspectn, aspectd, colorspace, colorrange);
return n;
}
+
static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
{
AVStream *st = s->streams[pkt->stream_index];
@@ -192,6 +217,10 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
case AV_PIX_FMT_YUV420P:
case AV_PIX_FMT_YUV422P:
case AV_PIX_FMT_YUV444P:
+ // TODO: remove YUVJ pixel formats when they are completely removed from the codebase.
+ case AV_PIX_FMT_YUVJ420P:
+ case AV_PIX_FMT_YUVJ422P:
+ case AV_PIX_FMT_YUVJ444P:
break;
case AV_PIX_FMT_GRAY9:
case AV_PIX_FMT_GRAY10:
@@ -271,6 +300,10 @@ static int yuv4_write_header(AVFormatContext *s)
case AV_PIX_FMT_YUV420P:
case AV_PIX_FMT_YUV422P:
case AV_PIX_FMT_YUV444P:
+ // TODO: remove YUVJ pixel formats when they are completely removed from the codebase.
+ case AV_PIX_FMT_YUVJ420P:
+ case AV_PIX_FMT_YUVJ422P:
+ case AV_PIX_FMT_YUVJ444P:
break;
case AV_PIX_FMT_GRAY9:
case AV_PIX_FMT_GRAY10: