[FFmpeg-cvslog] avformat/mov: call mov_rewrite_dvd_sub_extradata() after parsing dimensions from tkhd
Michael Niedermayer
git at videolan.org
Mon Mar 17 18:45:56 CET 2014
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Mon Mar 17 18:22:32 2014 +0100| [e21235f9b9e264111279847617bb7bdaa734b11a] | committer: Michael Niedermayer
avformat/mov: call mov_rewrite_dvd_sub_extradata() after parsing dimensions from tkhd
This also moves mov_rewrite_dvd_sub_extradata() to mov.c
Fixes: NeroRecodeSample.mp4
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e21235f9b9e264111279847617bb7bdaa734b11a
---
libavformat/isom.c | 56 ----------------------------------------------------
libavformat/mov.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 56 deletions(-)
diff --git a/libavformat/isom.c b/libavformat/isom.c
index a38d397..aec6878 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -439,60 +439,8 @@ static const AVCodecTag mp4_audio_types[] = {
{ AV_CODEC_ID_NONE, AOT_NULL },
};
-static uint32_t yuv_to_rgba(uint32_t ycbcr)
-{
- uint8_t r, g, b;
- int y, cb, cr;
-
- y = (ycbcr >> 16) & 0xFF;
- cr = (ycbcr >> 8) & 0xFF;
- cb = ycbcr & 0xFF;
-
- b = av_clip_uint8(1.164 * (y - 16) + 2.018 * (cb - 128));
- g = av_clip_uint8(1.164 * (y - 16) - 0.813 * (cr - 128) - 0.391 * (cb - 128));
- r = av_clip_uint8(1.164 * (y - 16) + 1.596 * (cr - 128));
-
- return (r << 16) | (g << 8) | b;
-}
-
-static int mov_rewrite_dvd_sub_extradata(AVStream *st)
-{
- char buf[256] = {0};
- uint8_t *src = st->codec->extradata;
- int i;
-
- if (st->codec->extradata_size != 64)
- return 0;
-
- if (st->codec->width > 0 && st->codec->height > 0)
- snprintf(buf, sizeof(buf), "size: %dx%d\n",
- st->codec->width, st->codec->height);
- av_strlcat(buf, "palette: ", sizeof(buf));
-
- for (i = 0; i < 16; i++) {
- uint32_t yuv = AV_RB32(src + i * 4);
- uint32_t rgba = yuv_to_rgba(yuv);
-
- av_strlcatf(buf, sizeof(buf), "%06x%s", rgba, i != 15 ? ", " : "");
- }
-
- if (av_strlcat(buf, "\n", sizeof(buf)) >= sizeof(buf))
- return 0;
-
- av_freep(&st->codec->extradata);
- st->codec->extradata_size = 0;
- st->codec->extradata = av_mallocz(strlen(buf) + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!st->codec->extradata)
- return AVERROR(ENOMEM);
- st->codec->extradata_size = strlen(buf);
- memcpy(st->codec->extradata, buf, st->codec->extradata_size);
-
- return 0;
-}
-
int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
{
- int err;
int len, tag;
int ret;
int object_type_id = avio_r8(pb);
@@ -535,10 +483,6 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext
cfg.object_type)))
st->codec->codec_id = AV_CODEC_ID_AAC;
}
- if (st->codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
- if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
- return err;
- }
}
return 0;
}
diff --git a/libavformat/mov.c b/libavformat/mov.c
index e7849c8..469da94 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1489,6 +1489,57 @@ static void mov_parse_stsd_subtitle(MOVContext *c, AVIOContext *pb,
st->codec->height = sc->height;
}
+static uint32_t yuv_to_rgba(uint32_t ycbcr)
+{
+ uint8_t r, g, b;
+ int y, cb, cr;
+
+ y = (ycbcr >> 16) & 0xFF;
+ cr = (ycbcr >> 8) & 0xFF;
+ cb = ycbcr & 0xFF;
+
+ b = av_clip_uint8(1.164 * (y - 16) + 2.018 * (cb - 128));
+ g = av_clip_uint8(1.164 * (y - 16) - 0.813 * (cr - 128) - 0.391 * (cb - 128));
+ r = av_clip_uint8(1.164 * (y - 16) + 1.596 * (cr - 128));
+
+ return (r << 16) | (g << 8) | b;
+}
+
+static int mov_rewrite_dvd_sub_extradata(AVStream *st)
+{
+ char buf[256] = {0};
+ uint8_t *src = st->codec->extradata;
+ int i;
+
+ if (st->codec->extradata_size != 64)
+ return 0;
+
+ if (st->codec->width > 0 && st->codec->height > 0)
+ snprintf(buf, sizeof(buf), "size: %dx%d\n",
+ st->codec->width, st->codec->height);
+ av_strlcat(buf, "palette: ", sizeof(buf));
+
+ for (i = 0; i < 16; i++) {
+ uint32_t yuv = AV_RB32(src + i * 4);
+ uint32_t rgba = yuv_to_rgba(yuv);
+
+ av_strlcatf(buf, sizeof(buf), "%06x%s", rgba, i != 15 ? ", " : "");
+ }
+
+ if (av_strlcat(buf, "\n", sizeof(buf)) >= sizeof(buf))
+ return 0;
+
+ av_freep(&st->codec->extradata);
+ st->codec->extradata_size = 0;
+ st->codec->extradata = av_mallocz(strlen(buf) + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!st->codec->extradata)
+ return AVERROR(ENOMEM);
+ st->codec->extradata_size = strlen(buf);
+ memcpy(st->codec->extradata, buf, st->codec->extradata_size);
+
+ return 0;
+}
+
static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb,
AVStream *st, MOVStreamContext *sc,
int size)
@@ -3430,6 +3481,10 @@ static int mov_read_header(AVFormatContext *s)
st->codec->width = sc->width;
st->codec->height = sc->height;
}
+ if (st->codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
+ if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
+ return err;
+ }
}
}
More information about the ffmpeg-cvslog
mailing list