[FFmpeg-devel] [PATCH 1/2] avformat/microdvd: Use \n instead of \0 to end file header
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Thu Dec 19 23:03:00 EET 2019
Andreas Rheinhardt:
> Up until now, the microdvd demuxer uses av_strdup() to allocate the
> extradata from a string; its length is set to strlen() + 1, i.e.
> including the \0 at the end. Upon remuxing, the muxer would simply copy
> the extradata at the beginning, including the \0.
>
> This commit changes this by not adding the \0 to the size of the
> extradata; the muxer now delimits extradata by inserting a \n. This
> required to change the subtitles-microdvd-remux FATE-test.
>
> Furthermore, the extradata is now allocated with zeroed padding.
>
> The microdvd decoder is not affected by this, as it didn't use the size
> of the extradata at all, but treated it as a C-string.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
> libavformat/microdvddec.c | 9 +++++----
> libavformat/microdvdenc.c | 1 +
> tests/ref/fate/sub-microdvd-remux | Bin 416 -> 416 bytes
> 3 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c
> index ca9086afe9..08e6fca09c 100644
> --- a/libavformat/microdvddec.c
> +++ b/libavformat/microdvddec.c
> @@ -117,10 +117,11 @@ static int microdvd_read_header(AVFormatContext *s)
> continue;
> }
> if (!st->codecpar->extradata && sscanf(line, "{DEFAULT}{}%c", &c) == 1) {
> - st->codecpar->extradata = av_strdup(line + 11);
> - if (!st->codecpar->extradata)
> - return AVERROR(ENOMEM);
> - st->codecpar->extradata_size = strlen(st->codecpar->extradata) + 1;
> + int ret, size = strlen(line + 11);
> + ret = ff_alloc_extradata(st->codecpar, size);
> + if (ret < 0)
> + return ret;
> + memcpy(st->codecpar->extradata, line + 11, size);
> continue;
> }
> }
> diff --git a/libavformat/microdvdenc.c b/libavformat/microdvdenc.c
> index 04f475b645..6639651e02 100644
> --- a/libavformat/microdvdenc.c
> +++ b/libavformat/microdvdenc.c
> @@ -36,6 +36,7 @@ static int microdvd_write_header(struct AVFormatContext *s)
> if (par->extradata && par->extradata_size > 0) {
> avio_write(s->pb, "{DEFAULT}{}", 11);
> avio_write(s->pb, par->extradata, par->extradata_size);
> + avio_w8(s->pb, '\n');
> avio_flush(s->pb);
> }
>
> diff --git a/tests/ref/fate/sub-microdvd-remux b/tests/ref/fate/sub-microdvd-remux
> index a71da99031fdc4bff13ea7124c046e761a650dc8..92ff233f56b6fec33d4e9e0698ec43377ea5fab7 100644
> GIT binary patch
> delta 12
> TcmZ3$ynuOvE+f}Qy&^^c7%l^0
>
> delta 12
> TcmZ3$ynuOvE+fN6y&^^c7yJWP
>
Ping.
- Andreas
More information about the ffmpeg-devel
mailing list