Re: [FFmpeg-devel] [PATCH 81/87] avcodec: Move all AVCodecParser.split functions to remove_extradata_bsf
Thanks for the pointer. Much appreciated. On Thu, 2022-05-12 at 17:43 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > Hi all, > > > > I know this happened quite some time ago, but we just noticed the > > change. > > > > This effectively disables the public API AVCodecParser.split for > > these > > codecs. HandBrake uses this API to split out extradata for a few > > codecs. Any chance we can bring these back? Otherwise, we will > > have to > > replicate this code in HandBrake 😕️ > > > > I know that AVCodecParser was lacking the typical public-private > demarkation, but you are actually not supposed to call these function > pointers directly. In fact, it is not publically documented at all > what > AVCodecParser.split does. > Anyway, use the extract_extradata BSF. It is the intended replacement > for this feature. It is also what avformat_find_stream_info() uses to > extract extradata in case the container doesn't provide any. > > > On Mon, 2021-04-19 at 11:10 -0300, James Almer wrote: > > > From: Andreas Rheinhardt > > > > > > The remove_extradata bsf is the only user of these functions. > > > > > > Signed-off-by: Andreas Rheinhardt > > > --- > > > libavcodec/Makefile | 4 +- > > > libavcodec/av1_parser.c | 25 +--- > > > libavcodec/avs2_parser.c | 1 - > > > libavcodec/avs3_parser.c | 1 - > > > libavcodec/cavs_parser.c | 1 - > > > libavcodec/h264_parser.c | 38 -- > > > libavcodec/hevc_parser.c | 34 - > > > libavcodec/mpeg4video_parser.c | 1 - > > > libavcodec/mpegvideo_parser.c | 18 --- > > > libavcodec/parser.c | 14 --- > > > libavcodec/remove_extradata_bsf.c | 201 > > > +--- > > > -- > > > libavcodec/vc1_parser.c | 19 --- > > > 12 files changed, 171 insertions(+), 186 deletions(-) > > > > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > > > index a640c548e5..c19a3cb60d 100644 > > > --- a/libavcodec/Makefile > > > +++ b/libavcodec/Makefile > > > @@ -1075,7 +1075,7 @@ OBJS-$(CONFIG_AAC_PARSER) += > > > aac_parser.o aac_ac3_parser.o \ > > > mpeg4audio.o > > > OBJS-$(CONFIG_AC3_PARSER) += ac3tab.o > > > aac_ac3_parser.o > > > OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o adx.o > > > -OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o > > > av1_parse.o > > > +OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o > > > OBJS-$(CONFIG_AVS2_PARSER) += avs2_parser.o > > > OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o > > > OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o > > > @@ -1159,7 +1159,7 @@ OBJS-$(CONFIG_NULL_BSF) > > > += > > > null_bsf.o > > > OBJS-$(CONFIG_OPUS_METADATA_BSF) += opus_metadata_bsf.o > > > OBJS-$(CONFIG_PCM_RECHUNK_BSF) += pcm_rechunk_bsf.o > > > OBJS-$(CONFIG_PRORES_METADATA_BSF) += > > > prores_metadata_bsf.o > > > -OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += > > > remove_extradata_bsf.o > > > +OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += > > > remove_extradata_bsf.o > > > av1_parse.o > > > OBJS-$(CONFIG_SETTS_BSF) += setts_bsf.o > > > OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += movsub_bsf.o > > > OBJS-$(CONFIG_TRACE_HEADERS_BSF) += trace_headers_bsf.o > > > diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c > > > index 578f5293c8..b6c8004ee3 100644 > > > --- a/libavcodec/av1_parser.c > > > +++ b/libavcodec/av1_parser.c > > > @@ -20,7 +20,7 @@ > > > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > > > 02110-1301 USA > > > */ > > > > > > -#include "av1_parse.h" > > > +#include "libavutil/avassert.h" > > > #include "cbs.h" > > > #include "cbs_av1.h" > > > #include "internal.h" > > > @@ -205,33 +205,10 @@ static void > > > av1_parser_close(AVCodecParserContext *ctx) > > > ff_cbs_close(&s->cbc); > > > } > > > > > > -static int av1_parser_split(AVCodecContext *avctx, > > > - const uint8_t *buf, int buf_size)
Re: [FFmpeg-devel] [PATCH 81/87] avcodec: Move all AVCodecParser.split functions to remove_extradata_bsf
Hi all, I know this happened quite some time ago, but we just noticed the change. This effectively disables the public API AVCodecParser.split for these codecs. HandBrake uses this API to split out extradata for a few codecs. Any chance we can bring these back? Otherwise, we will have to replicate this code in HandBrake 😕️ On Mon, 2021-04-19 at 11:10 -0300, James Almer wrote: > From: Andreas Rheinhardt > > The remove_extradata bsf is the only user of these functions. > > Signed-off-by: Andreas Rheinhardt > --- > libavcodec/Makefile | 4 +- > libavcodec/av1_parser.c | 25 +--- > libavcodec/avs2_parser.c | 1 - > libavcodec/avs3_parser.c | 1 - > libavcodec/cavs_parser.c | 1 - > libavcodec/h264_parser.c | 38 -- > libavcodec/hevc_parser.c | 34 - > libavcodec/mpeg4video_parser.c | 1 - > libavcodec/mpegvideo_parser.c | 18 --- > libavcodec/parser.c | 14 --- > libavcodec/remove_extradata_bsf.c | 201 +--- > -- > libavcodec/vc1_parser.c | 19 --- > 12 files changed, 171 insertions(+), 186 deletions(-) > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > index a640c548e5..c19a3cb60d 100644 > --- a/libavcodec/Makefile > +++ b/libavcodec/Makefile > @@ -1075,7 +1075,7 @@ OBJS-$(CONFIG_AAC_PARSER) += > aac_parser.o aac_ac3_parser.o \ > mpeg4audio.o > OBJS-$(CONFIG_AC3_PARSER) += ac3tab.o aac_ac3_parser.o > OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o adx.o > -OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o > +OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o > OBJS-$(CONFIG_AVS2_PARSER) += avs2_parser.o > OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o > OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o > @@ -1159,7 +1159,7 @@ OBJS-$(CONFIG_NULL_BSF) += > null_bsf.o > OBJS-$(CONFIG_OPUS_METADATA_BSF) += opus_metadata_bsf.o > OBJS-$(CONFIG_PCM_RECHUNK_BSF) += pcm_rechunk_bsf.o > OBJS-$(CONFIG_PRORES_METADATA_BSF) += prores_metadata_bsf.o > -OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o > +OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o > av1_parse.o > OBJS-$(CONFIG_SETTS_BSF) += setts_bsf.o > OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += movsub_bsf.o > OBJS-$(CONFIG_TRACE_HEADERS_BSF) += trace_headers_bsf.o > diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c > index 578f5293c8..b6c8004ee3 100644 > --- a/libavcodec/av1_parser.c > +++ b/libavcodec/av1_parser.c > @@ -20,7 +20,7 @@ > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > 02110-1301 USA > */ > > -#include "av1_parse.h" > +#include "libavutil/avassert.h" > #include "cbs.h" > #include "cbs_av1.h" > #include "internal.h" > @@ -205,33 +205,10 @@ static void > av1_parser_close(AVCodecParserContext *ctx) > ff_cbs_close(&s->cbc); > } > > -static int av1_parser_split(AVCodecContext *avctx, > - const uint8_t *buf, int buf_size) > -{ > - AV1OBU obu; > - const uint8_t *ptr = buf, *end = buf + buf_size; > - > - while (ptr < end) { > - int len = ff_av1_extract_obu(&obu, ptr, buf_size, avctx); > - if (len < 0) > - break; > - > - if (obu.type == AV1_OBU_FRAME_HEADER || > - obu.type == AV1_OBU_FRAME) { > - return ptr - buf; > - } > - ptr += len; > - buf_size -= len; > - } > - > - return 0; > -} > - > const AVCodecParser ff_av1_parser = { > .codec_ids = { AV_CODEC_ID_AV1 }, > .priv_data_size = sizeof(AV1ParseContext), > .parser_init = av1_parser_init, > .parser_close = av1_parser_close, > .parser_parse = av1_parser_parse, > - .split = av1_parser_split, > }; > diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c > index 059faf77c5..b7d5d7774e 100644 > --- a/libavcodec/avs2_parser.c > +++ b/libavcodec/avs2_parser.c > @@ -91,5 +91,4 @@ const AVCodecParser ff_avs2_parser = { > .priv_data_size = sizeof(ParseContext), > .parser_parse = avs2_parse, > .parser_close = ff_parse_close, > - .split = ff_mpeg4video_split, > }; > diff --git a/libavcodec/avs3_parser.c b/libavcodec/avs3_parser.c > index b0e720a844..1a05ea042e 100644 > --- a/libavcodec/avs3_parser.c > +++ b/libavcodec/avs3_parser.c > @@ -175,5 +175,4 @@ const AVCodecParser ff_avs3_parser = { > .priv_data_size = sizeof(ParseContext), > .parser_parse = avs3_parse, > .parser_close = ff_parse_close, > - .split = ff_mpeg4video_split, > }; > diff --git a/libavcodec/cavs_parser.c b/libavcodec/cavs_parser.c > index 20adca1dbc..03f392c2e5 100644 > --- a/libavcodec/cavs_parser.c > +++ b/libavcodec/cavs_parser.c > @@ -102,5 +102,4 @@ con
[FFmpeg-devel] [PATCH 5/5] lavf/mpegtsenc: enable PGS split auto bsf
PGS segments must be one per packet for muxing to m2ts --- libavformat/mpegtsenc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index f2be6c6632..5b86dffd0e 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1984,6 +1984,8 @@ static int mpegts_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt (st->codecpar->extradata_size > 0 && st->codecpar->extradata[0] == 1))) ret = ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL); +} else if (st->codecpar->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE) { +ret = ff_stream_add_bitstream_filter(st, "pgs_frame_split", NULL); } return ret; -- 2.25.4 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 4/5] lavf/matroskaenc: enable PGS merge auto bsf
PGS segments must be merged to one packet for muxing to mkv --- libavformat/matroskaenc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 99b549ecc4..7f2cda41b9 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2735,6 +2735,8 @@ static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL); } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) { ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL); +} else if (st->codecpar->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE) { +ret = ff_stream_add_bitstream_filter(st, "pgs_frame_merge", NULL); } return ret; -- 2.25.4 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/5] lavc/pgs_frame_split_bsf: add bsf to split PGS segments
Requried to remux mkv to m2ts --- Changelog| 1 + doc/bitstream_filters.texi | 8 ++ libavcodec/Makefile | 1 + libavcodec/bitstream_filters.c | 1 + libavcodec/pgs_frame_split_bsf.c | 179 +++ 5 files changed, 190 insertions(+) create mode 100644 libavcodec/pgs_frame_split_bsf.c diff --git a/Changelog b/Changelog index 0b108e548f..7564a55220 100644 --- a/Changelog +++ b/Changelog @@ -67,6 +67,7 @@ version : - Pro Pinball Series Soundbank demuxer - pcm_rechunk bitstream filter - PGS subtitle frame merge bitstream filter +- PGS subtitle frame split bitstream filter version 4.2: diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index de2ddcacc4..5b992b1a5d 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -586,6 +586,14 @@ segment into a single packet. This is required by some containers that support PGS subtitles (muxer @code{matroska}). +@section pgs_frame_split + +Split a packet containing a sequence of PGS Subtitle segments into separate +packets each containing a single segment. + +This is required by some streaming formats, typically the MPEG-2 +transport stream format (muxer @code{mpegts}). + @section prores_metadata Modify color property metadata embedded in prores stream. diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1a3c411a81..a011e7c3ba 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1119,6 +1119,7 @@ OBJS-$(CONFIG_NULL_BSF) += null_bsf.o OBJS-$(CONFIG_OPUS_METADATA_BSF) += opus_metadata_bsf.o OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= pcm_rechunk_bsf.o OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o +OBJS-$(CONFIG_PGS_FRAME_SPLIT_BSF)+= pgs_frame_split_bsf.o OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index b4a9388ee2..7c79bc3e4b 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -52,6 +52,7 @@ extern const AVBitStreamFilter ff_null_bsf; extern const AVBitStreamFilter ff_opus_metadata_bsf; extern const AVBitStreamFilter ff_pcm_rechunk_bsf; extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; +extern const AVBitStreamFilter ff_pgs_frame_split_bsf; extern const AVBitStreamFilter ff_prores_metadata_bsf; extern const AVBitStreamFilter ff_remove_extradata_bsf; extern const AVBitStreamFilter ff_text2movsub_bsf; diff --git a/libavcodec/pgs_frame_split_bsf.c b/libavcodec/pgs_frame_split_bsf.c new file mode 100644 index 00..cb60f59a87 --- /dev/null +++ b/libavcodec/pgs_frame_split_bsf.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2020 John Stebbins + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * This bitstream filter splits PGS subtitle packets into packets containing + * just one segment. + * + * Packets already containing only one segment will be passed through + * unchanged. + */ + +#include "libavutil/log.h" +#include "avcodec.h" +#include "bsf.h" +#include "libavutil/intreadwrite.h" + +enum PGSSegmentType { +PALETTE_SEGMENT = 0x14, +OBJECT_SEGMENT = 0x15, +PRESENTATION_SEGMENT= 0x16, +WINDOW_SEGMENT = 0x17, +END_DISPLAY_SET_SEGMENT = 0x80, +}; + +typedef struct PGSSplitContext { +AVPacket *in; +} PGSSplitContext; + +static int frame_split_filter(AVBSFContext *bsf, AVPacket *out) +{ +PGSSplitContext *ctx = bsf->priv_data; +AVPacket *in = ctx->in; +int ret; +unsigned int i; +uint8_t segment_type; +int segment_len; +int split = !!in->data; + +if (!in->data) { +ret = ff_bsf_get_packet_ref(bsf, in); +if (ret < 0) +return ret; +} +if (!in->size) { +av_packet_unref(in); +return AVERROR(EAGAIN); +} + +// Validate packet data +i = 0; +while (i < in->size) { +segment_type = in->data[i]; +segment_len = AV_RB16(in->data
[FFmpeg-devel] [PATCH 3/5] lavc/version: Bump minor-version for new PGS bsfs
--- libavcodec/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/version.h b/libavcodec/version.h index 691320b63c..82255d7f38 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 58 -#define LIBAVCODEC_VERSION_MINOR 83 +#define LIBAVCODEC_VERSION_MINOR 84 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ -- 2.25.4 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/5] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
Required to remux m2ts to mkv --- Changelog| 1 + doc/bitstream_filters.texi | 8 ++ libavcodec/Makefile | 1 + libavcodec/bitstream_filters.c | 1 + libavcodec/pgs_frame_merge_bsf.c | 183 +++ 5 files changed, 194 insertions(+) create mode 100644 libavcodec/pgs_frame_merge_bsf.c diff --git a/Changelog b/Changelog index b75d2b6b96..0b108e548f 100644 --- a/Changelog +++ b/Changelog @@ -66,6 +66,7 @@ version : - asubboost filter - Pro Pinball Series Soundbank demuxer - pcm_rechunk bitstream filter +- PGS subtitle frame merge bitstream filter version 4.2: diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 8a2f55cc41..de2ddcacc4 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -578,6 +578,14 @@ for NTSC frame rate using the @option{frame_rate} option. ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf pcm_rechunk=r=3/1001 -f framecrc - @end example +@section pgs_frame_merge + +Merge a sequence of PGS Subtitle segments ending with an "end of display set" +segment into a single packet. + +This is required by some containers that support PGS subtitles +(muxer @code{matroska}). + @section prores_metadata Modify color property metadata embedded in prores stream. diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 38f6f07680..1a3c411a81 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1118,6 +1118,7 @@ OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o OBJS-$(CONFIG_NULL_BSF) += null_bsf.o OBJS-$(CONFIG_OPUS_METADATA_BSF) += opus_metadata_bsf.o OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= pcm_rechunk_bsf.o +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index 359961fedd..b4a9388ee2 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -51,6 +51,7 @@ extern const AVBitStreamFilter ff_noise_bsf; extern const AVBitStreamFilter ff_null_bsf; extern const AVBitStreamFilter ff_opus_metadata_bsf; extern const AVBitStreamFilter ff_pcm_rechunk_bsf; +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; extern const AVBitStreamFilter ff_prores_metadata_bsf; extern const AVBitStreamFilter ff_remove_extradata_bsf; extern const AVBitStreamFilter ff_text2movsub_bsf; diff --git a/libavcodec/pgs_frame_merge_bsf.c b/libavcodec/pgs_frame_merge_bsf.c new file mode 100644 index 00..b064febe13 --- /dev/null +++ b/libavcodec/pgs_frame_merge_bsf.c @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2020 John Stebbins + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * This bitstream filter merges PGS subtitle packets containing incomplete + * set of segments into a single packet + * + * Packets already containing a complete set of segments will be passed through + * unchanged. + */ + +#include "libavutil/log.h" +#include "avcodec.h" +#include "bsf.h" +#include "libavutil/intreadwrite.h" + +enum PGSSegmentType { +PALETTE_SEGMENT = 0x14, +OBJECT_SEGMENT = 0x15, +PRESENTATION_SEGMENT= 0x16, +WINDOW_SEGMENT = 0x17, +END_DISPLAY_SET_SEGMENT = 0x80, +}; + +typedef struct PGSMergeContext { +AVPacket *buffer_pkt, *in; +int presentation_found; +} PGSMergeContext; + +static void frame_merge_flush(AVBSFContext *bsf) +{ +PGSMergeContext *ctx = bsf->priv_data; + +ctx->presentation_found = 0; +av_packet_unref(ctx->in); +av_packet_unref(ctx->buffer_pkt); +} + +static int frame_merge_filter(AVBSFContext *bsf, AVPacket *out) +{ +PGSMergeContext *ctx = bsf->priv_data; +AVPacket *in = ctx->in, *pkt = ctx->buffer_pkt; +int ret, size, pos, display = 0, presentation = 0; +unsigned int i; + +if (!in->data) { +ret = ff_bsf_get_packet_ref(bsf, in); +if (ret < 0) +return ret; +} +
[FFmpeg-devel] PGS bsfs
Addresses review comments Rebased on master Adds split bsf to mpegtsenc patch ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/4] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
On Mon, 2020-05-04 at 08:29 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > On Sat, 2020-05-02 at 22:30 +0200, Andreas Rheinhardt wrote: > > > John Stebbins: > > > > Required to remux m2ts to mkv > > > > --- > > > > Changelog| 1 + > > > > doc/bitstream_filters.texi | 8 ++ > > > > libavcodec/Makefile | 1 + > > > > libavcodec/bitstream_filters.c | 1 + > > > > libavcodec/pgs_frame_merge_bsf.c | 168 > > > > +++ > > > > 5 files changed, 179 insertions(+) > > > > create mode 100644 libavcodec/pgs_frame_merge_bsf.c > > > > > > > > diff --git a/Changelog b/Changelog > > > > index d9fcd8bb0a..fec4867488 100644 > > > > --- a/Changelog > > > > +++ b/Changelog > > > > @@ -59,6 +59,7 @@ version : > > > > - mv30 decoder > > > > - Expanded styling support for 3GPP Timed Text Subtitles > > > > (movtext) > > > > - WebP parser > > > > +- PGS subtitle frame merge bitstream filter > > > > > > > > > > > > version 4.2: > > > > diff --git a/doc/bitstream_filters.texi > > > > b/doc/bitstream_filters.texi > > > > index 8fe5b3ad75..21ed09986c 100644 > > > > --- a/doc/bitstream_filters.texi > > > > +++ b/doc/bitstream_filters.texi > > > > @@ -548,6 +548,14 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] > > > > output.mkv > > > > @section null > > > > This bitstream filter passes the packets through unchanged. > > > > > > > > +@section pgs_frame_merge > > > > + > > > > +Merge a sequence of PGS Subtitle segments ending with an "end > > > > of > > > > display set" > > > > +segment into a single packet. > > > > + > > > > +This is required by some containers that support PGS subtitles > > > > +(muxer @code{matroska}). > > > > + > > > > @section prores_metadata > > > > > > > > Modify color property metadata embedded in prores stream. > > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > > > > index 88944d9a3a..b630de21bc 100644 > > > > --- a/libavcodec/Makefile > > > > +++ b/libavcodec/Makefile > > > > @@ -1115,6 +1115,7 @@ OBJS- > > > > $(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += > > > > mp3_header_decompress_bsf.o \ > > > > OBJS-$(CONFIG_MPEG2_METADATA_BSF) += > > > > mpeg2_metadata_bsf.o > > > > OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o > > > > OBJS-$(CONFIG_NULL_BSF) += null_bsf.o > > > > +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= > > > > pgs_frame_merge_bsf.o > > > > OBJS-$(CONFIG_PRORES_METADATA_BSF)+= > > > > prores_metadata_bsf.o > > > > OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += > > > > remove_extradata_bsf.o > > > > OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o > > > > diff --git a/libavcodec/bitstream_filters.c > > > > b/libavcodec/bitstream_filters.c > > > > index 6b5ffe4d70..92619225f0 100644 > > > > --- a/libavcodec/bitstream_filters.c > > > > +++ b/libavcodec/bitstream_filters.c > > > > @@ -49,6 +49,7 @@ extern const AVBitStreamFilter > > > > ff_mpeg4_unpack_bframes_bsf; > > > > extern const AVBitStreamFilter ff_mov2textsub_bsf; > > > > extern const AVBitStreamFilter ff_noise_bsf; > > > > extern const AVBitStreamFilter ff_null_bsf; > > > > +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; > > > > extern const AVBitStreamFilter ff_prores_metadata_bsf; > > > > extern const AVBitStreamFilter ff_remove_extradata_bsf; > > > > extern const AVBitStreamFilter ff_text2movsub_bsf; > > > > diff --git a/libavcodec/pgs_frame_merge_bsf.c > > > > b/libavcodec/pgs_frame_merge_bsf.c > > > > new file mode 100644 > > > > index 00..cae5c75655 > > > > --- /dev/null > > > > +++ b/libavcodec/pgs_frame_merge_bsf.c > > > > @@ -0,0 +1,168 @@ > > > > +/* > > > > + * Copyright (c) 2020 John Stebbins > > > > + * > > > > + * This file is part of FFmpeg. > > > > + * > > > > + * FFmpeg is free software; you can redistribute it and/or > &
Re: [FFmpeg-devel] [PATCH 3/4] lavc/pgs_frame_split_bsf: add bsf to split PGS segments
On Sat, 2020-05-02 at 23:05 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > Requried to remux mkv to m2ts > > --- > > Changelog| 1 + > > doc/bitstream_filters.texi | 8 ++ > > libavcodec/Makefile | 1 + > > libavcodec/bitstream_filters.c | 1 + > > libavcodec/pgs_frame_split_bsf.c | 176 > > +++ > > 5 files changed, 187 insertions(+) > > create mode 100644 libavcodec/pgs_frame_split_bsf.c > > > > diff --git a/Changelog b/Changelog > > index fec4867488..372bb4694c 100644 > > --- a/Changelog > > +++ b/Changelog > > @@ -60,6 +60,7 @@ version : > > - Expanded styling support for 3GPP Timed Text Subtitles (movtext) > > - WebP parser > > - PGS subtitle frame merge bitstream filter > > +- PGS subtitle frame split bitstream filter > > > > > > version 4.2: > > diff --git a/doc/bitstream_filters.texi > > b/doc/bitstream_filters.texi > > index 21ed09986c..643c419076 100644 > > --- a/doc/bitstream_filters.texi > > +++ b/doc/bitstream_filters.texi > > @@ -556,6 +556,14 @@ segment into a single packet. > > This is required by some containers that support PGS subtitles > > (muxer @code{matroska}). > > > > +@section pgs_frame_split > > + > > +Split a packet containing a sequence of PGS Subtitle segments into > > separate > > +packets each containing a single segment. > > + > > +This is required by some streaming formats, typically the MPEG-2 > > +transport stream format (muxer @code{mpegts}). > > Is there a reason you don't add this bsf automatically for ts? Yes, it is dependent on: http://ffmpeg.org/pipermail/ffmpeg-devel/2020-April/261598.html I have a patch ready for when the above gets approved and committed > > > + > > @section prores_metadata > > > > Modify color property metadata embedded in prores stream. > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > > index b630de21bc..0e5f2db192 100644 > > --- a/libavcodec/Makefile > > +++ b/libavcodec/Makefile > > @@ -1116,6 +1116,7 @@ OBJS-$(CONFIG_MPEG2_METADATA_BSF) += > > mpeg2_metadata_bsf.o > > OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o > > OBJS-$(CONFIG_NULL_BSF) += null_bsf.o > > OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o > > +OBJS-$(CONFIG_PGS_FRAME_SPLIT_BSF)+= pgs_frame_split_bsf.o > > OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o > > OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += > > remove_extradata_bsf.o > > OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o > > diff --git a/libavcodec/bitstream_filters.c > > b/libavcodec/bitstream_filters.c > > index 92619225f0..02e72c9ca5 100644 > > --- a/libavcodec/bitstream_filters.c > > +++ b/libavcodec/bitstream_filters.c > > @@ -50,6 +50,7 @@ extern const AVBitStreamFilter > > ff_mov2textsub_bsf; > > extern const AVBitStreamFilter ff_noise_bsf; > > extern const AVBitStreamFilter ff_null_bsf; > > extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; > > +extern const AVBitStreamFilter ff_pgs_frame_split_bsf; > > extern const AVBitStreamFilter ff_prores_metadata_bsf; > > extern const AVBitStreamFilter ff_remove_extradata_bsf; > > extern const AVBitStreamFilter ff_text2movsub_bsf; > > diff --git a/libavcodec/pgs_frame_split_bsf.c > > b/libavcodec/pgs_frame_split_bsf.c > > new file mode 100644 > > index 00..c983f6acf5 > > --- /dev/null > > +++ b/libavcodec/pgs_frame_split_bsf.c > > @@ -0,0 +1,176 @@ > > +/* > > + * Copyright (c) 2020 John Stebbins > > + * > > + * This file is part of FFmpeg. > > + * > > + * FFmpeg is free software; you can redistribute it and/or > > + * modify it under the terms of the GNU Lesser General Public > > + * License as published by the Free Software Foundation; either > > + * version 2.1 of the License, or (at your option) any later > > version. > > + * > > + * FFmpeg is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > GNU > > + * Lesser General Public License for more details. > > + * > > + * You should have received a copy of the GNU Lesser General > > Public > > + * License along with FFmpeg; if not, write to the Free Software > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > > 0
Re: [FFmpeg-devel] [PATCH 2/4] lavf/matroskaenc: add PGS merge to auto bsf list
On Sat, 2020-05-02 at 22:40 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > PGS segments must be merged to one packet for muxing to mkv > > --- > > libavformat/matroskaenc.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c > > index d3256d8f5d..bccf8b11d2 100644 > > --- a/libavformat/matroskaenc.c > > +++ b/libavformat/matroskaenc.c > > @@ -2655,6 +2655,8 @@ static int mkv_check_bitstream(struct > > AVFormatContext *s, const AVPacket *pkt) > > ret = ff_stream_add_bitstream_filter(st, > > "aac_adtstoasc", NULL); > > } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) { > > ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", > > NULL); > > +} else if (st->codecpar->codec_id == > > AV_CODEC_ID_HDMV_PGS_SUBTITLE) { > > +ret = ff_stream_add_bitstream_filter(st, > > "pgs_frame_merge", NULL); > > } > > > > return ret; > > > 1128aa875367f66ac11adc30364d5652919a2591 removed the auto bsf list > (no > muxer added more than one bsf for the same stream), so your commit > message needs to be updated. > Will do ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/4] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
On Sat, 2020-05-02 at 22:30 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > Required to remux m2ts to mkv > > --- > > Changelog| 1 + > > doc/bitstream_filters.texi | 8 ++ > > libavcodec/Makefile | 1 + > > libavcodec/bitstream_filters.c | 1 + > > libavcodec/pgs_frame_merge_bsf.c | 168 > > +++ > > 5 files changed, 179 insertions(+) > > create mode 100644 libavcodec/pgs_frame_merge_bsf.c > > > > diff --git a/Changelog b/Changelog > > index d9fcd8bb0a..fec4867488 100644 > > --- a/Changelog > > +++ b/Changelog > > @@ -59,6 +59,7 @@ version : > > - mv30 decoder > > - Expanded styling support for 3GPP Timed Text Subtitles (movtext) > > - WebP parser > > +- PGS subtitle frame merge bitstream filter > > > > > > version 4.2: > > diff --git a/doc/bitstream_filters.texi > > b/doc/bitstream_filters.texi > > index 8fe5b3ad75..21ed09986c 100644 > > --- a/doc/bitstream_filters.texi > > +++ b/doc/bitstream_filters.texi > > @@ -548,6 +548,14 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] > > output.mkv > > @section null > > This bitstream filter passes the packets through unchanged. > > > > +@section pgs_frame_merge > > + > > +Merge a sequence of PGS Subtitle segments ending with an "end of > > display set" > > +segment into a single packet. > > + > > +This is required by some containers that support PGS subtitles > > +(muxer @code{matroska}). > > + > > @section prores_metadata > > > > Modify color property metadata embedded in prores stream. > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > > index 88944d9a3a..b630de21bc 100644 > > --- a/libavcodec/Makefile > > +++ b/libavcodec/Makefile > > @@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += > > mp3_header_decompress_bsf.o \ > > OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o > > OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o > > OBJS-$(CONFIG_NULL_BSF) += null_bsf.o > > +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o > > OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o > > OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += > > remove_extradata_bsf.o > > OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o > > diff --git a/libavcodec/bitstream_filters.c > > b/libavcodec/bitstream_filters.c > > index 6b5ffe4d70..92619225f0 100644 > > --- a/libavcodec/bitstream_filters.c > > +++ b/libavcodec/bitstream_filters.c > > @@ -49,6 +49,7 @@ extern const AVBitStreamFilter > > ff_mpeg4_unpack_bframes_bsf; > > extern const AVBitStreamFilter ff_mov2textsub_bsf; > > extern const AVBitStreamFilter ff_noise_bsf; > > extern const AVBitStreamFilter ff_null_bsf; > > +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; > > extern const AVBitStreamFilter ff_prores_metadata_bsf; > > extern const AVBitStreamFilter ff_remove_extradata_bsf; > > extern const AVBitStreamFilter ff_text2movsub_bsf; > > diff --git a/libavcodec/pgs_frame_merge_bsf.c > > b/libavcodec/pgs_frame_merge_bsf.c > > new file mode 100644 > > index 00..cae5c75655 > > --- /dev/null > > +++ b/libavcodec/pgs_frame_merge_bsf.c > > @@ -0,0 +1,168 @@ > > +/* > > + * Copyright (c) 2020 John Stebbins > > + * > > + * This file is part of FFmpeg. > > + * > > + * FFmpeg is free software; you can redistribute it and/or > > + * modify it under the terms of the GNU Lesser General Public > > + * License as published by the Free Software Foundation; either > > + * version 2.1 of the License, or (at your option) any later > > version. > > + * > > + * FFmpeg is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > GNU > > + * Lesser General Public License for more details. > > + * > > + * You should have received a copy of the GNU Lesser General > > Public > > + * License along with FFmpeg; if not, write to the Free Software > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > > 02110-1301 USA > > + */ > > + > > +/** > > + * @file > > + * This bitstream filter merges PGS subtitle packets containing > > incomplete > > + * set of segments into a single packet > > + * > > + * Packet
[FFmpeg-devel] [PATCH] avformat/matroskaenc: return error if aac extradata changes
extradata changing would result in an invalid and undecodable stream. Also, as the code was written, rewriting extradata was corrupting the track header resulting in an invalid file. --- libavformat/matroskaenc.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 784973a951..ae5636f71d 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2183,6 +2183,16 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) case AV_CODEC_ID_AAC: if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { int filler, output_sample_rate = 0; +if (par->extradata && par->extradata_size) { +if (par->extradata_size != side_data_size || +memcmp(par->extradata, side_data, side_data_size)) { +av_log(s, AV_LOG_ERROR, "Error, AAC extradata changed mid-stream.\n"); +return AVERROR_INPUT_CHANGED; +} else { // Already written +break; +} +} + ret = get_aac_sample_rates(s, side_data, side_data_size, &track->sample_rate, &output_sample_rate); if (ret < 0) -- 2.25.4 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avformat/matroskaenc: return error if aac extradata changes
extradata changing would result in an invalid stream. also, as the code was written, rewriting extradata was corrupting the track header resulting in an invalid file. --- libavformat/matroskaenc.c | 8 1 file changed, 8 insertions(+) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 784973a951..d6932bdb5b 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2183,6 +2183,14 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) case AV_CODEC_ID_AAC: if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { int filler, output_sample_rate = 0; +if (par->extradata && par->extradata_size) +if (par->extradata_size != side_data_size || +memcmp(par->extradata, side_data, side_data_size)) { +av_log(s, AV_LOG_ERROR, "Error, AAC extradata changed mid-stream.\n"); +return AVERROR_INPUT_CHANGED; +} else // Already written +break; + ret = get_aac_sample_rates(s, side_data, side_data_size, &track->sample_rate, &output_sample_rate); if (ret < 0) -- 2.25.4 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avformat/matroskaenc: always reserve max aac private data
On Fri, 2020-05-01 at 20:28 +0200, Nicolas George wrote: > John Stebbins (12020-05-01): > > Well, current code in aac_adtstoasc silently ignores any > > changes. It > > only generates extradata from the initial packet. It's not checked > > in > > subsequent packets. > > > > So this would have to be "fixed" in aac_adtstoasc as well if you > > want > > to add error logging. > > Probably. I want to emphasize that bugs in our current code cannot be > considered precedent to accept similar bugs in new code. > > > This is also a bit beyond my expertise. I don't know what would > > constitute incompitible parameters beyond a few obvious > > things. I'm > > not well versed in aac details. > > Then for now, I would say that we can only accept when it is > bit-identical with the extradata already there. If we cannot test for > compatibility more finely, then we have to assume incompatibility and > reject every AV_PKT_DATA_NEW_EXTRADATA with an error. > > Seems reasonable. To be clear, this should result in an error returned up the call stack (i.e. av_interleaved_write_frame would ultimately return an error), and an error log? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avformat/matroskaenc: always reserve max aac private data
On Fri, 2020-05-01 at 20:10 +0200, Nicolas George wrote: > John Stebbins (12020-05-01): > > If the parameters change on the fly, some part of the audio stream > > is > > going to be unplayable. Either the part after the change will be > > unplayable if you ignore extradata changes, or everything > > preceeding > > the last extradata change will be unplayable if you rewrite codec > > private on every change. > > Then the only acceptable solution is to report an error. > > If we can detect that the new extradata is compatible and will not > cause > the file to be unplayable, we can let it pass, but we should try to > NEVER allow to lose data without notifying users. > Well, current code in aac_adtstoasc silently ignores any changes. It only generates extradata from the initial packet. It's not checked in subsequent packets. So this would have to be "fixed" in aac_adtstoasc as well if you want to add error logging. This is also a bit beyond my expertise. I don't know what would constitute incompitible parameters beyond a few obvious things. I'm not well versed in aac details. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avformat/matroskaenc: always reserve max aac private data
On Fri, 2020-05-01 at 20:03 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > On Fri, 2020-05-01 at 14:27 -0300, James Almer wrote: > > > On 5/1/2020 2:09 PM, John Stebbins wrote: > > > > When extra data is updated using AV_PKT_DATA_NEW_EXTRADATA, the > > > > data is > > > > written plus extra space is reserved for the max possible size > > > > extradata. > > > > But when extradata is written during mkv_write_header, no extra > > > > space is > > > > reserved. So the side data update overwrites whatever follows > > > > the > > > > extradata in the track header and results in an invalid file. > > > > > > In what scenario there's extradata during init() and then new > > > extradata > > > propagated in a packet side data for AAC? And should the side > > > data > > > one > > > take priority over the original one? > > > > > > > This is partially a HandBrake issue. Before ffmpeg ever had side > > data, > > HandBrake parsed the extradata out of the aac stream in TS files > > ourselves before initializing the muxer. We still do this, so > > extradata is supplied by us when the muxer it initialized and again > > by > > side data generated in aac_adtstoasc bsf. > > > Does this mean that HandBrake's extradata and the aac_adtstoasc bsf > side-data extradata are actually one and the same? > Yes ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avformat/matroskaenc: always reserve max aac private data
On Fri, 2020-05-01 at 19:55 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > On Fri, 2020-05-01 at 19:22 +0200, Andreas Rheinhardt wrote: > > > John Stebbins: > > > > When extra data is updated using AV_PKT_DATA_NEW_EXTRADATA, the > > > > data is > > > > written plus extra space is reserved for the max possible size > > > > extradata. > > > > But when extradata is written during mkv_write_header, no extra > > > > space is > > > > reserved. So the side data update overwrites whatever follows > > > > the > > > > extradata in the track header and results in an invalid file. > > > > --- > > > > libavformat/matroskaenc.c | 14 -- > > > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > > > > > diff --git a/libavformat/matroskaenc.c > > > > b/libavformat/matroskaenc.c > > > > index 784973a951..e6917002c4 100644 > > > > --- a/libavformat/matroskaenc.c > > > > +++ b/libavformat/matroskaenc.c > > > > @@ -728,8 +728,6 @@ static int > > > > mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext > > > > *pb, > > > > case AV_CODEC_ID_AAC: > > > > if (par->extradata_size) > > > > avio_write(dyn_cp, par->extradata, par- > > > > > extradata_size); > > > > -else > > > > -put_ebml_void(pb, MAX_PCE_SIZE + 2 + 4); > > > > break; > > > > default: > > > > if (par->codec_id == AV_CODEC_ID_PRORES && > > > > @@ -749,6 +747,7 @@ static int > > > > mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, > > > > AVIOContext *dyn_cp; > > > > uint8_t *codecpriv; > > > > int ret, codecpriv_size; > > > > +int64_t offset; > > > > > > > > ret = avio_open_dyn_buf(&dyn_cp); > > > > if (ret < 0) > > > > @@ -802,9 +801,15 @@ static int > > > > mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, > > > > } > > > > > > > > codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv); > > > > +offset = avio_tell(pb); > > > > if (codecpriv_size) > > > > put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, > > > > codecpriv, > > > > codecpriv_size); > > > > +if (par->codec_id == AV_CODEC_ID_AAC) { > > > > +int filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(pb) - > > > > offset); > > > > +if (filler) > > > > +put_ebml_void(pb, filler); > > > > +} > > > > ffio_free_dyn_buf(&dyn_cp); > > > > return ret; > > > > } > > > > @@ -2182,7 +2187,7 @@ static int > > > > mkv_check_new_extra_data(AVFormatContext *s, const AVPacket > > > > *pkt) > > > > switch (par->codec_id) { > > > > case AV_CODEC_ID_AAC: > > > > if (side_data_size && (s->pb->seekable & > > > > AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { > > > > -int filler, output_sample_rate = 0; > > > > +int output_sample_rate = 0; > > > > ret = get_aac_sample_rates(s, side_data, > > > > side_data_size, &track->sample_rate, > > > > &output_sample_rate); > > > > if (ret < 0) > > > > @@ -2195,9 +2200,6 @@ static int > > > > mkv_check_new_extra_data(AVFormatContext *s, const AVPacket > > > > *pkt) > > > > memcpy(par->extradata, side_data, side_data_size); > > > > avio_seek(mkv->tracks_bc, track->codecpriv_offset, > > > > SEEK_SET); > > > > mkv_write_codecprivate(s, mkv->tracks_bc, par, 1, > > > > 0); > > > > -filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(mkv- > > > > > tracks_bc) - track->codecpriv_offset); > > > > -if (filler) > > > > -put_ebml_void(mkv->tracks_bc, filler); > > > > avio_seek(mkv->tracks_bc, track- > > > > >sample_rate_offset, > > > > SEEK_SET); > > > > put_ebml_float(mkv->tracks_bc, > > > >
Re: [FFmpeg-devel] [PATCH] avformat/matroskaenc: always reserve max aac private data
On Fri, 2020-05-01 at 19:53 +0200, Nicolas George wrote: > John Stebbins (12020-05-01): > > The test case is a TS file with aac audio. It TS files, it is > > certainly possible for stream parameters to change on the fly. But, > > if > > the extradata changes, there's really no way to handle it in mkv > > since > > this data is global in mkv. So perhaps a better solution is to > > ignore > > side data extradata if it's already been written once? > > Would it not lead to a corrupted file, possibly unplayable? > > If the parameters change on the fly, some part of the audio stream is going to be unplayable. Either the part after the change will be unplayable if you ignore extradata changes, or everything preceeding the last extradata change will be unplayable if you rewrite codec private on every change. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avformat/matroskaenc: always reserve max aac private data
On Fri, 2020-05-01 at 14:27 -0300, James Almer wrote: > On 5/1/2020 2:09 PM, John Stebbins wrote: > > When extra data is updated using AV_PKT_DATA_NEW_EXTRADATA, the > > data is > > written plus extra space is reserved for the max possible size > > extradata. > > But when extradata is written during mkv_write_header, no extra > > space is > > reserved. So the side data update overwrites whatever follows the > > extradata in the track header and results in an invalid file. > > In what scenario there's extradata during init() and then new > extradata > propagated in a packet side data for AAC? And should the side data > one > take priority over the original one? > This is partially a HandBrake issue. Before ffmpeg ever had side data, HandBrake parsed the extradata out of the aac stream in TS files ourselves before initializing the muxer. We still do this, so extradata is supplied by us when the muxer it initialized and again by side data generated in aac_adtstoasc bsf. So remuxing ts to mkv with ffmpeg exe does not have this problem. But it is a problem when using the API in valid ways. I don't think it matters which takes priority. If stream parameters change, there really is no way to handle in mkv since this is global data in mkv. So perhaps just ignore side data when extradata has already been set once? > With FLAC we know it must have priority because the encoder sends it > at > the end of the encoding process with information that was not > available > during init(), but afaik that's not the case with AAC. > > > --- > > libavformat/matroskaenc.c | 14 -- > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c > > index 784973a951..e6917002c4 100644 > > --- a/libavformat/matroskaenc.c > > +++ b/libavformat/matroskaenc.c > > @@ -728,8 +728,6 @@ static int > > mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, > > case AV_CODEC_ID_AAC: > > if (par->extradata_size) > > avio_write(dyn_cp, par->extradata, par- > > >extradata_size); > > -else > > -put_ebml_void(pb, MAX_PCE_SIZE + 2 + 4); > > break; > > default: > > if (par->codec_id == AV_CODEC_ID_PRORES && > > @@ -749,6 +747,7 @@ static int > > mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, > > AVIOContext *dyn_cp; > > uint8_t *codecpriv; > > int ret, codecpriv_size; > > +int64_t offset; > > > > ret = avio_open_dyn_buf(&dyn_cp); > > if (ret < 0) > > @@ -802,9 +801,15 @@ static int > > mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, > > } > > > > codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv); > > +offset = avio_tell(pb); > > if (codecpriv_size) > > put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codecpriv, > > codecpriv_size); > > +if (par->codec_id == AV_CODEC_ID_AAC) { > > +int filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(pb) - > > offset); > > +if (filler) > > +put_ebml_void(pb, filler); > > +} > > Why are you adding this here instead of adapting the code in > mkv_write_native_codecprivate()? > > Can't you just do something like > > case AV_CODEC_ID_AAC: > if (par->extradata_size) > avio_write(dyn_cp, par->extradata, par->extradata_size); > put_ebml_void(pb, MAX_PCE_SIZE + 2 + 4 - avio_tell(dyn_cp)); > break; > > > ffio_free_dyn_buf(&dyn_cp); > > return ret; > > } > > @@ -2182,7 +2187,7 @@ static int > > mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) > > switch (par->codec_id) { > > case AV_CODEC_ID_AAC: > > if (side_data_size && (s->pb->seekable & > > AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { > > -int filler, output_sample_rate = 0; > > +int output_sample_rate = 0; > > ret = get_aac_sample_rates(s, side_data, > > side_data_size, &track->sample_rate, > > &output_sample_rate); > > if (ret < 0) > > @@ -2195,9 +2200,6 @@ static int > > mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) > > memcpy(par->extradata, side_data, side_data_size); > > avio_seek(mkv->tracks_bc, track->codecpriv_offset, > > SEEK_SET); >
Re: [FFmpeg-devel] [PATCH] avformat/matroskaenc: always reserve max aac private data
On Fri, 2020-05-01 at 19:22 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > When extra data is updated using AV_PKT_DATA_NEW_EXTRADATA, the > > data is > > written plus extra space is reserved for the max possible size > > extradata. > > But when extradata is written during mkv_write_header, no extra > > space is > > reserved. So the side data update overwrites whatever follows the > > extradata in the track header and results in an invalid file. > > --- > > libavformat/matroskaenc.c | 14 -- > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c > > index 784973a951..e6917002c4 100644 > > --- a/libavformat/matroskaenc.c > > +++ b/libavformat/matroskaenc.c > > @@ -728,8 +728,6 @@ static int > > mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, > > case AV_CODEC_ID_AAC: > > if (par->extradata_size) > > avio_write(dyn_cp, par->extradata, par- > > >extradata_size); > > -else > > -put_ebml_void(pb, MAX_PCE_SIZE + 2 + 4); > > break; > > default: > > if (par->codec_id == AV_CODEC_ID_PRORES && > > @@ -749,6 +747,7 @@ static int > > mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, > > AVIOContext *dyn_cp; > > uint8_t *codecpriv; > > int ret, codecpriv_size; > > +int64_t offset; > > > > ret = avio_open_dyn_buf(&dyn_cp); > > if (ret < 0) > > @@ -802,9 +801,15 @@ static int > > mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, > > } > > > > codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv); > > +offset = avio_tell(pb); > > if (codecpriv_size) > > put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codecpriv, > > codecpriv_size); > > +if (par->codec_id == AV_CODEC_ID_AAC) { > > +int filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(pb) - > > offset); > > +if (filler) > > +put_ebml_void(pb, filler); > > +} > > ffio_free_dyn_buf(&dyn_cp); > > return ret; > > } > > @@ -2182,7 +2187,7 @@ static int > > mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) > > switch (par->codec_id) { > > case AV_CODEC_ID_AAC: > > if (side_data_size && (s->pb->seekable & > > AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { > > -int filler, output_sample_rate = 0; > > +int output_sample_rate = 0; > > ret = get_aac_sample_rates(s, side_data, > > side_data_size, &track->sample_rate, > > &output_sample_rate); > > if (ret < 0) > > @@ -2195,9 +2200,6 @@ static int > > mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) > > memcpy(par->extradata, side_data, side_data_size); > > avio_seek(mkv->tracks_bc, track->codecpriv_offset, > > SEEK_SET); > > mkv_write_codecprivate(s, mkv->tracks_bc, par, 1, 0); > > -filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(mkv- > > >tracks_bc) - track->codecpriv_offset); > > -if (filler) > > -put_ebml_void(mkv->tracks_bc, filler); > > avio_seek(mkv->tracks_bc, track->sample_rate_offset, > > SEEK_SET); > > put_ebml_float(mkv->tracks_bc, > > MATROSKA_ID_AUDIOSAMPLINGFREQ, track->sample_rate); > > put_ebml_float(mkv->tracks_bc, > > MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate); > > > If we already had extradata when writing the header, then what > guarantees us that the new extradata is better and should be > preferred > to the old extradata? (I don't know the details of AAC extradata, but > is > it possible that the extradata is simply incompatible to the old one > (e.g. when a user splices together actually incompatible streams)?) > The test case is a TS file with aac audio. It TS files, it is certainly possible for stream parameters to change on the fly. But, if the extradata changes, there's really no way to handle it in mkv since this data is global in mkv. So perhaps a better solution is to ignore side data extradata if it's already been written once? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avformat/matroskaenc: always reserve max aac private data
When extra data is updated using AV_PKT_DATA_NEW_EXTRADATA, the data is written plus extra space is reserved for the max possible size extradata. But when extradata is written during mkv_write_header, no extra space is reserved. So the side data update overwrites whatever follows the extradata in the track header and results in an invalid file. --- libavformat/matroskaenc.c | 14 -- 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 784973a951..e6917002c4 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -728,8 +728,6 @@ static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, case AV_CODEC_ID_AAC: if (par->extradata_size) avio_write(dyn_cp, par->extradata, par->extradata_size); -else -put_ebml_void(pb, MAX_PCE_SIZE + 2 + 4); break; default: if (par->codec_id == AV_CODEC_ID_PRORES && @@ -749,6 +747,7 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVIOContext *dyn_cp; uint8_t *codecpriv; int ret, codecpriv_size; +int64_t offset; ret = avio_open_dyn_buf(&dyn_cp); if (ret < 0) @@ -802,9 +801,15 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, } codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv); +offset = avio_tell(pb); if (codecpriv_size) put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codecpriv, codecpriv_size); +if (par->codec_id == AV_CODEC_ID_AAC) { +int filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(pb) - offset); +if (filler) +put_ebml_void(pb, filler); +} ffio_free_dyn_buf(&dyn_cp); return ret; } @@ -2182,7 +2187,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) switch (par->codec_id) { case AV_CODEC_ID_AAC: if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { -int filler, output_sample_rate = 0; +int output_sample_rate = 0; ret = get_aac_sample_rates(s, side_data, side_data_size, &track->sample_rate, &output_sample_rate); if (ret < 0) @@ -2195,9 +2200,6 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) memcpy(par->extradata, side_data, side_data_size); avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET); mkv_write_codecprivate(s, mkv->tracks_bc, par, 1, 0); -filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(mkv->tracks_bc) - track->codecpriv_offset); -if (filler) -put_ebml_void(mkv->tracks_bc, filler); avio_seek(mkv->tracks_bc, track->sample_rate_offset, SEEK_SET); put_ebml_float(mkv->tracks_bc, MATROSKA_ID_AUDIOSAMPLINGFREQ, track->sample_rate); put_ebml_float(mkv->tracks_bc, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate); -- 2.25.4 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] PGS subtitle bitstream filters
On Sat, 2020-04-18 at 08:25 -0600, John Stebbins wrote: > Added Changelog entries > Added doc/bitstream_filters.texi entries > Added minor version bump patch > Changed how keyframe detection works in merge > > > Ping. Of the 4 patches, only the first has received comments in an earlier version. Changelog and version.h now have conflicts with master. Should I resend the series rebased against master? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2 4/6] avformat/mux: add proper support for full N:M bitstream filtering
On Sat, 2020-04-18 at 21:18 +0200, Marton Balint wrote: > Previously only 1:1 bitstream filters were supported, the end of the > stream was > not signalled to the bitstream filters and time base changes were > ignored. > > Signed-off-by: Marton Balint > --- > libavformat/mux.c | 91 ++--- > -- > 1 file changed, 57 insertions(+), 34 deletions(-) > FWIW, this works as expected with my PGS splitter bsf ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 4/4] avcodec/version: Bump minor-version for new PGS bsfs
--- libavcodec/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/version.h b/libavcodec/version.h index 8cff2e855b..ad85fb15e5 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 58 -#define LIBAVCODEC_VERSION_MINOR 80 +#define LIBAVCODEC_VERSION_MINOR 81 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/4] lavc/pgs_frame_split_bsf: add bsf to split PGS segments
Requried to remux mkv to m2ts --- Changelog| 1 + doc/bitstream_filters.texi | 8 ++ libavcodec/Makefile | 1 + libavcodec/bitstream_filters.c | 1 + libavcodec/pgs_frame_split_bsf.c | 176 +++ 5 files changed, 187 insertions(+) create mode 100644 libavcodec/pgs_frame_split_bsf.c diff --git a/Changelog b/Changelog index fec4867488..372bb4694c 100644 --- a/Changelog +++ b/Changelog @@ -60,6 +60,7 @@ version : - Expanded styling support for 3GPP Timed Text Subtitles (movtext) - WebP parser - PGS subtitle frame merge bitstream filter +- PGS subtitle frame split bitstream filter version 4.2: diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 21ed09986c..643c419076 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -556,6 +556,14 @@ segment into a single packet. This is required by some containers that support PGS subtitles (muxer @code{matroska}). +@section pgs_frame_split + +Split a packet containing a sequence of PGS Subtitle segments into separate +packets each containing a single segment. + +This is required by some streaming formats, typically the MPEG-2 +transport stream format (muxer @code{mpegts}). + @section prores_metadata Modify color property metadata embedded in prores stream. diff --git a/libavcodec/Makefile b/libavcodec/Makefile index b630de21bc..0e5f2db192 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1116,6 +1116,7 @@ OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o OBJS-$(CONFIG_NULL_BSF) += null_bsf.o OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o +OBJS-$(CONFIG_PGS_FRAME_SPLIT_BSF)+= pgs_frame_split_bsf.o OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index 92619225f0..02e72c9ca5 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -50,6 +50,7 @@ extern const AVBitStreamFilter ff_mov2textsub_bsf; extern const AVBitStreamFilter ff_noise_bsf; extern const AVBitStreamFilter ff_null_bsf; extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; +extern const AVBitStreamFilter ff_pgs_frame_split_bsf; extern const AVBitStreamFilter ff_prores_metadata_bsf; extern const AVBitStreamFilter ff_remove_extradata_bsf; extern const AVBitStreamFilter ff_text2movsub_bsf; diff --git a/libavcodec/pgs_frame_split_bsf.c b/libavcodec/pgs_frame_split_bsf.c new file mode 100644 index 00..c983f6acf5 --- /dev/null +++ b/libavcodec/pgs_frame_split_bsf.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2020 John Stebbins + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * This bitstream filter splits PGS subtitle packets into packets containing + * just one segment. + * + * Packets already containing only one segment will be passed through + * unchanged. + */ + +#include "avcodec.h" +#include "bsf.h" +#include "libavutil/intreadwrite.h" + +enum PGSSegmentType { +PALETTE_SEGMENT = 0x14, +OBJECT_SEGMENT = 0x15, +PRESENTATION_SEGMENT = 0x16, +WINDOW_SEGMENT = 0x17, +DISPLAY_SEGMENT = 0x80, +}; + +typedef struct PGSSplitContext { +AVPacket *in; +} PGSSplitContext; + +static int frame_split_filter(AVBSFContext *bsf, AVPacket *out) +{ +PGSSplitContext *ctx = bsf->priv_data; +AVPacket *in = ctx->in; +int i, ret; +uint8_t segment_type; +uint16_t segment_len; +int split = !!in->data; + +if (!in->data) { +ret = ff_bsf_get_packet_ref(bsf, in); +if (ret < 0) +return ret; +} +if (!in->size) { +av_packet_unref(in); +return AVERROR(EAGAIN); +} + +// Validate packet data +i = 0; +while (i < in->size) { +segment_type = in->data[i]; +segment_len = AV_RB16(in->data + i + 1) + 3; +i += segment_len; +} +if (i != in->size) { +
[FFmpeg-devel] [PATCH 1/4] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
Required to remux m2ts to mkv --- Changelog| 1 + doc/bitstream_filters.texi | 8 ++ libavcodec/Makefile | 1 + libavcodec/bitstream_filters.c | 1 + libavcodec/pgs_frame_merge_bsf.c | 168 +++ 5 files changed, 179 insertions(+) create mode 100644 libavcodec/pgs_frame_merge_bsf.c diff --git a/Changelog b/Changelog index d9fcd8bb0a..fec4867488 100644 --- a/Changelog +++ b/Changelog @@ -59,6 +59,7 @@ version : - mv30 decoder - Expanded styling support for 3GPP Timed Text Subtitles (movtext) - WebP parser +- PGS subtitle frame merge bitstream filter version 4.2: diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 8fe5b3ad75..21ed09986c 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -548,6 +548,14 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv @section null This bitstream filter passes the packets through unchanged. +@section pgs_frame_merge + +Merge a sequence of PGS Subtitle segments ending with an "end of display set" +segment into a single packet. + +This is required by some containers that support PGS subtitles +(muxer @code{matroska}). + @section prores_metadata Modify color property metadata embedded in prores stream. diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 88944d9a3a..b630de21bc 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += mp3_header_decompress_bsf.o \ OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o OBJS-$(CONFIG_NULL_BSF) += null_bsf.o +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index 6b5ffe4d70..92619225f0 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf; extern const AVBitStreamFilter ff_mov2textsub_bsf; extern const AVBitStreamFilter ff_noise_bsf; extern const AVBitStreamFilter ff_null_bsf; +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; extern const AVBitStreamFilter ff_prores_metadata_bsf; extern const AVBitStreamFilter ff_remove_extradata_bsf; extern const AVBitStreamFilter ff_text2movsub_bsf; diff --git a/libavcodec/pgs_frame_merge_bsf.c b/libavcodec/pgs_frame_merge_bsf.c new file mode 100644 index 00..cae5c75655 --- /dev/null +++ b/libavcodec/pgs_frame_merge_bsf.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2020 John Stebbins + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * This bitstream filter merges PGS subtitle packets containing incomplete + * set of segments into a single packet + * + * Packets already containing a complete set of segments will be passed through + * unchanged. + */ + +#include "avcodec.h" +#include "bsf.h" +#include "libavutil/intreadwrite.h" + +enum PGSSegmentType { +PALETTE_SEGMENT = 0x14, +OBJECT_SEGMENT = 0x15, +PRESENTATION_SEGMENT = 0x16, +WINDOW_SEGMENT = 0x17, +DISPLAY_SEGMENT = 0x80, +}; + +typedef struct PGSMergeContext { +AVPacket *buffer_pkt, *in; +int presentation_found; +} PGSMergeContext; + +static void frame_merge_flush(AVBSFContext *bsf) +{ +PGSMergeContext *ctx = bsf->priv_data; + +av_packet_unref(ctx->in); +av_packet_unref(ctx->buffer_pkt); +} + +static int frame_merge_filter(AVBSFContext *bsf, AVPacket *out) +{ +PGSMergeContext *ctx = bsf->priv_data; +AVPacket *in = ctx->in, *pkt = ctx->buffer_pkt; +int ret, i, size, pos, display = 0; + +if (!in->data) { +ret = ff_bsf_get_packet_ref(bsf, in); +if (ret < 0) +return ret; +} +if (!in->size) { +av_packet_unref(in); +return AVERROR(EAGAIN); +} + +// Validate packet data and find display_end segm
[FFmpeg-devel] [PATCH 2/4] lavf/matroskaenc: add PGS merge to auto bsf list
PGS segments must be merged to one packet for muxing to mkv --- libavformat/matroskaenc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index d3256d8f5d..bccf8b11d2 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2655,6 +2655,8 @@ static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL); } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) { ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL); +} else if (st->codecpar->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE) { +ret = ff_stream_add_bitstream_filter(st, "pgs_frame_merge", NULL); } return ret; -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] PGS subtitle bitstream filters
Added Changelog entries Added doc/bitstream_filters.texi entries Added minor version bump patch Changed how keyframe detection works in merge ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/3] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
On Fri, 2020-04-17 at 08:52 -0700, John Stebbins wrote: > On Fri, 2020-04-17 at 13:21 +0300, Petri Hintukainen wrote: > > to, 2020-04-16 kello 16:57 -0600, John Stebbins kirjoitti: > > > Required to remux m2ts to mkv > > > --- > > > libavcodec/Makefile | 1 + > > > libavcodec/bitstream_filters.c | 1 + > > > libavcodec/pgs_frame_merge_bsf.c | 164 > > > +++ > > > 3 files changed, 166 insertions(+) > > > create mode 100644 libavcodec/pgs_frame_merge_bsf.c > > > > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > > > index c1c9a44f2b..c7d8fbebaa 100644 > > > --- a/libavcodec/Makefile > > > +++ b/libavcodec/Makefile > > > @@ -1110,6 +1110,7 @@ OBJS- > > > $(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += > > > mp3_header_decompress_bsf.o \ > > > OBJS-$(CONFIG_MPEG2_METADATA_BSF) += > > > mpeg2_metadata_bsf.o > > > OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o > > > OBJS-$(CONFIG_NULL_BSF) += null_bsf.o > > > +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= > > > pgs_frame_merge_bsf.o > > > OBJS-$(CONFIG_PRORES_METADATA_BSF)+= > > > prores_metadata_bsf.o > > > OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += > > > remove_extradata_bsf.o > > > OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o > > > diff --git a/libavcodec/bitstream_filters.c > > > b/libavcodec/bitstream_filters.c > > > index 6b5ffe4d70..92619225f0 100644 > > > --- a/libavcodec/bitstream_filters.c > > > +++ b/libavcodec/bitstream_filters.c > > > @@ -49,6 +49,7 @@ extern const AVBitStreamFilter > > > ff_mpeg4_unpack_bframes_bsf; > > > extern const AVBitStreamFilter ff_mov2textsub_bsf; > > > extern const AVBitStreamFilter ff_noise_bsf; > > > extern const AVBitStreamFilter ff_null_bsf; > > > +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; > > > extern const AVBitStreamFilter ff_prores_metadata_bsf; > > > extern const AVBitStreamFilter ff_remove_extradata_bsf; > > > extern const AVBitStreamFilter ff_text2movsub_bsf; > > > diff --git a/libavcodec/pgs_frame_merge_bsf.c > > > b/libavcodec/pgs_frame_merge_bsf.c > > > new file mode 100644 > > > index 00..d1bb3a60c2 > > > --- /dev/null > > > +++ b/libavcodec/pgs_frame_merge_bsf.c > > > @@ -0,0 +1,164 @@ > > > +/* > > > + * Copyright (c) 2020 John Stebbins > > > + * > > > + * This file is part of FFmpeg. > > > + * > > > + * FFmpeg is free software; you can redistribute it and/or > > > + * modify it under the terms of the GNU Lesser General Public > > > + * License as published by the Free Software Foundation; either > > > + * version 2.1 of the License, or (at your option) any later > > > version. > > > + * > > > + * FFmpeg is distributed in the hope that it will be useful, > > > + * but WITHOUT ANY WARRANTY; without even the implied warranty > > > of > > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > > GNU > > > + * Lesser General Public License for more details. > > > + * > > > + * You should have received a copy of the GNU Lesser General > > > Public > > > + * License along with FFmpeg; if not, write to the Free Software > > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > > > 02110-1301 USA > > > + */ > > > + > > > +/** > > > + * @file > > > + * This bitstream filter merges PGS subtitle packets containing > > > incomplete > > > + * set of segments into a single packet > > > + * > > > + * Packets already containing a complete set of segments will be > > > passed through > > > + * unchanged. > > > + */ > > > + > > > +#include "avcodec.h" > > > +#include "bsf.h" > > > +#include "libavutil/intreadwrite.h" > > > + > > > +enum PGSSegmentType { > > > +PALETTE_SEGMENT = 0x14, > > > +OBJECT_SEGMENT = 0x15, > > > +PRESENTATION_SEGMENT = 0x16, > > > +WINDOW_SEGMENT = 0x17, > > > +DISPLAY_SEGMENT = 0x80, > > > +}; > > > > This is duplicated in pgssubdec.c and pgs_frame_split_bsf.c. It's > > not > > much of code for a separate header, but maybe you'll find more >
Re: [FFmpeg-devel] [PATCH 1/3] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
On Fri, 2020-04-17 at 13:21 +0300, Petri Hintukainen wrote: > to, 2020-04-16 kello 16:57 -0600, John Stebbins kirjoitti: > > Required to remux m2ts to mkv > > --- > > libavcodec/Makefile | 1 + > > libavcodec/bitstream_filters.c | 1 + > > libavcodec/pgs_frame_merge_bsf.c | 164 > > +++ > > 3 files changed, 166 insertions(+) > > create mode 100644 libavcodec/pgs_frame_merge_bsf.c > > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > > index c1c9a44f2b..c7d8fbebaa 100644 > > --- a/libavcodec/Makefile > > +++ b/libavcodec/Makefile > > @@ -1110,6 +1110,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += > > mp3_header_decompress_bsf.o \ > > OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o > > OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o > > OBJS-$(CONFIG_NULL_BSF) += null_bsf.o > > +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o > > OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o > > OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += > > remove_extradata_bsf.o > > OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o > > diff --git a/libavcodec/bitstream_filters.c > > b/libavcodec/bitstream_filters.c > > index 6b5ffe4d70..92619225f0 100644 > > --- a/libavcodec/bitstream_filters.c > > +++ b/libavcodec/bitstream_filters.c > > @@ -49,6 +49,7 @@ extern const AVBitStreamFilter > > ff_mpeg4_unpack_bframes_bsf; > > extern const AVBitStreamFilter ff_mov2textsub_bsf; > > extern const AVBitStreamFilter ff_noise_bsf; > > extern const AVBitStreamFilter ff_null_bsf; > > +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; > > extern const AVBitStreamFilter ff_prores_metadata_bsf; > > extern const AVBitStreamFilter ff_remove_extradata_bsf; > > extern const AVBitStreamFilter ff_text2movsub_bsf; > > diff --git a/libavcodec/pgs_frame_merge_bsf.c > > b/libavcodec/pgs_frame_merge_bsf.c > > new file mode 100644 > > index 00..d1bb3a60c2 > > --- /dev/null > > +++ b/libavcodec/pgs_frame_merge_bsf.c > > @@ -0,0 +1,164 @@ > > +/* > > + * Copyright (c) 2020 John Stebbins > > + * > > + * This file is part of FFmpeg. > > + * > > + * FFmpeg is free software; you can redistribute it and/or > > + * modify it under the terms of the GNU Lesser General Public > > + * License as published by the Free Software Foundation; either > > + * version 2.1 of the License, or (at your option) any later > > version. > > + * > > + * FFmpeg is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > GNU > > + * Lesser General Public License for more details. > > + * > > + * You should have received a copy of the GNU Lesser General > > Public > > + * License along with FFmpeg; if not, write to the Free Software > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > > 02110-1301 USA > > + */ > > + > > +/** > > + * @file > > + * This bitstream filter merges PGS subtitle packets containing > > incomplete > > + * set of segments into a single packet > > + * > > + * Packets already containing a complete set of segments will be > > passed through > > + * unchanged. > > + */ > > + > > +#include "avcodec.h" > > +#include "bsf.h" > > +#include "libavutil/intreadwrite.h" > > + > > +enum PGSSegmentType { > > +PALETTE_SEGMENT = 0x14, > > +OBJECT_SEGMENT = 0x15, > > +PRESENTATION_SEGMENT = 0x16, > > +WINDOW_SEGMENT = 0x17, > > +DISPLAY_SEGMENT = 0x80, > > +}; > > This is duplicated in pgssubdec.c and pgs_frame_split_bsf.c. It's not > much of code for a separate header, but maybe you'll find more while > writing the encoder ? > I've already written the encoder. This enum is the only thing shared. So hardly seems worth adding a header. Testing the encoder is what lead me to writing the bsfs. It "works" in the sense that it's generating correct bitstreams. But I realized the bsfs were needed to handle muxing properly. And there is still the case to handle when the input AVSubtitle has end_display_time set. In this case I need to generate 2 segment sequences. One for the subtitle and one to indicate the end of the subtitle. The current subtitle encoder API doesn't handle multipe output packets f
Re: [FFmpeg-devel] [PATCH 1/3] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
On Thu, 2020-04-16 at 15:59 -0700, John Stebbins wrote: > On Thu, 2020-04-16 at 16:57 -0600, John Stebbins wrote: > > Required to remux m2ts to mkv > > --- > > libavcodec/Makefile | 1 + > > libavcodec/bitstream_filters.c | 1 + > > libavcodec/pgs_frame_merge_bsf.c | 164 > > +++ > > 3 files changed, 166 insertions(+) > > create mode 100644 libavcodec/pgs_frame_merge_bsf.c > > > > Ugh! I forgot the version bump. Will get on that... A question about this. I have 2 bsf submitted for review. Should I just do a separate patch that updates the minor version once. Or do you require it to be bumped with each change separately? > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > > index c1c9a44f2b..c7d8fbebaa 100644 > > --- a/libavcodec/Makefile > > +++ b/libavcodec/Makefile > > @@ -1110,6 +1110,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += > > mp3_header_decompress_bsf.o \ > > OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o > > OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o > > OBJS-$(CONFIG_NULL_BSF) += null_bsf.o > > +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o > > OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o > > OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += > > remove_extradata_bsf.o > > OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o > > diff --git a/libavcodec/bitstream_filters.c > > b/libavcodec/bitstream_filters.c > > index 6b5ffe4d70..92619225f0 100644 > > --- a/libavcodec/bitstream_filters.c > > +++ b/libavcodec/bitstream_filters.c > > @@ -49,6 +49,7 @@ extern const AVBitStreamFilter > > ff_mpeg4_unpack_bframes_bsf; > > extern const AVBitStreamFilter ff_mov2textsub_bsf; > > extern const AVBitStreamFilter ff_noise_bsf; > > extern const AVBitStreamFilter ff_null_bsf; > > +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; > > extern const AVBitStreamFilter ff_prores_metadata_bsf; > > extern const AVBitStreamFilter ff_remove_extradata_bsf; > > extern const AVBitStreamFilter ff_text2movsub_bsf; > > diff --git a/libavcodec/pgs_frame_merge_bsf.c > > b/libavcodec/pgs_frame_merge_bsf.c > > new file mode 100644 > > index 00..d1bb3a60c2 > > --- /dev/null > > +++ b/libavcodec/pgs_frame_merge_bsf.c > > @@ -0,0 +1,164 @@ > > +/* > > + * Copyright (c) 2020 John Stebbins > > + * > > + * This file is part of FFmpeg. > > + * > > + * FFmpeg is free software; you can redistribute it and/or > > + * modify it under the terms of the GNU Lesser General Public > > + * License as published by the Free Software Foundation; either > > + * version 2.1 of the License, or (at your option) any later > > version. > > + * > > + * FFmpeg is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > GNU > > + * Lesser General Public License for more details. > > + * > > + * You should have received a copy of the GNU Lesser General > > Public > > + * License along with FFmpeg; if not, write to the Free Software > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > > 02110-1301 USA > > + */ > > + > > +/** > > + * @file > > + * This bitstream filter merges PGS subtitle packets containing > > incomplete > > + * set of segments into a single packet > > + * > > + * Packets already containing a complete set of segments will be > > passed through > > + * unchanged. > > + */ > > + > > +#include "avcodec.h" > > +#include "bsf.h" > > +#include "libavutil/intreadwrite.h" > > + > > +enum PGSSegmentType { > > +PALETTE_SEGMENT = 0x14, > > +OBJECT_SEGMENT = 0x15, > > +PRESENTATION_SEGMENT = 0x16, > > +WINDOW_SEGMENT = 0x17, > > +DISPLAY_SEGMENT = 0x80, > > +}; > > + > > +typedef struct PGSMergeContext { > > +AVPacket *buffer_pkt, *in; > > +int presentation_found; > > +} PGSMergeContext; > > + > > +static void frame_merge_flush(AVBSFContext *bsf) > > +{ > > +PGSMergeContext *ctx = bsf->priv_data; > > + > > +av_packet_unref(ctx->in); > > +av_packet_unref(ctx->buffer_pkt); > > +} > > + > > +static int frame_merge_filter(AVBSFContext *bsf, AVPacket *out) > > +{ > > +PG
Re: [FFmpeg-devel] [PATCH 1/3] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
On Thu, 2020-04-16 at 16:57 -0600, John Stebbins wrote: > Required to remux m2ts to mkv > --- > libavcodec/Makefile | 1 + > libavcodec/bitstream_filters.c | 1 + > libavcodec/pgs_frame_merge_bsf.c | 164 > +++ > 3 files changed, 166 insertions(+) > create mode 100644 libavcodec/pgs_frame_merge_bsf.c > Ugh! I forgot the version bump. Will get on that... > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > index c1c9a44f2b..c7d8fbebaa 100644 > --- a/libavcodec/Makefile > +++ b/libavcodec/Makefile > @@ -1110,6 +1110,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += > mp3_header_decompress_bsf.o \ > OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o > OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o > OBJS-$(CONFIG_NULL_BSF) += null_bsf.o > +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o > OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o > OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o > OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o > diff --git a/libavcodec/bitstream_filters.c > b/libavcodec/bitstream_filters.c > index 6b5ffe4d70..92619225f0 100644 > --- a/libavcodec/bitstream_filters.c > +++ b/libavcodec/bitstream_filters.c > @@ -49,6 +49,7 @@ extern const AVBitStreamFilter > ff_mpeg4_unpack_bframes_bsf; > extern const AVBitStreamFilter ff_mov2textsub_bsf; > extern const AVBitStreamFilter ff_noise_bsf; > extern const AVBitStreamFilter ff_null_bsf; > +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; > extern const AVBitStreamFilter ff_prores_metadata_bsf; > extern const AVBitStreamFilter ff_remove_extradata_bsf; > extern const AVBitStreamFilter ff_text2movsub_bsf; > diff --git a/libavcodec/pgs_frame_merge_bsf.c > b/libavcodec/pgs_frame_merge_bsf.c > new file mode 100644 > index 00..d1bb3a60c2 > --- /dev/null > +++ b/libavcodec/pgs_frame_merge_bsf.c > @@ -0,0 +1,164 @@ > +/* > + * Copyright (c) 2020 John Stebbins > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later > version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > 02110-1301 USA > + */ > + > +/** > + * @file > + * This bitstream filter merges PGS subtitle packets containing > incomplete > + * set of segments into a single packet > + * > + * Packets already containing a complete set of segments will be > passed through > + * unchanged. > + */ > + > +#include "avcodec.h" > +#include "bsf.h" > +#include "libavutil/intreadwrite.h" > + > +enum PGSSegmentType { > +PALETTE_SEGMENT = 0x14, > +OBJECT_SEGMENT = 0x15, > +PRESENTATION_SEGMENT = 0x16, > +WINDOW_SEGMENT = 0x17, > +DISPLAY_SEGMENT = 0x80, > +}; > + > +typedef struct PGSMergeContext { > +AVPacket *buffer_pkt, *in; > +int presentation_found; > +} PGSMergeContext; > + > +static void frame_merge_flush(AVBSFContext *bsf) > +{ > +PGSMergeContext *ctx = bsf->priv_data; > + > +av_packet_unref(ctx->in); > +av_packet_unref(ctx->buffer_pkt); > +} > + > +static int frame_merge_filter(AVBSFContext *bsf, AVPacket *out) > +{ > +PGSMergeContext *ctx = bsf->priv_data; > +AVPacket *in = ctx->in, *pkt = ctx->buffer_pkt; > +int ret, i, size, pos, display = 0; > + > +if (!in->data) { > +ret = ff_bsf_get_packet_ref(bsf, in); > +if (ret < 0) > +return ret; > +} > +if (!in->size) { > +av_packet_unref(in); > +return AVERROR(EAGAIN); > +} > + > +// Validate packet data and find display_end segment > +size = in->size; > +i = 0; > +while (i + 3 <= in->size) { > +uint8_t segment_type; > +int segment_len; > + > +segment_type = in->data[i]; > +segment_len = AV_RB16(in->data + i + 1) + 3; > +if (i + segment_len > i
[FFmpeg-devel] [PATCH 1/3] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
Required to remux m2ts to mkv --- libavcodec/Makefile | 1 + libavcodec/bitstream_filters.c | 1 + libavcodec/pgs_frame_merge_bsf.c | 164 +++ 3 files changed, 166 insertions(+) create mode 100644 libavcodec/pgs_frame_merge_bsf.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index c1c9a44f2b..c7d8fbebaa 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1110,6 +1110,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += mp3_header_decompress_bsf.o \ OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o OBJS-$(CONFIG_NULL_BSF) += null_bsf.o +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index 6b5ffe4d70..92619225f0 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf; extern const AVBitStreamFilter ff_mov2textsub_bsf; extern const AVBitStreamFilter ff_noise_bsf; extern const AVBitStreamFilter ff_null_bsf; +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; extern const AVBitStreamFilter ff_prores_metadata_bsf; extern const AVBitStreamFilter ff_remove_extradata_bsf; extern const AVBitStreamFilter ff_text2movsub_bsf; diff --git a/libavcodec/pgs_frame_merge_bsf.c b/libavcodec/pgs_frame_merge_bsf.c new file mode 100644 index 00..d1bb3a60c2 --- /dev/null +++ b/libavcodec/pgs_frame_merge_bsf.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2020 John Stebbins + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * This bitstream filter merges PGS subtitle packets containing incomplete + * set of segments into a single packet + * + * Packets already containing a complete set of segments will be passed through + * unchanged. + */ + +#include "avcodec.h" +#include "bsf.h" +#include "libavutil/intreadwrite.h" + +enum PGSSegmentType { +PALETTE_SEGMENT = 0x14, +OBJECT_SEGMENT = 0x15, +PRESENTATION_SEGMENT = 0x16, +WINDOW_SEGMENT = 0x17, +DISPLAY_SEGMENT = 0x80, +}; + +typedef struct PGSMergeContext { +AVPacket *buffer_pkt, *in; +int presentation_found; +} PGSMergeContext; + +static void frame_merge_flush(AVBSFContext *bsf) +{ +PGSMergeContext *ctx = bsf->priv_data; + +av_packet_unref(ctx->in); +av_packet_unref(ctx->buffer_pkt); +} + +static int frame_merge_filter(AVBSFContext *bsf, AVPacket *out) +{ +PGSMergeContext *ctx = bsf->priv_data; +AVPacket *in = ctx->in, *pkt = ctx->buffer_pkt; +int ret, i, size, pos, display = 0; + +if (!in->data) { +ret = ff_bsf_get_packet_ref(bsf, in); +if (ret < 0) +return ret; +} +if (!in->size) { +av_packet_unref(in); +return AVERROR(EAGAIN); +} + +// Validate packet data and find display_end segment +size = in->size; +i = 0; +while (i + 3 <= in->size) { +uint8_t segment_type; +int segment_len; + +segment_type = in->data[i]; +segment_len = AV_RB16(in->data + i + 1) + 3; +if (i + segment_len > in->size) // Invalid data +break; +if (segment_type == PRESENTATION_SEGMENT && !ctx->presentation_found) { +int object_count; +ctx->presentation_found = 1; +ret = av_packet_copy_props(pkt, in); +if (ret < 0) +goto fail; +object_count = in->data[i + 13]; +pkt->flags = !!object_count * AV_PKT_FLAG_KEY; +} +i += segment_len; +if (segment_type == DISPLAY_SEGMENT) { +size = display = i; +break; +} +} +if (display && pkt->size == 0 && size == in->size) { // passthrough +av_packet_move_ref(out, in); +return 0; +} +
Re: [FFmpeg-devel] [PATCH 1/3] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
On Thu, 2020-04-16 at 22:39 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > Required to remux m2ts to mkv > > --- > > libavcodec/Makefile | 1 + > > libavcodec/bitstream_filters.c | 1 + > > libavcodec/pgs_frame_merge_bsf.c | 152 > > +++ > > Missing version bump. > > > 3 files changed, 154 insertions(+) > > create mode 100644 libavcodec/pgs_frame_merge_bsf.c > > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > > index c1c9a44f2b..13909faabf 100644 > > --- a/libavcodec/Makefile > > +++ b/libavcodec/Makefile > > @@ -1119,6 +1119,7 @@ OBJS-$(CONFIG_VP9_METADATA_BSF) += > > vp9_metadata_bsf.o > > OBJS-$(CONFIG_VP9_RAW_REORDER_BSF)+= vp9_raw_reorder_bsf.o > > OBJS-$(CONFIG_VP9_SUPERFRAME_BSF) += vp9_superframe_bsf.o > > OBJS-$(CONFIG_VP9_SUPERFRAME_SPLIT_BSF) += > > vp9_superframe_split_bsf.o > > +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o > > Not sorted alphabetically. Will do. I didn't notice they were sorted. > > > > # thread libraries > > OBJS-$(HAVE_LIBC_MSVCRT) += file_open.o > > diff --git a/libavcodec/bitstream_filters.c > > b/libavcodec/bitstream_filters.c > > index 6b5ffe4d70..138f6dd7ad 100644 > > --- a/libavcodec/bitstream_filters.c > > +++ b/libavcodec/bitstream_filters.c > > @@ -58,6 +58,7 @@ extern const AVBitStreamFilter > > ff_vp9_metadata_bsf; > > extern const AVBitStreamFilter ff_vp9_raw_reorder_bsf; > > extern const AVBitStreamFilter ff_vp9_superframe_bsf; > > extern const AVBitStreamFilter ff_vp9_superframe_split_bsf; > > +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; > > Not sorted alphabetically. ditto > > > > > #include "libavcodec/bsf_list.c" > > > > diff --git a/libavcodec/pgs_frame_merge_bsf.c > > b/libavcodec/pgs_frame_merge_bsf.c > > new file mode 100644 > > index 00..4b8061d4e1 > > --- /dev/null > > +++ b/libavcodec/pgs_frame_merge_bsf.c > > @@ -0,0 +1,152 @@ > > +/* > > + * Copyright (c) 2020 John Stebbins > > + * > > + * This file is part of FFmpeg. > > + * > > + * FFmpeg is free software; you can redistribute it and/or > > + * modify it under the terms of the GNU Lesser General Public > > + * License as published by the Free Software Foundation; either > > + * version 2.1 of the License, or (at your option) any later > > version. > > + * > > + * FFmpeg is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > GNU > > + * Lesser General Public License for more details. > > + * > > + * You should have received a copy of the GNU Lesser General > > Public > > + * License along with FFmpeg; if not, write to the Free Software > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA > > 02110-1301 USA > > + */ > > + > > +/** > > + * @file > > + * This bitstream filter merges PGS subtitle packets containing > > incomplete > > + * set of segments into a single packet > > + * > > + * Packets already containing a complete set of segments will be > > passed through > > + * unchanged. > > + */ > > + > > +#include "avcodec.h" > > +#include "bsf.h" > > +#include "libavutil/intreadwrite.h" > > + > > +enum PGSSegmentType { > > +PALETTE_SEGMENT = 0x14, > > +OBJECT_SEGMENT = 0x15, > > +PRESENTATION_SEGMENT = 0x16, > > +WINDOW_SEGMENT = 0x17, > > +DISPLAY_SEGMENT = 0x80, > > +}; > > + > > +typedef struct PGSMergeContext { > > +AVPacket *buffer_pkt, *in; > > +} PGSMergeContext; > > + > > +static void frame_merge_flush(AVBSFContext *bsf) > > +{ > > +PGSMergeContext *ctx = bsf->priv_data; > > + > > +av_packet_unref(ctx->in); > > +av_packet_unref(ctx->buffer_pkt); > > +} > > + > > +static int frame_merge_filter(AVBSFContext *bsf, AVPacket *out) > > +{ > > +PGSMergeContext *ctx = bsf->priv_data; > > +AVPacket *in = ctx->in, *pkt = ctx->buffer_pkt; > > +int ret, i, size, pos, display = 0; > > +uint8_t segment_type; > > +uint16_t segment_len; > > + > > +if (!in->data) { > > +ret = ff_bsf_get_packet_ref(bsf, in); > > +if
[FFmpeg-devel] [PATCH 3/3] lavc/pgs_frame_split_bsf: add bsf to split PGS segments
Requried to remux mkv to m2ts --- libavcodec/Makefile | 1 + libavcodec/bitstream_filters.c | 1 + libavcodec/pgs_frame_split_bsf.c | 176 +++ 3 files changed, 178 insertions(+) create mode 100644 libavcodec/pgs_frame_split_bsf.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 13909faabf..948aee0252 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1120,6 +1120,7 @@ OBJS-$(CONFIG_VP9_RAW_REORDER_BSF)+= vp9_raw_reorder_bsf.o OBJS-$(CONFIG_VP9_SUPERFRAME_BSF) += vp9_superframe_bsf.o OBJS-$(CONFIG_VP9_SUPERFRAME_SPLIT_BSF) += vp9_superframe_split_bsf.o OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o +OBJS-$(CONFIG_PGS_FRAME_SPLIT_BSF)+= pgs_frame_split_bsf.o # thread libraries OBJS-$(HAVE_LIBC_MSVCRT) += file_open.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index 138f6dd7ad..5422392e11 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -59,6 +59,7 @@ extern const AVBitStreamFilter ff_vp9_raw_reorder_bsf; extern const AVBitStreamFilter ff_vp9_superframe_bsf; extern const AVBitStreamFilter ff_vp9_superframe_split_bsf; extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; +extern const AVBitStreamFilter ff_pgs_frame_split_bsf; #include "libavcodec/bsf_list.c" diff --git a/libavcodec/pgs_frame_split_bsf.c b/libavcodec/pgs_frame_split_bsf.c new file mode 100644 index 00..c983f6acf5 --- /dev/null +++ b/libavcodec/pgs_frame_split_bsf.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2020 John Stebbins + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * This bitstream filter splits PGS subtitle packets into packets containing + * just one segment. + * + * Packets already containing only one segment will be passed through + * unchanged. + */ + +#include "avcodec.h" +#include "bsf.h" +#include "libavutil/intreadwrite.h" + +enum PGSSegmentType { +PALETTE_SEGMENT = 0x14, +OBJECT_SEGMENT = 0x15, +PRESENTATION_SEGMENT = 0x16, +WINDOW_SEGMENT = 0x17, +DISPLAY_SEGMENT = 0x80, +}; + +typedef struct PGSSplitContext { +AVPacket *in; +} PGSSplitContext; + +static int frame_split_filter(AVBSFContext *bsf, AVPacket *out) +{ +PGSSplitContext *ctx = bsf->priv_data; +AVPacket *in = ctx->in; +int i, ret; +uint8_t segment_type; +uint16_t segment_len; +int split = !!in->data; + +if (!in->data) { +ret = ff_bsf_get_packet_ref(bsf, in); +if (ret < 0) +return ret; +} +if (!in->size) { +av_packet_unref(in); +return AVERROR(EAGAIN); +} + +// Validate packet data +i = 0; +while (i < in->size) { +segment_type = in->data[i]; +segment_len = AV_RB16(in->data + i + 1) + 3; +i += segment_len; +} +if (i != in->size) { +av_log(bsf, AV_LOG_WARNING, "Failed to parse PGS segments.\n"); +av_packet_move_ref(out, in); +return 0; +} + +segment_type = in->data[0]; +segment_len = AV_RB16(in->data + 1) + 3; +if (split || segment_len < in->size) { // Split +int64_t ts_delta, dts; + +ret = av_packet_ref(out, in); +if (ret < 0) +goto fail; +out->size = segment_len; +in->data += segment_len; +in->size -= segment_len; + +// Update PTS/DTS, Stagger timestamps by 3ms +ts_delta = 270; // Assume 90khz tick if no time_base_in +if (bsf->time_base_in.num && bsf->time_base_in.den) +ts_delta = bsf->time_base_in.den / bsf->time_base_in.num / 333; +if (ts_delta == 0) +ts_delta = 1; + +// Compute DTS, it's the same for all packets that carry it +// Assuming input PTS/DTS come from original presentation_segment +if (in->dts <= in->pts - 2 * ts_delta && +in->dts != AV_NOPTS_VALUE) +dts = in->dts; +else if (in->pts != AV_NOPTS_VALUE) +dts = in->pts - 2 * ts_delta; + +
[FFmpeg-devel] [PATCH 1/3] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments
Required to remux m2ts to mkv --- libavcodec/Makefile | 1 + libavcodec/bitstream_filters.c | 1 + libavcodec/pgs_frame_merge_bsf.c | 152 +++ 3 files changed, 154 insertions(+) create mode 100644 libavcodec/pgs_frame_merge_bsf.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index c1c9a44f2b..13909faabf 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1119,6 +1119,7 @@ OBJS-$(CONFIG_VP9_METADATA_BSF) += vp9_metadata_bsf.o OBJS-$(CONFIG_VP9_RAW_REORDER_BSF)+= vp9_raw_reorder_bsf.o OBJS-$(CONFIG_VP9_SUPERFRAME_BSF) += vp9_superframe_bsf.o OBJS-$(CONFIG_VP9_SUPERFRAME_SPLIT_BSF) += vp9_superframe_split_bsf.o +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o # thread libraries OBJS-$(HAVE_LIBC_MSVCRT) += file_open.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index 6b5ffe4d70..138f6dd7ad 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -58,6 +58,7 @@ extern const AVBitStreamFilter ff_vp9_metadata_bsf; extern const AVBitStreamFilter ff_vp9_raw_reorder_bsf; extern const AVBitStreamFilter ff_vp9_superframe_bsf; extern const AVBitStreamFilter ff_vp9_superframe_split_bsf; +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf; #include "libavcodec/bsf_list.c" diff --git a/libavcodec/pgs_frame_merge_bsf.c b/libavcodec/pgs_frame_merge_bsf.c new file mode 100644 index 00..4b8061d4e1 --- /dev/null +++ b/libavcodec/pgs_frame_merge_bsf.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2020 John Stebbins + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * This bitstream filter merges PGS subtitle packets containing incomplete + * set of segments into a single packet + * + * Packets already containing a complete set of segments will be passed through + * unchanged. + */ + +#include "avcodec.h" +#include "bsf.h" +#include "libavutil/intreadwrite.h" + +enum PGSSegmentType { +PALETTE_SEGMENT = 0x14, +OBJECT_SEGMENT = 0x15, +PRESENTATION_SEGMENT = 0x16, +WINDOW_SEGMENT = 0x17, +DISPLAY_SEGMENT = 0x80, +}; + +typedef struct PGSMergeContext { +AVPacket *buffer_pkt, *in; +} PGSMergeContext; + +static void frame_merge_flush(AVBSFContext *bsf) +{ +PGSMergeContext *ctx = bsf->priv_data; + +av_packet_unref(ctx->in); +av_packet_unref(ctx->buffer_pkt); +} + +static int frame_merge_filter(AVBSFContext *bsf, AVPacket *out) +{ +PGSMergeContext *ctx = bsf->priv_data; +AVPacket *in = ctx->in, *pkt = ctx->buffer_pkt; +int ret, i, size, pos, display = 0; +uint8_t segment_type; +uint16_t segment_len; + +if (!in->data) { +ret = ff_bsf_get_packet_ref(bsf, in); +if (ret < 0) +return ret; +} +if (!in->size) { +av_packet_unref(in); +return AVERROR(EAGAIN); +} + +// Validate packet data and find display_end segment +size = in->size; +i = 0; +while (i < in->size) { +segment_type = in->data[i]; +segment_len = AV_RB16(in->data + i + 1) + 3; +if (segment_type == DISPLAY_SEGMENT) { +size = display = i + segment_len; +break; +} +if (segment_type == PRESENTATION_SEGMENT) { +av_packet_copy_props(pkt, in); +pkt->pts = in->pts; +pkt->dts = in->dts; +} +i += segment_len; +} +if ((!display && i != in->size) || size > in->size) { +av_log(ctx, AV_LOG_WARNING, "Failed to parse PGS segments.\n"); +// force output what we have +display = size = in->size;; +} + +pos = pkt->size; +ret = av_grow_packet(pkt, size); +if (ret < 0) +goto fail; +memcpy(pkt->data + pos, in->data, size); + +if (size == in->size) +av_packet_unref(in); +else { +in->data += size; +in->size -= size; +} + +if (display) { +av_packet_move_ref(out, pkt); +av_packet_copy_props(pkt, out); +return 0; +} +return AVE
[FFmpeg-devel] [PATCH 2/3] lavf/matroskaenc: add PGS merge to auto bsf list
PGS segments must be merged to one packet for muxing to mkv --- libavformat/matroskaenc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 060e8b7816..6d88fcd784 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2658,6 +2658,8 @@ static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL); } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) { ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL); +} else if (st->codecpar->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE) { +ret = ff_stream_add_bitstream_filter(st, "pgs_frame_merge", NULL); } return ret; -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 4/4] avformat/mpegtsenc: use the correct stream_types and write HDMV descriptors for m2ts
On Wed, 2020-04-15 at 23:44 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > On Fri, 2020-04-10 at 21:44 +0200, Marton Balint wrote: > > > Fixes ticket #2622. > > > > > > Signed-off-by: Marton Balint > > > --- > > > libavformat/mpegtsenc.c | 58 > > > - > > > 1 file changed, 57 insertions(+), 1 deletion(-) > > > > > > diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c > > > index add35aca89..b154675d60 100644 > > > --- a/libavformat/mpegtsenc.c > > > +++ b/libavformat/mpegtsenc.c > > > @@ -359,6 +359,54 @@ static int > > > get_dvb_stream_type(AVFormatContext > > > *s, AVStream *st) > > > return stream_type; > > > } > > > > > > +static int get_m2ts_stream_type(AVFormatContext *s, AVStream > > > *st) > > > +{ > > > +int stream_type; > > > + > > > +switch (st->codecpar->codec_id) { > > > +case AV_CODEC_ID_MPEG2VIDEO: > > > +stream_type = STREAM_TYPE_VIDEO_MPEG2; > > > +break; > > > +case AV_CODEC_ID_H264: > > > +stream_type = STREAM_TYPE_VIDEO_H264; > > > +break; > > > +case AV_CODEC_ID_VC1: > > > +stream_type = STREAM_TYPE_VIDEO_VC1; > > > +break; > > > +case AV_CODEC_ID_HEVC: > > > +stream_type = STREAM_TYPE_VIDEO_HEVC; > > > +break; > > > +case AV_CODEC_ID_PCM_BLURAY: > > > +stream_type = 0x80; > > > +break; > > > +case AV_CODEC_ID_AC3: > > > +stream_type = 0x81; > > > +break; > > > +case AV_CODEC_ID_DTS: > > > +stream_type = (st->codecpar->channels > 6) ? 0x85 : > > > 0x82; > > > +break; > > > +case AV_CODEC_ID_TRUEHD: > > > +stream_type = 0x83; > > > +break; > > > +case AV_CODEC_ID_EAC3: > > > +stream_type = 0x84; > > > +break; > > > +case AV_CODEC_ID_HDMV_PGS_SUBTITLE: > > > +stream_type = 0x90; > > > +break; > > > +case AV_CODEC_ID_HDMV_TEXT_SUBTITLE: > > > +stream_type = 0x92; > > > +break; > > > +default: > > > +av_log(s, AV_LOG_WARNING, "Stream %d, codec %s, is muxed > > > as > > > a private data stream " > > > + "and may not be recognized upon reading.\n", st- > > > > index, avcodec_get_name(st->codecpar->codec_id)); > > > +stream_type = STREAM_TYPE_PRIVATE_DATA; > > > +break; > > > +} > > > + > > > +return stream_type; > > > +} > > > + > > > static int mpegts_write_pmt(AVFormatContext *s, MpegTSService > > > *service) > > > { > > > MpegTSWrite *ts = s->priv_data; > > > @@ -372,6 +420,14 @@ static int mpegts_write_pmt(AVFormatContext > > > *s, > > > MpegTSService *service) > > > q += 2; /* patched after */ > > > > > > /* put program info here */ > > > +if (ts->m2ts_mode) { > > > +put_registration_descriptor(&q, MKTAG('H', 'D', 'M', > > > 'V')); > > > +*q++ = 0x88;// descriptor_tag - > > > hdmv_copy_control_descriptor > > > +*q++ = 0x04;// descriptor_length > > > +put16(&q, 0x0fff); // CA_System_ID > > > +*q++ = 0xfc;// private_data_byte > > > +*q++ = 0xfc;// private_data_byte > > > +} > > > > > > val = 0xf000 | (q - program_info_length_ptr - 2); > > > program_info_length_ptr[0] = val >> 8; > > > @@ -401,7 +457,7 @@ static int mpegts_write_pmt(AVFormatContext > > > *s, > > > MpegTSService *service) > > > break; > > > } > > > > > > -stream_type = get_dvb_stream_type(s, st); > > > +stream_type = ts->m2ts_mode ? get_m2ts_stream_type(s, > > > st) : > > > get_dvb_stream_type(s, st); > > > > > > *q++ = stream_type; > > > put16(&q, 0xe000 | ts_st->pid); > > > > I just wanted to comment on PGS subtitles. PGS in Matroska have > > all > > segments combined in one packet. m2ts requires each
Re: [FFmpeg-devel] [PATCH 4/4] avformat/mpegtsenc: use the correct stream_types and write HDMV descriptors for m2ts
On Fri, 2020-04-10 at 21:44 +0200, Marton Balint wrote: > Fixes ticket #2622. > > Signed-off-by: Marton Balint > --- > libavformat/mpegtsenc.c | 58 > - > 1 file changed, 57 insertions(+), 1 deletion(-) > > diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c > index add35aca89..b154675d60 100644 > --- a/libavformat/mpegtsenc.c > +++ b/libavformat/mpegtsenc.c > @@ -359,6 +359,54 @@ static int get_dvb_stream_type(AVFormatContext > *s, AVStream *st) > return stream_type; > } > > +static int get_m2ts_stream_type(AVFormatContext *s, AVStream *st) > +{ > +int stream_type; > + > +switch (st->codecpar->codec_id) { > +case AV_CODEC_ID_MPEG2VIDEO: > +stream_type = STREAM_TYPE_VIDEO_MPEG2; > +break; > +case AV_CODEC_ID_H264: > +stream_type = STREAM_TYPE_VIDEO_H264; > +break; > +case AV_CODEC_ID_VC1: > +stream_type = STREAM_TYPE_VIDEO_VC1; > +break; > +case AV_CODEC_ID_HEVC: > +stream_type = STREAM_TYPE_VIDEO_HEVC; > +break; > +case AV_CODEC_ID_PCM_BLURAY: > +stream_type = 0x80; > +break; > +case AV_CODEC_ID_AC3: > +stream_type = 0x81; > +break; > +case AV_CODEC_ID_DTS: > +stream_type = (st->codecpar->channels > 6) ? 0x85 : 0x82; > +break; > +case AV_CODEC_ID_TRUEHD: > +stream_type = 0x83; > +break; > +case AV_CODEC_ID_EAC3: > +stream_type = 0x84; > +break; > +case AV_CODEC_ID_HDMV_PGS_SUBTITLE: > +stream_type = 0x90; > +break; > +case AV_CODEC_ID_HDMV_TEXT_SUBTITLE: > +stream_type = 0x92; > +break; > +default: > +av_log(s, AV_LOG_WARNING, "Stream %d, codec %s, is muxed as > a private data stream " > + "and may not be recognized upon reading.\n", st- > >index, avcodec_get_name(st->codecpar->codec_id)); > +stream_type = STREAM_TYPE_PRIVATE_DATA; > +break; > +} > + > +return stream_type; > +} > + > static int mpegts_write_pmt(AVFormatContext *s, MpegTSService > *service) > { > MpegTSWrite *ts = s->priv_data; > @@ -372,6 +420,14 @@ static int mpegts_write_pmt(AVFormatContext *s, > MpegTSService *service) > q += 2; /* patched after */ > > /* put program info here */ > +if (ts->m2ts_mode) { > +put_registration_descriptor(&q, MKTAG('H', 'D', 'M', 'V')); > +*q++ = 0x88;// descriptor_tag - > hdmv_copy_control_descriptor > +*q++ = 0x04;// descriptor_length > +put16(&q, 0x0fff); // CA_System_ID > +*q++ = 0xfc;// private_data_byte > +*q++ = 0xfc;// private_data_byte > +} > > val = 0xf000 | (q - program_info_length_ptr - 2); > program_info_length_ptr[0] = val >> 8; > @@ -401,7 +457,7 @@ static int mpegts_write_pmt(AVFormatContext *s, > MpegTSService *service) > break; > } > > -stream_type = get_dvb_stream_type(s, st); > +stream_type = ts->m2ts_mode ? get_m2ts_stream_type(s, st) : > get_dvb_stream_type(s, st); > > *q++ = stream_type; > put16(&q, 0xe000 | ts_st->pid); I just wanted to comment on PGS subtitles. PGS in Matroska have all segments combined in one packet. m2ts requires each segment in it's own packet. So remuxing PGS from Matroska to m2ts will not work correctly without the addition of a bsf to split segments. I just happen to be starting testing of just such a bsf (I also wrote a merge bsf to go the other way). I hacked in some of you're patch to do a smoke test converting back and forth between m2ts and Matroska. Split bsf emits multiple packets for each input packet and merge consumes multiple packets for each input packet. So I also had to do significant surgery on the auto bsf code in mux.c After cleaning up the patches and doing some additional testing, I'll be submitting these bsf. I also have a PGS encoder working. But, like dvbsub, it may need to emit 2 packets for 1 input subtitle. What's being done for dvbsub in ffmpeg.c to work around this is ugly and I'd like to propose something like avcodec_send_frame/avcodec_receive_packet interface for subtitles to clean this up. Would anyone object to an avcodec_send_subtitle and just extend avcodec_receive_packet to handle subtitles? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [FFmpeg-devel, v2] dvbsub.c, change segment order to be in line with spec
On Tue, 2020-04-14 at 10:29 +0200, Paul B Mahol wrote: > On 4/14/20, Alen Vrečko wrote: > > Hello, everyone. > > > > Looks like this patch got forgotten. I'd very much like to see it > > applied. > > > > In our testing. This patch doesn't break any existing players. But > > it does > > allow for older STBs to play subtitles. > > > > If you don't like the patch, feel free to change the order > > yourself. The > > current dvb structure order in dvbsub.c is not in line with ETSI EN > > 300 743 > > (any version). > > > > Spec order: display definition segment > page composition segment > > > region > > composition segment > CLUT > > Your order: display definition segment > page composition segment > > > *CLUT* > > > region composition segment > > Is specification freely available? > > > I can answer that since I've been poking around in that code lately... https://www.etsi.org/deliver/etsi_en/300700_300799/300743/01.03.01_60/en_300743v010301p.pdf The relevant information is in section 4.3 Within a display set the sequence of segments (when present) is: •display definition segment; •page composition; •region composition; •CLUT definition; •object data; •end of display set segment. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] Subtitle encoder return codes
On Fri, 2020-04-10 at 14:12 -0700, Philip Langdale wrote: > On Fri, 10 Apr 2020 13:02:16 -0600 > John Stebbins wrote: > > > Patch set makes return codes from subtitle encoders more meaningful > > and consistent. Also fixes output buffer size checking where > > needed. > > > > After this, a user of a subtitle encoder can attempt to encode > > again > > with a larger buffer if the encoder returns > > AVERROR_BUFFER_TOO_SMALL > > > > The changes look good. Can you send me a branch for these? > > Here it is https://github.com/jstebbins/FFmpeg/tree/sub-enc-rets ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] movtext decode/encode improvements
On Fri, 2020-04-10 at 09:50 -0700, Philip Langdale wrote: > On Thu, 9 Apr 2020 23:28:49 + > John Stebbins wrote: > > > > Essentially yes. We've had our own mov text encoder and decoder in > > HandBrake for years. I added support for using ffmpeg for decoding > > subtitles last year but the movtext decoder wasn't up to the same > > level as ours, so we weren't using ffmpeg for that yet. I'm > > following > > up that work from last year to add subtitle encoding with ffmpeg > > and > > dropping our decoder and encoder for mov text. > > That's great - and I really appreciate you taking the extra effort to > feed this back! Of course, I can't help but be greedy: Have you > looked > at subtitle positioning? I think that's the biggest functional gap > left. > > > I'm also almost finished writing a PGS subtitle encoder for ffmpeg > > ;) > > Very nice! > Subtitle positioning is on my todo list. But it wasn't supported in HandBrake's mov text encoder, so I didn't need to add it for feature parity. I've got a bunch of subtitle TODOs for both HandBrake and ffmpeg. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 7/7] lavc/xsubenc: return meaningfull error codes
--- libavcodec/xsubenc.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/xsubenc.c b/libavcodec/xsubenc.c index b3da909679..4d58e0f3b5 100644 --- a/libavcodec/xsubenc.c +++ b/libavcodec/xsubenc.c @@ -63,7 +63,7 @@ static int xsub_encode_rle(PutBitContext *pb, const uint8_t *bitmap, while (x0 < w) { // Make sure we have enough room for at least one run and padding if (pb->size_in_bits - put_bits_count(pb) < 7*8) -return -1; +return AVERROR_BUFFER_TOO_SMALL; x1 = x0; color = bitmap[x1++] & 3; @@ -124,7 +124,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, if (bufsize < 27 + 7*2 + 4*3) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for XSUB header.\n"); -return -1; +return AVERROR_BUFFER_TOO_SMALL; } // TODO: support multiple rects @@ -147,7 +147,7 @@ FF_ENABLE_DEPRECATION_WARNINGS // TODO: render text-based subtitles into bitmaps if (!h->rects[0]->data[0] || !h->rects[0]->data[1]) { av_log(avctx, AV_LOG_WARNING, "No subtitle bitmap available.\n"); -return -1; +return AVERROR(EINVAL); } // TODO: color reduction, similar to dvdsub encoder @@ -160,7 +160,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (make_tc(startTime, start_tc) || make_tc(endTime, end_tc)) { av_log(avctx, AV_LOG_WARNING, "Time code >= 100 hours.\n"); -return -1; +return AVERROR(EINVAL); } snprintf(buf, 28, @@ -195,13 +195,13 @@ FF_ENABLE_DEPRECATION_WARNINGS if (xsub_encode_rle(&pb, h->rects[0]->data[0], h->rects[0]->linesize[0] * 2, h->rects[0]->w, (h->rects[0]->h + 1) >> 1)) -return -1; +return AVERROR_BUFFER_TOO_SMALL; bytestream_put_le16(&rlelenptr, put_bits_count(&pb) >> 3); // Length of first field if (xsub_encode_rle(&pb, h->rects[0]->data[0] + h->rects[0]->linesize[0], h->rects[0]->linesize[0] * 2, h->rects[0]->w, h->rects[0]->h >> 1)) -return -1; +return AVERROR_BUFFER_TOO_SMALL; // Enforce total height to be a multiple of 2 if (h->rects[0]->h & 1) { -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 6/7] lavc/webvttenc: return more meaningful error codes
--- libavcodec/webvttenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c index c84bbf4b4e..febf6ee370 100644 --- a/libavcodec/webvttenc.c +++ b/libavcodec/webvttenc.c @@ -168,7 +168,7 @@ static int webvtt_encode_frame(AVCodecContext *avctx, if (sub->rects[i]->type != SUBTITLE_ASS) { av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n"); -return AVERROR(ENOSYS); +return AVERROR(EINVAL); } #if FF_API_ASS_TIMING @@ -200,7 +200,7 @@ static int webvtt_encode_frame(AVCodecContext *avctx, if (s->buffer.len > bufsize) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); -return -1; +return AVERROR_BUFFER_TOO_SMALL; } memcpy(buf, s->buffer.str, s->buffer.len); -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 4/7] lavc/movtextenc: return more meaningful error codes
--- libavcodec/movtextenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index d8dbc546aa..b2368b641b 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -693,7 +693,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, if (sub->rects[i]->type != SUBTITLE_ASS) { av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n"); -return AVERROR(ENOSYS); +return AVERROR(EINVAL); } #if FF_API_ASS_TIMING @@ -736,7 +736,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, if (s->buffer.len > bufsize - 3) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); -length = AVERROR(EINVAL); +length = AVERROR_BUFFER_TOO_SMALL; goto exit; } -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/7] lavc/dvbsub: return meaningful error codes
--- libavcodec/dvbsub.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/dvbsub.c b/libavcodec/dvbsub.c index a0be0b1056..5c081f2b71 100644 --- a/libavcodec/dvbsub.c +++ b/libavcodec/dvbsub.c @@ -282,7 +282,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, page_id = 1; if (h->num_rects && !h->rects) -return -1; +return AVERROR(EINVAL); if (avctx->width > 0 && avctx->height > 0) { if (buf_size < 11) @@ -341,7 +341,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, /* 8 bpp, standard encoding */ bpp_index = 2; } else { -return -1; +return AVERROR(EINVAL); } @@ -393,7 +393,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, /* 8 bpp, standard encoding */ bpp_index = 2; } else { -return -1; +return AVERROR(EINVAL); } *q++ = 0x0f; /* sync_byte */ @@ -441,7 +441,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, /* 8 bpp, standard encoding */ dvb_encode_rle = dvb_encode_rle8; } else { -return -1; +return AVERROR(EINVAL); } /* Object Data segment */ -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 5/7] lavc/srtenc: return more meaninful error codes
--- libavcodec/srtenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/srtenc.c b/libavcodec/srtenc.c index 34f0f0d5e6..655b65679e 100644 --- a/libavcodec/srtenc.c +++ b/libavcodec/srtenc.c @@ -241,7 +241,7 @@ static int encode_frame(AVCodecContext *avctx, if (sub->rects[i]->type != SUBTITLE_ASS) { av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n"); -return AVERROR(ENOSYS); +return AVERROR(EINVAL); } #if FF_API_ASS_TIMING @@ -276,7 +276,7 @@ static int encode_frame(AVCodecContext *avctx, if (s->buffer.len > bufsize) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); -return -1; +return AVERROR_BUFFER_TOO_SMALL; } memcpy(buf, s->buffer.str, s->buffer.len); -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/7] lavc/assenc: return more meaningful error code
When the buffer is too small, return AVERROR_BUFFER_TOO_SMALL --- libavcodec/assenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c index e54c1d8ec3..a6e1d5d8b9 100644 --- a/libavcodec/assenc.c +++ b/libavcodec/assenc.c @@ -93,7 +93,7 @@ static int ass_encode_frame(AVCodecContext *avctx, if (len > bufsize-total_len-1) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); -return AVERROR(EINVAL); +return AVERROR_BUFFER_TOO_SMALL; } total_len += len; -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/7] lavc/dvbsub: fix potential encode buffer overflow
encode buffer size was ignored --- libavcodec/dvbsub.c | 97 +++-- 1 file changed, 75 insertions(+), 22 deletions(-) diff --git a/libavcodec/dvbsub.c b/libavcodec/dvbsub.c index a8d43d81d6..a0be0b1056 100644 --- a/libavcodec/dvbsub.c +++ b/libavcodec/dvbsub.c @@ -37,11 +37,11 @@ typedef struct DVBSubtitleContext { }\ } -static void dvb_encode_rle2(uint8_t **pq, -const uint8_t *bitmap, int linesize, -int w, int h) +static int dvb_encode_rle2(uint8_t **pq, int buf_size, + const uint8_t *bitmap, int linesize, + int w, int h) { -uint8_t *q; +uint8_t *q, *line_begin; unsigned int bitbuf; int bitcnt; int x, y, len, x1, v, color; @@ -49,6 +49,10 @@ static void dvb_encode_rle2(uint8_t **pq, q = *pq; for(y = 0; y < h; y++) { +// Worst case line is 3 bits per value + 4 bytes overhead +if (buf_size * 8 < w * 3 + 32) +return AVERROR_BUFFER_TOO_SMALL; +line_begin = q; *q++ = 0x10; bitbuf = 0; bitcnt = 6; @@ -109,8 +113,11 @@ static void dvb_encode_rle2(uint8_t **pq, } *q++ = 0xf0; bitmap += linesize; +buf_size -= q - line_begin; } +len = q - *pq; *pq = q; +return len; } #define PUTBITS4(val)\ @@ -125,11 +132,11 @@ static void dvb_encode_rle2(uint8_t **pq, } /* some DVB decoders only implement 4 bits/pixel */ -static void dvb_encode_rle4(uint8_t **pq, -const uint8_t *bitmap, int linesize, -int w, int h) +static int dvb_encode_rle4(uint8_t **pq, int buf_size, + const uint8_t *bitmap, int linesize, + int w, int h) { -uint8_t *q; +uint8_t *q, *line_begin; unsigned int bitbuf; int bitcnt; int x, y, len, x1, v, color; @@ -137,6 +144,10 @@ static void dvb_encode_rle4(uint8_t **pq, q = *pq; for(y = 0; y < h; y++) { +// Worst case line is 6 bits per value, + 4 bytes overhead +if (buf_size * 8 < w * 6 + 32) +return AVERROR_BUFFER_TOO_SMALL; +line_begin = q; *q++ = 0x11; bitbuf = 0; bitcnt = 4; @@ -189,20 +200,27 @@ static void dvb_encode_rle4(uint8_t **pq, } *q++ = 0xf0; bitmap += linesize; +buf_size -= q - line_begin; } +len = q - *pq; *pq = q; +return len; } -static void dvb_encode_rle8(uint8_t **pq, -const uint8_t *bitmap, int linesize, -int w, int h) +static int dvb_encode_rle8(uint8_t **pq, int buf_size, + const uint8_t *bitmap, int linesize, + int w, int h) { -uint8_t *q; +uint8_t *q, *line_begin; int x, y, len, x1, color; q = *pq; for (y = 0; y < h; y++) { +// Worst case line is 12 bits per value, + 3 bytes overhead +if (buf_size * 8 < w * 12 + 24) +return AVERROR_BUFFER_TOO_SMALL; +line_begin = q; *q++ = 0x12; x = 0; @@ -243,12 +261,16 @@ static void dvb_encode_rle8(uint8_t **pq, *q++ = 0x00; *q++ = 0xf0; bitmap += linesize; +buf_size -= q - line_begin; } +len = q - *pq; *pq = q; +return len; } static int encode_dvb_subtitles(AVCodecContext *avctx, -uint8_t *outbuf, const AVSubtitle *h) +uint8_t *outbuf, int buf_size, +const AVSubtitle *h) { DVBSubtitleContext *s = avctx->priv_data; uint8_t *q, *pseg_len; @@ -263,6 +285,8 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, return -1; if (avctx->width > 0 && avctx->height > 0) { +if (buf_size < 11) +return AVERROR_BUFFER_TOO_SMALL; /* display definition segment */ *q++ = 0x0f; /* sync_byte */ *q++ = 0x14; /* segment_type */ @@ -273,10 +297,13 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, bytestream_put_be16(&q, avctx->width - 1); /* display width */ bytestream_put_be16(&q, avctx->height - 1); /* display height */ bytestream_put_be16(&pseg_len, q - pseg_len - 2); +buf_size -= 11; } /* page composition segment */ +if (buf_size < 8 + h->num_rects * 6) +return AVERROR_BUFFER_TOO_SMALL; *q++ = 0x0f; /* sync_byte */ *q++ = 0x10; /* segment_type */ bytestream_put_be16(&q, page_id); @@ -295,9 +322,12 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, } bytestream_put_be16(&pseg_len, q - pseg_len - 2); +buf_size -= 8 + h->num_rects * 6; if (h->num_rects) { for (clut_id = 0; clut_id < h->num_rects; clut_id++) { +if (buf_size < 6 + h->rects[clut_id]->nb_colors
[FFmpeg-devel] Subtitle encoder return codes
Patch set makes return codes from subtitle encoders more meaningful and consistent. Also fixes output buffer size checking where needed. After this, a user of a subtitle encoder can attempt to encode again with a larger buffer if the encoder returns AVERROR_BUFFER_TOO_SMALL ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] libavformat/mov: restore use of mfra time as dts
On Thu, 2020-04-09 at 10:56 +0530, Gyan Doshi wrote: > > On 06-04-2020 11:12 pm, John Stebbins wrote: > > This was inadvertantly removed in 4a9d32baca > > --- > > libavformat/mov.c | 5 + > > 1 file changed, 5 insertions(+) > > > > diff --git a/libavformat/mov.c b/libavformat/mov.c > > index 16a40debc7..eee98fb69c 100644 > > --- a/libavformat/mov.c > > +++ b/libavformat/mov.c > > @@ -4813,6 +4813,11 @@ static int mov_read_trun(MOVContext *c, > > AVIOContext *pb, MOVAtom atom) > > pts = frag_stream_info->first_tfra_pts; > > av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64 > > ", using it for pts\n", pts); > > +} else if (frag_stream_info->first_tfra_pts != > > AV_NOPTS_VALUE && > > +c->use_mfra_for == FF_MOV_FLAG_MFRA_DTS) { > > +dts = frag_stream_info->first_tfra_pts; > > +av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64 > > +", using it for dts\n", pts); > > } else if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE) > > { > > // FIXME: sidx earliest_presentation_time is *PTS*, > > s.b. > > // pts = frag_stream_info->sidx_pts; > > LGTM. > > Gyan > Thanks for the review. I've got a couple other patch submissions that fix problems that resulted from 4a9d32baca which have received no comments in nearly 2 weeks. I don't have commit access, so if no comments means OK, can someone please commit? https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200329203245.225679-1-jstebb...@jetheaddev.com/ https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200329212738.226876-1-jstebb...@jetheaddev.com/ ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] movtext decode/encode improvements
On Thu, 2020-04-09 at 14:00 -0700, Philip Langdale wrote: > On Thu, 9 Apr 2020 19:30:53 + > John Stebbins wrote: > > Pushed to https://github.com/jstebbins/FFmpeg/commits/movtext > > > > There's one additional patch on the top implementing what we > > discussed > > about highlight alpha updates. Should I send that to the ml as > > well? > > > > The new one looks good too, so I will merge it along with the others. > > Thanks for all of this work! It's a big set of improvements for the > movtext handling! I'm guessing the motivation was to be able to > switch > Handbrake to using these instead of some other library? > > Essentially yes. We've had our own mov text encoder and decoder in HandBrake for years. I added support for using ffmpeg for decoding subtitles last year but the movtext decoder wasn't up to the same level as ours, so we weren't using ffmpeg for that yet. I'm following up that work from last year to add subtitle encoding with ffmpeg and dropping our decoder and encoder for mov text. I'm also almost finished writing a PGS subtitle encoder for ffmpeg ;) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] movtext decode/encode improvements
On Thu, 2020-04-09 at 11:17 -0700, Philip Langdale wrote: > On Thu, 9 Apr 2020 15:51:23 + > John Stebbins wrote: > > > On Wed, 2020-04-08 at 12:24 -0700, Philip Langdale wrote: > > > On Tue, 7 Apr 2020 14:38:52 + > > > John Stebbins wrote: > > > > > > > After checking carefully, patches 10 and 23 are as I want them. > > > > Sizes > > > > are relative to 288 when using override APIs, but are relative > > > > to > > > > PlayResY when processing the script. > > > > > > > > On the other hand, patch 20 needs a fix. If the cancel > > > > overrides > > > > does > > > > not specify a style, it *should* restore the ASS style of the > > > > current > > > > dialog, but instead it is returning to the mp4 default style. > > > > > > Thanks. I've gone through them all, and I've only had a few minor > > > comments. Will you need me to push these once they are finalised? > > > > > > > > > > Thanks to you as well. > > > > Yes, when we're all finished with reviews please commit. I don't > > have > > commit access. I have a few comments by you to resolve (patches 18 > > and 22) and one by Nicolas regarding indentation in patch 1. > > > > If I have to change the indentation in patch 1, it'll percolate > > through a few other patches that touch the same code. So I'll have > > to resend those, or I can just fix the indentation as a final patch > > on top? > > > > Looks like the indentation change is localised so shouldn't have a > big > effect. > > Can you push a branch to your github when you are ready - it'll be a > lot easier for me to manage than grabbing these from email. > > Thanks, > > Pushed to https://github.com/jstebbins/FFmpeg/commits/movtext There's one additional patch on the top implementing what we discussed about highlight alpha updates. Should I send that to the ml as well? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 01/23] lavc/movtextdec: fix ass header colors
On Thu, 2020-04-09 at 09:43 -0700, Philip Langdale wrote: > On Thu, 9 Apr 2020 15:09:45 + > John Stebbins wrote: > > > > > > > > I missed this review earlier. What about the indentation is > > off? Do > > you mean the indent of the function parameters does not align after > > the opening paren? I was keeping the lines aligned without > > wrapping > > at 80 characters. > > Yes, I believe he's referring to the function parameters and not the > overall indent. I would normally align to the paren. I think you can > do > that and keep under 80 if you put each one on its own line? > > The lines get longer in a subsequent patch (7) and do not fit without wrapping. So I would just have to undo the indent in that patch ;) I could conceivable break lines at expression operators instead of commas, but I think that would make reading more difficult. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 18/23] lavc/movtextenc: add alpha tag handling
On Thu, 2020-04-09 at 08:23 -0700, John Stebbins wrote: > On Wed, 2020-04-08 at 11:37 -0700, Philip Langdale wrote: > > On Mon, 6 Apr 2020 11:52:13 -0600 > > John Stebbins wrote: > > > > > --- > > > libavcodec/movtextenc.c | 25 - > > > 1 file changed, 24 insertions(+), 1 deletion(-) > > > > > > diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c > > > index 090536b887..e82393dde7 100644 > > > --- a/libavcodec/movtextenc.c > > > +++ b/libavcodec/movtextenc.c > > > @@ -351,6 +351,26 @@ static void mov_text_color_cb(void *priv, > > > unsigned int color, unsigned int color */ > > > } > > > > > > +static void mov_text_alpha_set(MovTextContext *s, uint8_t alpha) > > > +{ > > > +if (!s->style_attributes_temp || > > > +(s->style_attributes_temp->style_color & 0xff) == alpha) > > > { > > > +// color hasn't changed > > > +return; > > > +} > > > +if (mov_text_style_start(s)) > > > +s->style_attributes_temp->style_color = > > > +(s->style_attributes_temp->style_color & > > > 0xff00) > > > > alpha; +} > > > + > > > +static void mov_text_alpha_cb(void *priv, int alpha, int > > > alpha_id) > > > +{ > > > +MovTextContext *s = priv; > > > + > > > +if (alpha_id == 1) // primary alpha changes > > > +mov_text_alpha_set(s, 255 - alpha); > > > +} > > > > Worth a comment that secondary alpha can't be preserved? > > Sure, will do. Taking a second look at this, I'm wondering if alpha_id = 2 should be applied to the highlight color that is set in mov_text_color_cb? And if so, should a highlight box be started if only the alpha is changed and not the color? And if so, should the highlight color default to the current primary color when only alpha changes? I'm not familiar with how mov text highlight works and what it looks like in practice. Do you have an opinion? If I add the above, I'll do that as a separate new patch, along with the comment below. There should still be a comment here (and probably for color as well) that outline and background colors can not be modified in mov text. > > > > + > > > static void mov_text_end_cb(void *priv) > > > { > > > // End of text, close any open style record > > > @@ -360,7 +380,7 @@ static void mov_text_end_cb(void *priv) > > > static void mov_text_dialog(MovTextContext *s, ASSDialog > > > *dialog) > > > { > > > ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog- > > > > style); > > > -uint8_tstyle_flags; > > > +uint8_tstyle_flags, alpha; > > > uint32_t color; > > > > > > if (style) { > > > @@ -370,6 +390,8 @@ static void mov_text_dialog(MovTextContext > > > *s, > > > ASSDialog *dialog) mov_text_style_set(s, style_flags); > > > color = BGR_TO_RGB(style->primary_color & 0xff) << > > > 8; > > > mov_text_color_set(s, color); > > > +alpha = 255 - ((uint32_t)style->primary_color >> 24); > > > +mov_text_alpha_set(s, alpha); > > > } > > > } > > > > > > @@ -416,6 +438,7 @@ static const ASSCodesCallbacks > > > mov_text_callbacks > > > = { .new_line = mov_text_new_line_cb, > > > .style= mov_text_style_cb, > > > .color= mov_text_color_cb, > > > +.alpha= mov_text_alpha_cb, > > > .end = mov_text_end_cb, > > > }; > > > > > > > Otherwise LGTM. > > > > > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] movtext decode/encode improvements
On Wed, 2020-04-08 at 12:24 -0700, Philip Langdale wrote: > On Tue, 7 Apr 2020 14:38:52 + > John Stebbins wrote: > > > After checking carefully, patches 10 and 23 are as I want them. > > Sizes > > are relative to 288 when using override APIs, but are relative to > > PlayResY when processing the script. > > > > On the other hand, patch 20 needs a fix. If the cancel overrides > > does > > not specify a style, it *should* restore the ASS style of the > > current > > dialog, but instead it is returning to the mp4 default style. > > Thanks. I've gone through them all, and I've only had a few minor > comments. Will you need me to push these once they are finalised? > > Thanks to you as well. Yes, when we're all finished with reviews please commit. I don't have commit access. I have a few comments by you to resolve (patches 18 and 22) and one by Nicolas regarding indentation in patch 1. If I have to change the indentation in patch 1, it'll percolate through a few other patches that touch the same code. So I'll have to resend those, or I can just fix the indentation as a final patch on top? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 18/23] lavc/movtextenc: add alpha tag handling
On Wed, 2020-04-08 at 11:37 -0700, Philip Langdale wrote: > On Mon, 6 Apr 2020 11:52:13 -0600 > John Stebbins wrote: > > > --- > > libavcodec/movtextenc.c | 25 - > > 1 file changed, 24 insertions(+), 1 deletion(-) > > > > diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c > > index 090536b887..e82393dde7 100644 > > --- a/libavcodec/movtextenc.c > > +++ b/libavcodec/movtextenc.c > > @@ -351,6 +351,26 @@ static void mov_text_color_cb(void *priv, > > unsigned int color, unsigned int color */ > > } > > > > +static void mov_text_alpha_set(MovTextContext *s, uint8_t alpha) > > +{ > > +if (!s->style_attributes_temp || > > +(s->style_attributes_temp->style_color & 0xff) == alpha) { > > +// color hasn't changed > > +return; > > +} > > +if (mov_text_style_start(s)) > > +s->style_attributes_temp->style_color = > > +(s->style_attributes_temp->style_color & > > 0xff00) > > > alpha; +} > > + > > +static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id) > > +{ > > +MovTextContext *s = priv; > > + > > +if (alpha_id == 1) // primary alpha changes > > +mov_text_alpha_set(s, 255 - alpha); > > +} > > Worth a comment that secondary alpha can't be preserved? Sure, will do. > > > + > > static void mov_text_end_cb(void *priv) > > { > > // End of text, close any open style record > > @@ -360,7 +380,7 @@ static void mov_text_end_cb(void *priv) > > static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) > > { > > ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog- > > >style); > > -uint8_tstyle_flags; > > +uint8_tstyle_flags, alpha; > > uint32_t color; > > > > if (style) { > > @@ -370,6 +390,8 @@ static void mov_text_dialog(MovTextContext *s, > > ASSDialog *dialog) mov_text_style_set(s, style_flags); > > color = BGR_TO_RGB(style->primary_color & 0xff) << 8; > > mov_text_color_set(s, color); > > +alpha = 255 - ((uint32_t)style->primary_color >> 24); > > +mov_text_alpha_set(s, alpha); > > } > > } > > > > @@ -416,6 +438,7 @@ static const ASSCodesCallbacks > > mov_text_callbacks > > = { .new_line = mov_text_new_line_cb, > > .style= mov_text_style_cb, > > .color= mov_text_color_cb, > > +.alpha= mov_text_alpha_cb, > > .end = mov_text_end_cb, > > }; > > > > Otherwise LGTM. > > > > --phil > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 22/23] lavc/movtextenc: add font name handling
On Wed, 2020-04-08 at 12:23 -0700, Philip Langdale wrote: > On Mon, 6 Apr 2020 11:52:17 -0600 > John Stebbins wrote: > > > Initializes the mov text sample description from the ASS header and > > creates an mov font table from the fonts available in the ASS > > Styles. > > --- > > libavcodec/ass_split.c | 5 + > > libavcodec/ass_split.h | 8 ++ > > libavcodec/movtextenc.c | 253 > > 3 files changed, 216 > > insertions(+), 50 deletions(-) > > > > diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c > > index 94c32667af..9d5a66f931 100644 > > --- a/libavcodec/ass_split.c > > +++ b/libavcodec/ass_split.c > > @@ -599,3 +599,8 @@ ASSStyle *ff_ass_style_get(ASSSplitContext > > *ctx, > > const char *style) return ass->styles + i; > > return NULL; > > } > > + > > +ASS *ff_ass_get(ASSSplitContext *ctx) > > +{ > > +return &ctx->ass; > > +} > > diff --git a/libavcodec/ass_split.h b/libavcodec/ass_split.h > > index 30ce77250c..31b8e53242 100644 > > --- a/libavcodec/ass_split.h > > +++ b/libavcodec/ass_split.h > > @@ -204,4 +204,12 @@ int ff_ass_split_override_codes(const > > ASSCodesCallbacks *callbacks, void *priv, */ > > ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char > > *style); > > > > +/** > > + * Get ASS structure > > + * > > + * @param ctx Context previously initialized by ff_ass_split(). > > + * @return the ASS > > + */ > > +ASS *ff_ass_get(ASSSplitContext *ctx); > > Is this necesssary? The header says: You are correct, I missed that comment. I'll fix it. Kind of a sneaky "API". > > /** > * This struct can be casted to ASS to access to the split data. > */ > typedef struct ASSSplitContext ASSSplitContext; > > So can't you just cast the context you already have? > > > + > > #endif /* AVCODEC_ASS_SPLIT_H */ > > diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c > > index 167dffee6a..a62bdb7eb0 100644 > > --- a/libavcodec/movtextenc.c > > +++ b/libavcodec/movtextenc.c > > @@ -79,6 +79,8 @@ typedef struct { > > StyleBox d; > > uint16_t text_pos; > > uint16_t byte_count; > > +char ** fonts; > > +int font_count; > > } MovTextContext; > > > > typedef struct { > > @@ -171,69 +173,198 @@ static const Box box_types[] = { > > > > const static size_t box_count = FF_ARRAY_ELEMS(box_types); > > > > -static av_cold int mov_text_encode_init(AVCodecContext *avctx) > > +static int mov_text_encode_close(AVCodecContext *avctx) > > { > > -/* > > - * For now, we'll use a fixed default style. When we add > > styling > > - * support, this will be generated from the ASS style. > > - */ > > -static const uint8_t text_sample_entry[] = { > > +MovTextContext *s = avctx->priv_data; > > +int i; > > + > > +ff_ass_split_free(s->ass_ctx); > > +if (s->style_attributes) { > > +for (i = 0; i < s->count; i++) { > > +av_freep(&s->style_attributes[i]); > > +} > > +av_freep(&s->style_attributes); > > +} > > +av_freep(&s->fonts); > > +av_freep(&s->style_attributes_temp); > > +av_bprint_finalize(&s->buffer, NULL); > > +return 0; > > +} > > + > > +static int encode_sample_description(AVCodecContext *avctx) > > +{ > > +ASS * ass; > > +ASSStyle * style; > > +int i, j; > > +uint32_t tsmb_size, tsmb_type, back_color, style_color; > > +uint16_t style_start, style_end, fontID, count; > > +int font_names_total_len = 0; > > +MovTextContext *s = avctx->priv_data; > > + > > +static const uint8_t display_and_justification[] = { > > 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags > > 0x01, // int8_t horizontal-justification > > 0xFF, // int8_t vertical-justification > > -0x00, 0x00, 0x00, 0x00, // uint8_t background-color- > > rgba[4] > > -// BoxRecord { > > +}; > > +// 0x00, 0x00, 0x00, 0x00, // uint8_t background-color- > > rgba[4] > > Is this right? Should it be un-commented or removed entirely? Well, I was leaving that in as a comment showing the structure of the sample description. But if it's confusing, I can just remove all those comments. There are sever
Re: [FFmpeg-devel] [PATCH 01/23] lavc/movtextdec: fix ass header colors
On Mon, 2020-04-06 at 20:03 +0200, Nicolas George wrote: > John Stebbins (12020-04-06): > > A conversion from rgb to bgr is necessary > > --- > > libavcodec/movtextdec.c | 11 +++ > > 1 file changed, 7 insertions(+), 4 deletions(-) > > > > diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c > > index c38c5edce6..05becaf64d 100644 > > --- a/libavcodec/movtextdec.c > > +++ b/libavcodec/movtextdec.c > > @@ -48,6 +48,8 @@ > > #define TOP_CENTER 8 > > #define TOP_RIGHT 9 > > > > +#define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) > > >> 16) & 0xff)) > > + > > typedef struct { > > char *font; > > int fontsize; > > @@ -448,10 +450,11 @@ static int mov_text_init(AVCodecContext > > *avctx) { > > MovTextContext *m = avctx->priv_data; > > ret = mov_text_tx3g(avctx, m); > > if (ret == 0) { > > -return ff_ass_subtitle_header(avctx, m->d.font, m- > > >d.fontsize, m->d.color, > > -m->d.back_color, m->d.bold, m- > > >d.italic, > > -m->d.underline, > > ASS_DEFAULT_BORDERSTYLE, > > -m->d.alignment); > > +return ff_ass_subtitle_header(avctx, m->d.font, m- > > >d.fontsize, > > +RGB_TO_BGR(m->d.color), > > +RGB_TO_BGR(m->d.back_color), > > +m->d.bold, m->d.italic, m->d.underline, > > +ASS_DEFAULT_BORDERSTYLE, m->d.alignment); > > Indentation is off. It was off before, but since the lines are > changed > it should be ok now. > > Can't judge on semantic. > > > } else > > return ff_ass_subtitle_header_default(avctx); > > } > > I missed this review earlier. What about the indentation is off? Do you mean the indent of the function parameters does not align after the opening paren? I was keeping the lines aligned without wrapping at 80 characters. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 10/23] lavc/movtextdec: allow setting subtitle frame dimensions
On Wed, 2020-04-08 at 10:31 -0700, Philip Langdale wrote: > On Mon, 6 Apr 2020 11:52:05 -0600 > John Stebbins wrote: > > > Font sizes are relative to the subtitle frame dimensions. If the > > expected frame dimensions are not known, the font sizes will most > > likely be incorrect. > > --- > > libavcodec/ass.c| 30 +++--- > > libavcodec/ass.h| 28 > > libavcodec/movtextdec.c | 30 +- > > 3 files changed, 80 insertions(+), 8 deletions(-) > > > > diff --git a/libavcodec/ass.c b/libavcodec/ass.c > > index a51673fb4e..7c26e3fd6d 100644 > > --- a/libavcodec/ass.c > > +++ b/libavcodec/ass.c > > @@ -26,11 +26,13 @@ > > #include "libavutil/bprint.h" > > #include "libavutil/common.h" > > > > -int ff_ass_subtitle_header(AVCodecContext *avctx, > > - const char *font, int font_size, > > - int color, int back_color, > > - int bold, int italic, int underline, > > - int border_style, int alignment) > > +int ff_ass_subtitle_header_full(AVCodecContext *avctx, > > +int play_res_x, int play_res_y, > > +const char *font, int font_size, > > +int primary_color, int > > secondary_color, > > +int outline_color, int back_color, > > +int bold, int italic, int > > underline, > > +int border_style, int alignment) > > { > > avctx->subtitle_header = av_asprintf( > > "[Script Info]\r\n" > > @@ -67,8 +69,8 @@ int ff_ass_subtitle_header(AVCodecContext *avctx, > > "[Events]\r\n" > > "Format: Layer, Start, End, Style, Name, MarginL, > > MarginR, MarginV, Effect, Text\r\n", !(avctx->flags & > > AV_CODEC_FLAG_BITEXACT) ? AV_STRINGIFY(LIBAVCODEC_VERSION) : "", > > - ASS_DEFAULT_PLAYRESX, ASS_DEFAULT_PLAYRESY, > > - font, font_size, color, color, back_color, > > back_color, > > + play_res_x, play_res_y, font, font_size, > > + primary_color, secondary_color, outline_color, > > back_color, -bold, -italic, -underline, border_style, alignment); > > > > if (!avctx->subtitle_header) > > @@ -77,6 +79,20 @@ int ff_ass_subtitle_header(AVCodecContext > > *avctx, > > return 0; > > } > > > > +int ff_ass_subtitle_header(AVCodecContext *avctx, > > + const char *font, int font_size, > > + int color, int back_color, > > + int bold, int italic, int underline, > > + int border_style, int alignment) > > +{ > > +return ff_ass_subtitle_header_full(avctx, > > + ASS_DEFAULT_PLAYRESX, > > ASS_DEFAULT_PLAYRESY, > > + font, font_size, color, color, > > + back_color, back_color, > > + bold, italic, underline, > > + border_style, alignment); > > +} > > + > > int ff_ass_subtitle_header_default(AVCodecContext *avctx) > > { > > return ff_ass_subtitle_header(avctx, ASS_DEFAULT_FONT, > > diff --git a/libavcodec/ass.h b/libavcodec/ass.h > > index 314b43b686..2c260e4e78 100644 > > --- a/libavcodec/ass.h > > +++ b/libavcodec/ass.h > > @@ -47,6 +47,34 @@ typedef struct FFASSDecoderContext { > > int readorder; > > } FFASSDecoderContext; > > > > +/** > > + * Generate a suitable AVCodecContext.subtitle_header for > > SUBTITLE_ASS. > > + * Can specify all fields explicitly > > + * > > + * @param avctx pointer to the AVCodecContext > > + * @param play_res_x subtitle frame width > > + * @param play_res_y subtitle frame height > > + * @param font name of the default font face to use > > + * @param font_size default font size to use > > + * @param primary_color default text color to use (ABGR) > > + * @param secondary_color default secondary text color to use > > (ABGR) > > + * @param outline_color default outline color to use (ABGR) > > + * @param back_color default background color to use (ABGR) > > + * @param bold 1 for bold text, 0 for normal text > > + * @param
[FFmpeg-devel] [PATCH 20/23] lavc/movtextenc: handle cancel overrides callback
--- libavcodec/movtextenc.c | 43 - 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 9e657c9635..2d3c416407 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -69,6 +69,7 @@ typedef struct { AVCodecContext *avctx; ASSSplitContext *ass_ctx; +ASSStyle *ass_dialog_style; AVBPrint buffer; StyleBox **style_attributes; StyleBox *style_attributes_temp; @@ -396,9 +397,8 @@ static void mov_text_end_cb(void *priv) mov_text_style_start((MovTextContext*)priv); } -static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) +static void mov_text_ass_style_set(MovTextContext *s, ASSStyle *style) { -ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); uint8_tstyle_flags, alpha; uint32_t color; @@ -412,9 +412,33 @@ static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) alpha = 255 - ((uint32_t)style->primary_color >> 24); mov_text_alpha_set(s, alpha); mov_text_font_size_set(s, style->font_size); +} else { +// End current style record, go back to defaults +mov_text_style_start(s); } } +static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) +{ +ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); + +s->ass_dialog_style = style; +mov_text_ass_style_set(s, style); +} + +static void mov_text_cancel_overrides_cb(void *priv, const char * style_name) +{ +MovTextContext *s = priv; +ASSStyle * style; + +if (!style_name || !*style_name) +style = s->ass_dialog_style; +else +style= ff_ass_style_get(s->ass_ctx, style_name); + +mov_text_ass_style_set(s, style); +} + static uint16_t utf8_strlen(const char *text, int len) { uint16_t i = 0, ret = 0; @@ -454,13 +478,14 @@ static void mov_text_new_line_cb(void *priv, int forced) } static const ASSCodesCallbacks mov_text_callbacks = { -.text = mov_text_text_cb, -.new_line = mov_text_new_line_cb, -.style = mov_text_style_cb, -.color = mov_text_color_cb, -.alpha = mov_text_alpha_cb, -.font_size = mov_text_font_size_cb, -.end = mov_text_end_cb, +.text = mov_text_text_cb, +.new_line = mov_text_new_line_cb, +.style= mov_text_style_cb, +.color= mov_text_color_cb, +.alpha= mov_text_alpha_cb, +.font_size= mov_text_font_size_cb, +.cancel_overrides = mov_text_cancel_overrides_cb, +.end = mov_text_end_cb, }; static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, -- 2.25.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] movtext decode/encode improvements
On Mon, 2020-04-06 at 15:03 -0700, John Stebbins wrote: > On Mon, 2020-04-06 at 13:16 -0700, Philip Langdale wrote: > > On Mon, 6 Apr 2020 11:51:55 -0600 > > John Stebbins wrote: > > > > > Patch series adds more complete decoding and encoding of color, > > > alpha, > > > font size, font name, and style tags for movtext. It also fixes > > > a > > > number of bugs. > > > > > > > Hi John, > > > > Thanks for doing all of this! I'll try and take a look at these > > over > > the next few days. > > > > > > > > Thanks. A heads up though. I need to have a second look at patches > 10 > and 23 relating to frame sizes and font sizes. I've been reading > libass code to get a deeper understanding of how it manages font > sizes > and I think I've done that wrong. > > ass font size is relative to a fixed 288 pixel height (I assumed it > was > relative to PlayResY in the script). And mov text font size is > relative to the specified subtitle track height which should be the > same as the video height. After checking carefully, patches 10 and 23 are as I want them. Sizes are relative to 288 when using override APIs, but are relative to PlayResY when processing the script. On the other hand, patch 20 needs a fix. If the cancel overrides does not specify a style, it *should* restore the ASS style of the current dialog, but instead it is returning to the mp4 default style. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 02/23] lavc/movtextdec: simplify style record walk
On Mon, 2020-04-06 at 14:46 -0700, Philip Langdale wrote: > On Mon, 6 Apr 2020 11:51:57 -0600 > John Stebbins wrote: > > > It's not necessary to walk the style record list twice per subtitle > > character. style records are in order and do not overlap. > > --- > > libavcodec/movtextdec.c | 38 - > > - > > 1 file changed, 20 insertions(+), 18 deletions(-) > > > > diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c > > index 05becaf64d..47a8401119 100644 > > --- a/libavcodec/movtextdec.c > > +++ b/libavcodec/movtextdec.c > > @@ -355,8 +355,9 @@ static int text_to_ass(AVBPrint *buf, const > > char > > *text, const char *text_end, { > > MovTextContext *m = avctx->priv_data; > > int i = 0; > > -int j = 0; > > int text_pos = 0; > > +int style_active = 0; > > +int entry = 0; > > > > if (text < text_end && m->box_flags & TWRP_BOX) { > > if (m->w.wrap_flag == 1) { > > @@ -369,26 +370,27 @@ static int text_to_ass(AVBPrint *buf, const > > char *text, const char *text_end, while (text < text_end) { > > int len; > > > > -if (m->box_flags & STYL_BOX) { > > -for (i = 0; i < m->style_entries; i++) { > > -if (m->s[i]->style_flag && text_pos == > > m->s[i]->style_end) { > > -av_bprintf(buf, "{\\r}"); > > +if ((m->box_flags & STYL_BOX) && entry < m->style_entries) > > { > > +if (text_pos == m->s[entry]->style_start) { > > +style_active = 1; > > +if (m->s[entry]->style_flag & STYLE_FLAG_BOLD) > > +av_bprintf(buf, "{\\b1}"); > > +if (m->s[entry]->style_flag & STYLE_FLAG_ITALIC) > > +av_bprintf(buf, "{\\i1}"); > > +if (m->s[entry]->style_flag & > > STYLE_FLAG_UNDERLINE) > > +av_bprintf(buf, "{\\u1}"); > > +av_bprintf(buf, "{\\fs%d}", m->s[entry]- > > >fontsize); > > +for (i = 0; i < m->ftab_entries; i++) { > > +if (m->s[entry]->style_fontID == > > m->ftab[i]->fontID) > > +av_bprintf(buf, "{\\fn%s}", > > m->ftab[i]->font); } > > } > > -for (i = 0; i < m->style_entries; i++) { > > -if (m->s[i]->style_flag && text_pos == > > m->s[i]->style_start) { > > -if (m->s[i]->style_flag & STYLE_FLAG_BOLD) > > -av_bprintf(buf, "{\\b1}"); > > -if (m->s[i]->style_flag & STYLE_FLAG_ITALIC) > > -av_bprintf(buf, "{\\i1}"); > > -if (m->s[i]->style_flag & > > STYLE_FLAG_UNDERLINE) > > -av_bprintf(buf, "{\\u1}"); > > -av_bprintf(buf, "{\\fs%d}", m->s[i]- > > >fontsize); > > -for (j = 0; j < m->ftab_entries; j++) { > > -if (m->s[i]->style_fontID == > > m->ftab[j]->fontID) > > -av_bprintf(buf, "{\\fn%s}", > > m->ftab[j]->font); > > -} > > +if (text_pos == m->s[entry]->style_end) { > > +if (style_active) { > > +av_bprintf(buf, "{\\r}"); > > +style_active = 0; > > } > > +entry++; > > } > > } > > if (m->box_flags & HLIT_BOX) { > > OK. I could not convince myself originally that styles could not > overlap, but I could easily have missed that in the spec. > I went back and double checked this in the spec before changing the code. "The styles shall be ordered by starting character offset, and the starting offset of one style record shall be greater than or equal to the ending character offset of the preceding record; styles records shall not overlap their character ranges." ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] movtext decode/encode improvements
On Mon, 2020-04-06 at 13:16 -0700, Philip Langdale wrote: > On Mon, 6 Apr 2020 11:51:55 -0600 > John Stebbins wrote: > > > Patch series adds more complete decoding and encoding of color, > > alpha, > > font size, font name, and style tags for movtext. It also fixes a > > number of bugs. > > > > Hi John, > > Thanks for doing all of this! I'll try and take a look at these over > the next few days. > > > Thanks. A heads up though. I need to have a second look at patches 10 and 23 relating to frame sizes and font sizes. I've been reading libass code to get a deeper understanding of how it manages font sizes and I think I've done that wrong. ass font size is relative to a fixed 288 pixel height (I assumed it was relative to PlayResY in the script). And mov text font size is relative to the specified subtitle track height which should be the same as the video height. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 11/23] lavc/ass_split: fix parsing utf8 scripts
The [Script Info] section was skipped if starts with UTF8 BOM --- libavcodec/ass_split.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c index 67da7c6d84..c2c388d9f0 100644 --- a/libavcodec/ass_split.c +++ b/libavcodec/ass_split.c @@ -376,6 +376,8 @@ ASSSplitContext *ff_ass_split(const char *buf) ASSSplitContext *ctx = av_mallocz(sizeof(*ctx)); if (!ctx) return NULL; +if (buf && !memcmp(buf, "\xef\xbb\xbf", 3)) // Skip UTF-8 BOM header +buf += 3; ctx->current_section = -1; if (ass_split(ctx, buf) < 0) { ff_ass_split_free(ctx); -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 11/23] lavc/ass_split: fix parsing utf8 scripts
On Mon, 2020-04-06 at 20:08 +0200, Nicolas George wrote: > John Stebbins (12020-04-06): > > The [Script Info] section was skipped if starts with UTF8 BOM > > --- > > libavcodec/ass_split.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c > > index 67da7c6d84..94c32667af 100644 > > --- a/libavcodec/ass_split.c > > +++ b/libavcodec/ass_split.c > > @@ -354,6 +354,9 @@ static int ass_split(ASSSplitContext *ctx, > > const char *buf) > > if (ctx->current_section >= 0) > > buf = ass_split_section(ctx, buf); > > > > +if(!memcmp(buf, "\xef\xbb\xbf", 3)) { // Skip UTF-8 BOM header > > +buf += 3; > > +} > > This doesn't look correct: BOM should be skipped only at the very > beginning of the file. And the braces could be skipped. > > > while (buf && *buf) { > > if (sscanf(buf, "[%15[0-9A-Za-z+ ]]%c", section, &c) == 2) > > { > > buf += strcspn(buf, "\n"); > > Oh, whoops, I missed that ass_split gets called for a number of things. This belongs at the beginning of ff_ass_split() I believe? In the sample I ran into this with, there's a BOM at the beginning of the mkv private data for the track. I'll remove the braces... ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 22/23] lavc/movtextenc: add font name handling
Initializes the mov text sample description from the ASS header and creates an mov font table from the fonts available in the ASS Styles. --- libavcodec/ass_split.c | 5 + libavcodec/ass_split.h | 8 ++ libavcodec/movtextenc.c | 253 3 files changed, 216 insertions(+), 50 deletions(-) diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c index 94c32667af..9d5a66f931 100644 --- a/libavcodec/ass_split.c +++ b/libavcodec/ass_split.c @@ -599,3 +599,8 @@ ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char *style) return ass->styles + i; return NULL; } + +ASS *ff_ass_get(ASSSplitContext *ctx) +{ +return &ctx->ass; +} diff --git a/libavcodec/ass_split.h b/libavcodec/ass_split.h index 30ce77250c..31b8e53242 100644 --- a/libavcodec/ass_split.h +++ b/libavcodec/ass_split.h @@ -204,4 +204,12 @@ int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, */ ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char *style); +/** + * Get ASS structure + * + * @param ctx Context previously initialized by ff_ass_split(). + * @return the ASS + */ +ASS *ff_ass_get(ASSSplitContext *ctx); + #endif /* AVCODEC_ASS_SPLIT_H */ diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 167dffee6a..a62bdb7eb0 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -79,6 +79,8 @@ typedef struct { StyleBox d; uint16_t text_pos; uint16_t byte_count; +char ** fonts; +int font_count; } MovTextContext; typedef struct { @@ -171,69 +173,198 @@ static const Box box_types[] = { const static size_t box_count = FF_ARRAY_ELEMS(box_types); -static av_cold int mov_text_encode_init(AVCodecContext *avctx) +static int mov_text_encode_close(AVCodecContext *avctx) { -/* - * For now, we'll use a fixed default style. When we add styling - * support, this will be generated from the ASS style. - */ -static const uint8_t text_sample_entry[] = { +MovTextContext *s = avctx->priv_data; +int i; + +ff_ass_split_free(s->ass_ctx); +if (s->style_attributes) { +for (i = 0; i < s->count; i++) { +av_freep(&s->style_attributes[i]); +} +av_freep(&s->style_attributes); +} +av_freep(&s->fonts); +av_freep(&s->style_attributes_temp); +av_bprint_finalize(&s->buffer, NULL); +return 0; +} + +static int encode_sample_description(AVCodecContext *avctx) +{ +ASS * ass; +ASSStyle * style; +int i, j; +uint32_t tsmb_size, tsmb_type, back_color, style_color; +uint16_t style_start, style_end, fontID, count; +int font_names_total_len = 0; +MovTextContext *s = avctx->priv_data; + +static const uint8_t display_and_justification[] = { 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags 0x01, // int8_t horizontal-justification 0xFF, // int8_t vertical-justification -0x00, 0x00, 0x00, 0x00, // uint8_t background-color-rgba[4] -// BoxRecord { +}; +// 0x00, 0x00, 0x00, 0x00, // uint8_t background-color-rgba[4] +static const uint8_t box_record[] = { +// BoxRecord { 0x00, 0x00, // int16_t top 0x00, 0x00, // int16_t left 0x00, 0x00, // int16_t bottom 0x00, 0x00, // int16_t right -// }; -// StyleRecord { -0x00, 0x00, // uint16_t startChar -0x00, 0x00, // uint16_t endChar -0x00, 0x01, // uint16_t font-ID -0x00, // uint8_t face-style-flags -0x12, // uint8_t font-size -0xFF, 0xFF, 0xFF, 0xFF, // uint8_t text-color-rgba[4] -// }; -// FontTableBox { -0x00, 0x00, 0x00, 0x12, // uint32_t size -'f', 't', 'a', 'b', // uint8_t name[4] -0x00, 0x01, // uint16_t entry-count -// FontRecord { -0x00, 0x01, // uint16_t font-ID -0x05, // uint8_t font-name-length -'S', 'e', 'r', 'i', 'f',// uint8_t font[font-name-length] -// }; -// }; +// }; }; +// StyleRecord { +// 0x00, 0x00, // uint16_t startChar +// 0x00, 0x00, // uint16_t endChar +// 0x00, 0x01, // uint16_t font-ID +// 0x00, // uint8_t face-style-flags +// 0x12, // uint8_t font-size +// 0xFF, 0xFF, 0xFF, 0xFF, // uint8_t text-color-rgba[4] +// }; +// FontTableBox { +// 0x00, 0x00, 0x00, 0x12, // uint32_t size +// 'f', 't', 'a', 'b', // uint8_t name[4] +// 0x00, 0x01, // uint16_t entry-count +// FontRecord { +// 0x00, 0x01, // uint16_t font-ID +// 0x05, // uint8_t font-name-length +// 'S', 'e', 'r', 'i', 'f'
[FFmpeg-devel] [PATCH 23/23] lavc/movtextenc: add option to scale fontsize with height
If the video dimensions are different than the ASS play_res then the font sizes need to be adjusted to get the same apparent render size. --- libavcodec/movtextenc.c | 30 +- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index a62bdb7eb0..3d4371b180 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -21,6 +21,7 @@ #include #include "avcodec.h" +#include "libavutil/opt.h" #include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" @@ -45,6 +46,7 @@ #define DEFAULT_STYLE_FLAG 0x00 #define BGR_TO_RGB(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) +#define FONTSIZE_SCALE(s,fs) ((fs) * (s)->font_scale_factor + 0.5) #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) typedef struct { @@ -66,6 +68,7 @@ typedef struct { } HilightcolorBox; typedef struct { +AVClass *class; AVCodecContext *avctx; ASSSplitContext *ass_ctx; @@ -81,6 +84,8 @@ typedef struct { uint16_t byte_count; char ** fonts; int font_count; +double font_scale_factor; +int frame_height; } MovTextContext; typedef struct { @@ -236,6 +241,13 @@ static int encode_sample_description(AVCodecContext *avctx) // Populate sample description from ASS header ass = ff_ass_get(s->ass_ctx); +// Compute font scaling factor based on (optionally) provided +// output video height and ASS script play_res_y +if (s->frame_height && ass->script_info.play_res_y) +s->font_scale_factor = (double)s->frame_height / ass->script_info.play_res_y; +else +s->font_scale_factor = 1; + style = ff_ass_style_get(s->ass_ctx, "Default"); if (!style && ass->styles_count) { style = &ass->styles[0]; @@ -245,7 +257,7 @@ static int encode_sample_description(AVCodecContext *avctx) s->d.style_color= DEFAULT_STYLE_COLOR; s->d.style_flag = DEFAULT_STYLE_FLAG; if (style) { -s->d.style_fontsize = style->font_size; +s->d.style_fontsize = FONTSIZE_SCALE(s, style->font_size); s->d.style_color = BGR_TO_RGB(style->primary_color & 0xff) << 8 | 255 - ((uint32_t)style->primary_color >> 24); s->d.style_flag = (!!style->bold * STYLE_FLAG_BOLD) | @@ -530,6 +542,7 @@ static void mov_text_font_name_cb(void *priv, const char *name) static void mov_text_font_size_set(MovTextContext *s, int size) { +size = FONTSIZE_SCALE(s, size); if (!s->style_attributes_temp || s->style_attributes_temp->style_fontsize == size) { // color hasn't changed @@ -709,12 +722,27 @@ exit: return length; } +#define OFFSET(x) offsetof(MovTextContext, x) +#define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM +static const AVOption options[] = { +{ "height", "Frame height, usually video height", OFFSET(frame_height), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, +{ NULL }, +}; + +static const AVClass mov_text_encoder_class = { +.class_name = "MOV text enoder", +.item_name = av_default_item_name, +.option = options, +.version= LIBAVUTIL_VERSION_INT, +}; + AVCodec ff_movtext_encoder = { .name = "mov_text", .long_name = NULL_IF_CONFIG_SMALL("3GPP Timed Text subtitle"), .type = AVMEDIA_TYPE_SUBTITLE, .id = AV_CODEC_ID_MOV_TEXT, .priv_data_size = sizeof(MovTextContext), +.priv_class = &mov_text_encoder_class, .init = mov_text_encode_init, .encode_sub = mov_text_encode_frame, .close = mov_text_encode_close, -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 21/23] lavc/movtextenc: simplify initialization of new style record
--- libavcodec/movtextenc.c | 13 - 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 2e65489c4d..167dffee6a 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -96,8 +96,7 @@ static void mov_text_cleanup(MovTextContext *s) av_freep(&s->style_attributes); } if (s->style_attributes_temp) { -s->style_attributes_temp->style_flag = 0; -s->style_attributes_temp->style_start = 0; +*s->style_attributes_temp = s->d; } } @@ -122,7 +121,7 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) style_start = AV_RB16(&s->style_attributes[j]->style_start); style_end= AV_RB16(&s->style_attributes[j]->style_end); style_color = AV_RB32(&s->style_attributes[j]->style_color); -style_fontID = AV_RB16(&s->d.style_fontID); +style_fontID = AV_RB16(&s->style_attributes[j]->style_fontID); av_bprint_append_any(&s->buffer, &style_start, 2); av_bprint_append_any(&s->buffer, &style_end, 2); @@ -259,14 +258,10 @@ static int mov_text_style_start(MovTextContext *s) return 0; } -s->style_attributes_temp->style_flag = s->style_attributes[s->count - 1]->style_flag; -s->style_attributes_temp->style_color = s->style_attributes[s->count - 1]->style_color; -s->style_attributes_temp->style_fontsize = s->style_attributes[s->count - 1]->style_fontsize; +*s->style_attributes_temp = s->d; s->style_attributes_temp->style_start = s->text_pos; } else { // style entry matches defaults, drop entry -s->style_attributes_temp->style_flag = s->d.style_flag; -s->style_attributes_temp->style_color = s->d.style_color; -s->style_attributes_temp->style_fontsize = s->d.style_fontsize; +*s->style_attributes_temp = s->d; s->style_attributes_temp->style_start = s->text_pos; } return 1; -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 20/23] lavc/movtextenc: handle cancel overrides callback
--- libavcodec/movtextenc.c | 36 +++- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 9e657c9635..2e65489c4d 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -396,9 +396,8 @@ static void mov_text_end_cb(void *priv) mov_text_style_start((MovTextContext*)priv); } -static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) +static void mov_text_ass_style_set(MovTextContext *s, ASSStyle *style) { -ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); uint8_tstyle_flags, alpha; uint32_t color; @@ -412,9 +411,27 @@ static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) alpha = 255 - ((uint32_t)style->primary_color >> 24); mov_text_alpha_set(s, alpha); mov_text_font_size_set(s, style->font_size); +} else { +// End current style record, go back to defaults +mov_text_style_start(s); } } +static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) +{ +ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); + +mov_text_ass_style_set(s, style); +} + +static void mov_text_cancel_overrides_cb(void *priv, const char * style_name) +{ +MovTextContext *s = priv; +ASSStyle * style = ff_ass_style_get(s->ass_ctx, style_name); + +mov_text_ass_style_set(s, style); +} + static uint16_t utf8_strlen(const char *text, int len) { uint16_t i = 0, ret = 0; @@ -454,13 +471,14 @@ static void mov_text_new_line_cb(void *priv, int forced) } static const ASSCodesCallbacks mov_text_callbacks = { -.text = mov_text_text_cb, -.new_line = mov_text_new_line_cb, -.style = mov_text_style_cb, -.color = mov_text_color_cb, -.alpha = mov_text_alpha_cb, -.font_size = mov_text_font_size_cb, -.end = mov_text_end_cb, +.text = mov_text_text_cb, +.new_line = mov_text_new_line_cb, +.style= mov_text_style_cb, +.color= mov_text_color_cb, +.alpha= mov_text_alpha_cb, +.font_size= mov_text_font_size_cb, +.cancel_overrides = mov_text_cancel_overrides_cb, +.end = mov_text_end_cb, }; static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 19/23] lavc/movtextenc: add font size tag handling
--- libavcodec/movtextenc.c | 39 ++- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index e82393dde7..9e657c9635 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -128,7 +128,7 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) av_bprint_append_any(&s->buffer, &style_end, 2); av_bprint_append_any(&s->buffer, &style_fontID, 2); av_bprint_append_any(&s->buffer, &s->style_attributes[j]->style_flag, 1); -av_bprint_append_any(&s->buffer, &s->d.style_fontsize, 1); +av_bprint_append_any(&s->buffer, &s->style_attributes[j]->style_fontsize, 1); av_bprint_append_any(&s->buffer, &style_color, 4); } } @@ -244,8 +244,9 @@ static int mov_text_style_start(MovTextContext *s) if (s->style_attributes_temp->style_start == s->text_pos) // Still at same text pos, use same entry return 1; -if (s->style_attributes_temp->style_flag != s->d.style_flag || -s->style_attributes_temp->style_color != s->d.style_color) { +if (s->style_attributes_temp->style_flag != s->d.style_flag || +s->style_attributes_temp->style_color!= s->d.style_color || +s->style_attributes_temp->style_fontsize != s->d.style_fontsize) { // last style != defaults, end the style entry and start a new one s->box_flags |= STYL_BOX; s->style_attributes_temp->style_end = s->text_pos; @@ -260,10 +261,12 @@ static int mov_text_style_start(MovTextContext *s) s->style_attributes_temp->style_flag = s->style_attributes[s->count - 1]->style_flag; s->style_attributes_temp->style_color = s->style_attributes[s->count - 1]->style_color; +s->style_attributes_temp->style_fontsize = s->style_attributes[s->count - 1]->style_fontsize; s->style_attributes_temp->style_start = s->text_pos; } else { // style entry matches defaults, drop entry s->style_attributes_temp->style_flag = s->d.style_flag; s->style_attributes_temp->style_color = s->d.style_color; +s->style_attributes_temp->style_fontsize = s->d.style_fontsize; s->style_attributes_temp->style_start = s->text_pos; } return 1; @@ -371,6 +374,22 @@ static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id) mov_text_alpha_set(s, 255 - alpha); } +static void mov_text_font_size_set(MovTextContext *s, int size) +{ +if (!s->style_attributes_temp || +s->style_attributes_temp->style_fontsize == size) { +// color hasn't changed +return; +} +if (mov_text_style_start(s)) +s->style_attributes_temp->style_fontsize = size; +} + +static void mov_text_font_size_cb(void *priv, int size) +{ +mov_text_font_size_set((MovTextContext*)priv, size); +} + static void mov_text_end_cb(void *priv) { // End of text, close any open style record @@ -392,6 +411,7 @@ static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) mov_text_color_set(s, color); alpha = 255 - ((uint32_t)style->primary_color >> 24); mov_text_alpha_set(s, alpha); +mov_text_font_size_set(s, style->font_size); } } @@ -434,12 +454,13 @@ static void mov_text_new_line_cb(void *priv, int forced) } static const ASSCodesCallbacks mov_text_callbacks = { -.text = mov_text_text_cb, -.new_line = mov_text_new_line_cb, -.style= mov_text_style_cb, -.color= mov_text_color_cb, -.alpha= mov_text_alpha_cb, -.end = mov_text_end_cb, +.text = mov_text_text_cb, +.new_line = mov_text_new_line_cb, +.style = mov_text_style_cb, +.color = mov_text_color_cb, +.alpha = mov_text_alpha_cb, +.font_size = mov_text_font_size_cb, +.end = mov_text_end_cb, }; static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 18/23] lavc/movtextenc: add alpha tag handling
--- libavcodec/movtextenc.c | 25 - 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 090536b887..e82393dde7 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -351,6 +351,26 @@ static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color */ } +static void mov_text_alpha_set(MovTextContext *s, uint8_t alpha) +{ +if (!s->style_attributes_temp || +(s->style_attributes_temp->style_color & 0xff) == alpha) { +// color hasn't changed +return; +} +if (mov_text_style_start(s)) +s->style_attributes_temp->style_color = +(s->style_attributes_temp->style_color & 0xff00) | alpha; +} + +static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id) +{ +MovTextContext *s = priv; + +if (alpha_id == 1) // primary alpha changes +mov_text_alpha_set(s, 255 - alpha); +} + static void mov_text_end_cb(void *priv) { // End of text, close any open style record @@ -360,7 +380,7 @@ static void mov_text_end_cb(void *priv) static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) { ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); -uint8_tstyle_flags; +uint8_tstyle_flags, alpha; uint32_t color; if (style) { @@ -370,6 +390,8 @@ static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) mov_text_style_set(s, style_flags); color = BGR_TO_RGB(style->primary_color & 0xff) << 8; mov_text_color_set(s, color); +alpha = 255 - ((uint32_t)style->primary_color >> 24); +mov_text_alpha_set(s, alpha); } } @@ -416,6 +438,7 @@ static const ASSCodesCallbacks mov_text_callbacks = { .new_line = mov_text_new_line_cb, .style= mov_text_style_cb, .color= mov_text_color_cb, +.alpha= mov_text_alpha_cb, .end = mov_text_end_cb, }; -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 17/23] lavc/movtextenc: add color tag handling
--- libavcodec/movtextenc.c | 28 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 4e7d55efcb..090536b887 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -121,7 +121,7 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) style_start = AV_RB16(&s->style_attributes[j]->style_start); style_end= AV_RB16(&s->style_attributes[j]->style_end); -style_color = AV_RB32(&s->d.style_color); +style_color = AV_RB32(&s->style_attributes[j]->style_color); style_fontID = AV_RB16(&s->d.style_fontID); av_bprint_append_any(&s->buffer, &style_start, 2); @@ -244,7 +244,8 @@ static int mov_text_style_start(MovTextContext *s) if (s->style_attributes_temp->style_start == s->text_pos) // Still at same text pos, use same entry return 1; -if (s->style_attributes_temp->style_flag) { +if (s->style_attributes_temp->style_flag != s->d.style_flag || +s->style_attributes_temp->style_color != s->d.style_color) { // last style != defaults, end the style entry and start a new one s->box_flags |= STYL_BOX; s->style_attributes_temp->style_end = s->text_pos; @@ -258,9 +259,11 @@ static int mov_text_style_start(MovTextContext *s) } s->style_attributes_temp->style_flag = s->style_attributes[s->count - 1]->style_flag; +s->style_attributes_temp->style_color = s->style_attributes[s->count - 1]->style_color; s->style_attributes_temp->style_start = s->text_pos; } else { // style entry matches defaults, drop entry -s->style_attributes_temp->style_flag = 0; +s->style_attributes_temp->style_flag = s->d.style_flag; +s->style_attributes_temp->style_color = s->d.style_color; s->style_attributes_temp->style_start = s->text_pos; } return 1; @@ -313,12 +316,26 @@ static void mov_text_style_cb(void *priv, const char style, int close) } } +static void mov_text_color_set(MovTextContext *s, uint32_t color) +{ +if (!s->style_attributes_temp || +(s->style_attributes_temp->style_color & 0xff00) == color) { +// color hasn't changed +return; +} +if (mov_text_style_start(s)) +s->style_attributes_temp->style_color = (color & 0xff00) | +(s->style_attributes_temp->style_color & 0xff); +} + static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id) { MovTextContext *s = priv; color = BGR_TO_RGB(color) << 8; -if (color_id == 2) {//secondary color changes +if (color_id == 1) {//primary color changes +mov_text_color_set(s, color); +} else if (color_id == 2) {//secondary color changes if (s->box_flags & HLIT_BOX) { //close tag s->hlit.end = s->text_pos; } else { @@ -344,12 +361,15 @@ static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) { ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); uint8_tstyle_flags; +uint32_t color; if (style) { style_flags = (!!style->bold * STYLE_FLAG_BOLD) | (!!style->italic* STYLE_FLAG_ITALIC) | (!!style->underline * STYLE_FLAG_UNDERLINE); mov_text_style_set(s, style_flags); +color = BGR_TO_RGB(style->primary_color & 0xff) << 8; +mov_text_color_set(s, color); } } -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 16/23] lavc/movtextenc: init style record from ASS dialog style
--- libavcodec/movtextenc.c | 60 ++--- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index d389111419..4e7d55efcb 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -39,6 +39,11 @@ #define HLIT_BOX (1<<1) #define HCLR_BOX (1<<2) +#define DEFAULT_STYLE_FONT_ID 0x01 +#define DEFAULT_STYLE_FONTSIZE 0x12 +#define DEFAULT_STYLE_COLOR0x +#define DEFAULT_STYLE_FLAG 0x00 + #define BGR_TO_RGB(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) @@ -46,6 +51,9 @@ typedef struct { uint16_t style_start; uint16_t style_end; uint8_t style_flag; +uint16_t style_fontID; +uint8_t style_fontsize; +uint32_t style_color; } StyleBox; typedef struct { @@ -68,9 +76,7 @@ typedef struct { HilightcolorBox hclr; int count; uint8_t box_flags; -uint16_t style_fontID; -uint8_t style_fontsize; -uint32_t style_color; +StyleBox d; uint16_t text_pos; uint16_t byte_count; } MovTextContext; @@ -104,25 +110,26 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) tsmb_size = s->count * STYLE_RECORD_SIZE + SIZE_ADD; tsmb_size = AV_RB32(&tsmb_size); style_entries = AV_RB16(&s->count); -s->style_fontID = 0x00 | 0x01<<8; -s->style_fontsize = 0x12; -s->style_color = MKTAG(0xFF, 0xFF, 0xFF, 0xFF); /*The above three attributes are hard coded for now but will come from ASS style in the future*/ av_bprint_append_any(&s->buffer, &tsmb_size, 4); av_bprint_append_any(&s->buffer, &tsmb_type, 4); av_bprint_append_any(&s->buffer, &style_entries, 2); for (j = 0; j < s->count; j++) { -uint16_t style_start, style_end; +uint16_t style_start, style_end, style_fontID; +uint32_t style_color; style_start = AV_RB16(&s->style_attributes[j]->style_start); style_end= AV_RB16(&s->style_attributes[j]->style_end); +style_color = AV_RB32(&s->d.style_color); +style_fontID = AV_RB16(&s->d.style_fontID); + av_bprint_append_any(&s->buffer, &style_start, 2); av_bprint_append_any(&s->buffer, &style_end, 2); -av_bprint_append_any(&s->buffer, &s->style_fontID, 2); +av_bprint_append_any(&s->buffer, &style_fontID, 2); av_bprint_append_any(&s->buffer, &s->style_attributes[j]->style_flag, 1); -av_bprint_append_any(&s->buffer, &s->style_fontsize, 1); -av_bprint_append_any(&s->buffer, &s->style_color, 4); +av_bprint_append_any(&s->buffer, &s->d.style_fontsize, 1); +av_bprint_append_any(&s->buffer, &style_color, 4); } } mov_text_cleanup(s); @@ -220,6 +227,13 @@ static av_cold int mov_text_encode_init(AVCodecContext *avctx) memcpy(avctx->extradata, text_sample_entry, avctx->extradata_size); s->ass_ctx = ff_ass_split(avctx->subtitle_header); + +// TODO: Initialize from ASS style record +s->d.style_fontID = DEFAULT_STYLE_FONT_ID; +s->d.style_fontsize = DEFAULT_STYLE_FONTSIZE; +s->d.style_color= DEFAULT_STYLE_COLOR; +s->d.style_flag = DEFAULT_STYLE_FLAG; + return s->ass_ctx ? 0 : AVERROR_INVALIDDATA; } @@ -270,6 +284,17 @@ static uint8_t mov_text_style_to_flag(const char style) return style_flag; } +static void mov_text_style_set(MovTextContext *s, uint8_t style_flags) +{ +if (!s->style_attributes_temp || +!((s->style_attributes_temp->style_flag & style_flags) ^ style_flags)) { +// setting flags that that are already set +return; +} +if (mov_text_style_start(s)) +s->style_attributes_temp->style_flag |= style_flags; +} + static void mov_text_style_cb(void *priv, const char style, int close) { MovTextContext *s = priv; @@ -315,6 +340,19 @@ static void mov_text_end_cb(void *priv) mov_text_style_start((MovTextContext*)priv); } +static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) +{ +ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); +uint8_tstyle_flags; + +if (style) { +style_flags = (!!style->bold * STYLE_FLAG_BOLD) | + (!!style->italic* STYLE_FLAG_ITALIC) | + (!!style->underline * STYLE_FLAG_UNDERLINE); +mov_text_style_set(s, style_flags); +} +} + static uint16_t utf8_strlen(const char *text, int len) { uint16_t i = 0, ret = 0; @@ -386,6 +424,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, int num; dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num); for (; dialog && num--; dialog++) { +mov_tex
[FFmpeg-devel] [PATCH 14/23] lavc/movtextenc: simplify style record updates
Makes style update code easier to extend for style types not yet handled --- libavcodec/movtextenc.c | 131 +++- 1 file changed, 62 insertions(+), 69 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 5e5b786f44..05532cd544 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -89,6 +89,10 @@ static void mov_text_cleanup(MovTextContext *s) } av_freep(&s->style_attributes); } +if (s->style_attributes_temp) { +s->style_attributes_temp->style_flag = 0; +s->style_attributes_temp->style_start = 0; +} } static void encode_styl(MovTextContext *s, uint32_t tsmb_type) @@ -96,7 +100,7 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) int j; uint32_t tsmb_size; uint16_t style_entries; -if (s->box_flags & STYL_BOX) { +if ((s->box_flags & STYL_BOX) && s->count) { tsmb_size = s->count * STYLE_RECORD_SIZE + SIZE_ADD; tsmb_size = AV_RB32(&tsmb_size); style_entries = AV_RB16(&s->count); @@ -120,8 +124,8 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) av_bprint_append_any(&s->buffer, &s->style_fontsize, 1); av_bprint_append_any(&s->buffer, &s->style_color, 4); } -mov_text_cleanup(s); } +mov_text_cleanup(s); } static void encode_hlit(MovTextContext *s, uint32_t tsmb_type) @@ -201,6 +205,11 @@ static av_cold int mov_text_encode_init(AVCodecContext *avctx) MovTextContext *s = avctx->priv_data; s->avctx = avctx; +s->style_attributes_temp = av_mallocz(sizeof(*s->style_attributes_temp)); +if (!s->style_attributes_temp) { +return AVERROR(ENOMEM); +} + avctx->extradata_size = sizeof text_sample_entry; avctx->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!avctx->extradata) @@ -214,85 +223,69 @@ static av_cold int mov_text_encode_init(AVCodecContext *avctx) return s->ass_ctx ? 0 : AVERROR_INVALIDDATA; } -static void mov_text_style_cb(void *priv, const char style, int close) +// Start a new style box if needed +static int mov_text_style_start(MovTextContext *s) { -MovTextContext *s = priv; -if (!close) { -if (!(s->box_flags & STYL_BOX)) { //first style entry - -s->style_attributes_temp = av_malloc(sizeof(*s->style_attributes_temp)); - -if (!s->style_attributes_temp) { -av_bprint_clear(&s->buffer); -s->box_flags &= ~STYL_BOX; -return; -} - -s->style_attributes_temp->style_flag = 0; -s->style_attributes_temp->style_start = s->text_pos; -} else { -if (s->style_attributes_temp->style_flag) { //break the style record here and start a new one -s->style_attributes_temp->style_end = s->text_pos; -av_dynarray_add(&s->style_attributes, &s->count, s->style_attributes_temp); -s->style_attributes_temp = av_malloc(sizeof(*s->style_attributes_temp)); -if (!s->style_attributes_temp) { -mov_text_cleanup(s); -av_bprint_clear(&s->buffer); -s->box_flags &= ~STYL_BOX; -return; -} - -s->style_attributes_temp->style_flag = s->style_attributes[s->count - 1]->style_flag; -s->style_attributes_temp->style_start = s->text_pos; -} else { -s->style_attributes_temp->style_flag = 0; -s->style_attributes_temp->style_start = s->text_pos; -} -} -switch (style){ -case 'b': -s->style_attributes_temp->style_flag |= STYLE_FLAG_BOLD; -break; -case 'i': -s->style_attributes_temp->style_flag |= STYLE_FLAG_ITALIC; -break; -case 'u': -s->style_attributes_temp->style_flag |= STYLE_FLAG_UNDERLINE; -break; -} -} else if (!s->style_attributes_temp) { -av_log(s->avctx, AV_LOG_WARNING, "Ignoring unmatched close tag\n"); -return; -} else { +// there's an existing style entry +if (s->style_attributes_temp->style_start == s->text_pos) +// Still at same text pos, use same entry +return 1; +if (s->style_attributes_temp->style_flag) { +// last style != defaults, end the style entry and start a new one +s->box_flags |= STYL_BOX; s->style_attributes_temp->style_end = s->text_pos; av_dynarray_add(&s->style_attributes, &s->count, s->style_attributes_temp); - s->style_attributes_temp = av_malloc(sizeof(*s->style_attributes_temp)); - if (!s->style_attributes_temp) { mov_text_cleanup(s); av_bprint_clear(&s->buffer); s->box_flags &= ~STYL_BOX; -return; +ret
[FFmpeg-devel] [PATCH 15/23] lavc/movtextenc: fix unclosed style records
The last record at the end of each dialog was never closed --- libavcodec/movtextenc.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 05532cd544..d389111419 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -309,6 +309,12 @@ static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color */ } +static void mov_text_end_cb(void *priv) +{ +// End of text, close any open style record +mov_text_style_start((MovTextContext*)priv); +} + static uint16_t utf8_strlen(const char *text, int len) { uint16_t i = 0, ret = 0; @@ -352,6 +358,7 @@ static const ASSCodesCallbacks mov_text_callbacks = { .new_line = mov_text_new_line_cb, .style= mov_text_style_cb, .color= mov_text_color_cb, +.end = mov_text_end_cb, }; static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 13/23] lavc/movtextenc: keep values in native byte order till written
--- libavcodec/movtextenc.c | 38 ++ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 8638e303fe..5e5b786f44 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -68,7 +68,6 @@ typedef struct { HilightcolorBox hclr; int count; uint8_t box_flags; -uint16_t style_entries; uint16_t style_fontID; uint8_t style_fontsize; uint32_t style_color; @@ -96,10 +95,11 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) { int j; uint32_t tsmb_size; +uint16_t style_entries; if (s->box_flags & STYL_BOX) { tsmb_size = s->count * STYLE_RECORD_SIZE + SIZE_ADD; tsmb_size = AV_RB32(&tsmb_size); -s->style_entries = AV_RB16(&s->count); +style_entries = AV_RB16(&s->count); s->style_fontID = 0x00 | 0x01<<8; s->style_fontsize = 0x12; s->style_color = MKTAG(0xFF, 0xFF, 0xFF, 0xFF); @@ -107,10 +107,14 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) but will come from ASS style in the future*/ av_bprint_append_any(&s->buffer, &tsmb_size, 4); av_bprint_append_any(&s->buffer, &tsmb_type, 4); -av_bprint_append_any(&s->buffer, &s->style_entries, 2); +av_bprint_append_any(&s->buffer, &style_entries, 2); for (j = 0; j < s->count; j++) { -av_bprint_append_any(&s->buffer, &s->style_attributes[j]->style_start, 2); -av_bprint_append_any(&s->buffer, &s->style_attributes[j]->style_end, 2); +uint16_t style_start, style_end; + +style_start = AV_RB16(&s->style_attributes[j]->style_start); +style_end= AV_RB16(&s->style_attributes[j]->style_end); +av_bprint_append_any(&s->buffer, &style_start, 2); +av_bprint_append_any(&s->buffer, &style_end, 2); av_bprint_append_any(&s->buffer, &s->style_fontID, 2); av_bprint_append_any(&s->buffer, &s->style_attributes[j]->style_flag, 1); av_bprint_append_any(&s->buffer, &s->style_fontsize, 1); @@ -123,13 +127,16 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) static void encode_hlit(MovTextContext *s, uint32_t tsmb_type) { uint32_t tsmb_size; +uint16_t start, end; if (s->box_flags & HLIT_BOX) { tsmb_size = 12; tsmb_size = AV_RB32(&tsmb_size); +start = AV_RB16(&s->hlit.start); +end = AV_RB16(&s->hlit.end); av_bprint_append_any(&s->buffer, &tsmb_size, 4); av_bprint_append_any(&s->buffer, &tsmb_type, 4); -av_bprint_append_any(&s->buffer, &s->hlit.start, 2); -av_bprint_append_any(&s->buffer, &s->hlit.end, 2); +av_bprint_append_any(&s->buffer, &start, 2); +av_bprint_append_any(&s->buffer, &end, 2); } } @@ -222,10 +229,10 @@ static void mov_text_style_cb(void *priv, const char style, int close) } s->style_attributes_temp->style_flag = 0; -s->style_attributes_temp->style_start = AV_RB16(&s->text_pos); +s->style_attributes_temp->style_start = s->text_pos; } else { if (s->style_attributes_temp->style_flag) { //break the style record here and start a new one -s->style_attributes_temp->style_end = AV_RB16(&s->text_pos); +s->style_attributes_temp->style_end = s->text_pos; av_dynarray_add(&s->style_attributes, &s->count, s->style_attributes_temp); s->style_attributes_temp = av_malloc(sizeof(*s->style_attributes_temp)); if (!s->style_attributes_temp) { @@ -236,10 +243,10 @@ static void mov_text_style_cb(void *priv, const char style, int close) } s->style_attributes_temp->style_flag = s->style_attributes[s->count - 1]->style_flag; -s->style_attributes_temp->style_start = AV_RB16(&s->text_pos); +s->style_attributes_temp->style_start = s->text_pos; } else { s->style_attributes_temp->style_flag = 0; -s->style_attributes_temp->style_start = AV_RB16(&s->text_pos); +s->style_attributes_temp->style_start = s->text_pos; } } switch (style){ @@ -257,7 +264,7 @@ static void mov_text_style_cb(void *priv, const char style, int close) av_log(s->avctx, AV_LOG_WARNING, "Ignoring unmatched close tag\n"); return; } else { -s->style_attributes_temp->style_end = AV_RB16(&s->text_pos); +s->style_attributes_temp->style_end = s->text_pos; av_dynarray_add(&s->style_attributes, &s->count, s->style_attributes_temp); s->style_attributes_temp = av_malloc(sizeof(*s->style_attributes_temp)); @@ -282,7 +289,7 @@ static void mov_text_style_cb(void *priv, const char style, int close) break
[FFmpeg-devel] [PATCH 10/23] lavc/movtextdec: allow setting subtitle frame dimensions
Font sizes are relative to the subtitle frame dimensions. If the expected frame dimensions are not known, the font sizes will most likely be incorrect. --- libavcodec/ass.c| 30 +++--- libavcodec/ass.h| 28 libavcodec/movtextdec.c | 30 +- 3 files changed, 80 insertions(+), 8 deletions(-) diff --git a/libavcodec/ass.c b/libavcodec/ass.c index a51673fb4e..7c26e3fd6d 100644 --- a/libavcodec/ass.c +++ b/libavcodec/ass.c @@ -26,11 +26,13 @@ #include "libavutil/bprint.h" #include "libavutil/common.h" -int ff_ass_subtitle_header(AVCodecContext *avctx, - const char *font, int font_size, - int color, int back_color, - int bold, int italic, int underline, - int border_style, int alignment) +int ff_ass_subtitle_header_full(AVCodecContext *avctx, +int play_res_x, int play_res_y, +const char *font, int font_size, +int primary_color, int secondary_color, +int outline_color, int back_color, +int bold, int italic, int underline, +int border_style, int alignment) { avctx->subtitle_header = av_asprintf( "[Script Info]\r\n" @@ -67,8 +69,8 @@ int ff_ass_subtitle_header(AVCodecContext *avctx, "[Events]\r\n" "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r\n", !(avctx->flags & AV_CODEC_FLAG_BITEXACT) ? AV_STRINGIFY(LIBAVCODEC_VERSION) : "", - ASS_DEFAULT_PLAYRESX, ASS_DEFAULT_PLAYRESY, - font, font_size, color, color, back_color, back_color, + play_res_x, play_res_y, font, font_size, + primary_color, secondary_color, outline_color, back_color, -bold, -italic, -underline, border_style, alignment); if (!avctx->subtitle_header) @@ -77,6 +79,20 @@ int ff_ass_subtitle_header(AVCodecContext *avctx, return 0; } +int ff_ass_subtitle_header(AVCodecContext *avctx, + const char *font, int font_size, + int color, int back_color, + int bold, int italic, int underline, + int border_style, int alignment) +{ +return ff_ass_subtitle_header_full(avctx, + ASS_DEFAULT_PLAYRESX, ASS_DEFAULT_PLAYRESY, + font, font_size, color, color, + back_color, back_color, + bold, italic, underline, + border_style, alignment); +} + int ff_ass_subtitle_header_default(AVCodecContext *avctx) { return ff_ass_subtitle_header(avctx, ASS_DEFAULT_FONT, diff --git a/libavcodec/ass.h b/libavcodec/ass.h index 314b43b686..2c260e4e78 100644 --- a/libavcodec/ass.h +++ b/libavcodec/ass.h @@ -47,6 +47,34 @@ typedef struct FFASSDecoderContext { int readorder; } FFASSDecoderContext; +/** + * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. + * Can specify all fields explicitly + * + * @param avctx pointer to the AVCodecContext + * @param play_res_x subtitle frame width + * @param play_res_y subtitle frame height + * @param font name of the default font face to use + * @param font_size default font size to use + * @param primary_color default text color to use (ABGR) + * @param secondary_color default secondary text color to use (ABGR) + * @param outline_color default outline color to use (ABGR) + * @param back_color default background color to use (ABGR) + * @param bold 1 for bold text, 0 for normal text + * @param italic 1 for italic text, 0 for normal text + * @param underline 1 for underline text, 0 for normal text + * @param border_style 1 for outline, 3 for opaque box + * @param alignment position of the text (left, center, top...), defined after + * the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top) + * @return >= 0 on success otherwise an error code <0 + */ +int ff_ass_subtitle_header_full(AVCodecContext *avctx, +int play_res_x, int play_res_y, +const char *font, int font_size, +int primary_color, int secondary_color, +int outline_color, int back_color, +int bold, int italic, int underline, +int border_style, int alignment); /** * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. * diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index f3a504b47b..4b4da5e0d9 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -21,6 +21,7 @@ #include "avcodec.h" #include "as
[FFmpeg-devel] [PATCH 11/23] lavc/ass_split: fix parsing utf8 scripts
The [Script Info] section was skipped if starts with UTF8 BOM --- libavcodec/ass_split.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c index 67da7c6d84..94c32667af 100644 --- a/libavcodec/ass_split.c +++ b/libavcodec/ass_split.c @@ -354,6 +354,9 @@ static int ass_split(ASSSplitContext *ctx, const char *buf) if (ctx->current_section >= 0) buf = ass_split_section(ctx, buf); +if(!memcmp(buf, "\xef\xbb\xbf", 3)) { // Skip UTF-8 BOM header +buf += 3; +} while (buf && *buf) { if (sscanf(buf, "[%15[0-9A-Za-z+ ]]%c", section, &c) == 2) { buf += strcspn(buf, "\n"); -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 12/23] lavc/movtextenc: use correct color component order
--- libavcodec/movtextenc.c | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index c19ef384bc..8638e303fe 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -39,6 +39,7 @@ #define HLIT_BOX (1<<1) #define HCLR_BOX (1<<2) +#define BGR_TO_RGB(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) typedef struct { @@ -134,13 +135,14 @@ static void encode_hlit(MovTextContext *s, uint32_t tsmb_type) static void encode_hclr(MovTextContext *s, uint32_t tsmb_type) { -uint32_t tsmb_size; +uint32_t tsmb_size, color; if (s->box_flags & HCLR_BOX) { tsmb_size = 12; tsmb_size = AV_RB32(&tsmb_size); +color = AV_RB32(&s->hclr.color); av_bprint_append_any(&s->buffer, &tsmb_size, 4); av_bprint_append_any(&s->buffer, &tsmb_type, 4); -av_bprint_append_any(&s->buffer, &s->hclr.color, 4); +av_bprint_append_any(&s->buffer, &color, 4); } } @@ -289,6 +291,8 @@ static void mov_text_style_cb(void *priv, const char style, int close) static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id) { MovTextContext *s = priv; + +color = BGR_TO_RGB(color) << 8; if (color_id == 2) {//secondary color changes if (s->box_flags & HLIT_BOX) { //close tag s->hlit.end = AV_RB16(&s->text_pos); @@ -296,7 +300,7 @@ static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color s->box_flags |= HCLR_BOX; s->box_flags |= HLIT_BOX; s->hlit.start = AV_RB16(&s->text_pos); -s->hclr.color = color | (0xFF << 24); //set alpha value to FF +s->hclr.color = color | 0xFF; //set alpha value to FF } } /* If there are more than one secondary color changes in ASS, take start of -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 08/23] lavc/movtextdec: add color and alpha style tags
--- libavcodec/movtextdec.c | 15 --- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index eb9c7f5755..4d5dcdf5e7 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -76,6 +76,8 @@ typedef struct { uint8_t bold; uint8_t italic; uint8_t underline; +int color; +uint8_t alpha; uint8_t fontsize; uint16_t style_fontID; } StyleBox; @@ -329,14 +331,16 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt) m->s_temp->underline = !!(m->s_temp->style_flag & STYLE_FLAG_UNDERLINE); tsmb++; m->s_temp->fontsize = AV_RB8(tsmb); +tsmb++; +m->s_temp->color = AV_RB24(tsmb); +tsmb += 3; +m->s_temp->alpha = AV_RB8(tsmb); +tsmb++; av_dynarray_add(&m->s, &m->count_s, m->s_temp); if(!m->s) { mov_text_cleanup(m); return AVERROR(ENOMEM); } -tsmb++; -// text-color-rgba -tsmb += 4; } return 0; } @@ -400,6 +404,11 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, if (m->s[entry]->style_fontID == m->ftab[i]->fontID) av_bprintf(buf, "{\\fn%s}", m->ftab[i]->font); } +if (m->d.color != m->s[entry]->color) +av_bprintf(buf, "{\\1c&H%X&}", + RGB_TO_BGR(m->s[entry]->color)); +if (m->d.alpha != m->s[entry]->alpha) +av_bprintf(buf, "{\\1a&H%02X&}", 255 - m->s[entry]->alpha); } if (text_pos == m->s[entry]->style_end) { if (style_active) { -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 09/23] lavc/movtextdec: restore active style color after hilite
--- libavcodec/movtextdec.c | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index 4d5dcdf5e7..f3a504b47b 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -376,6 +376,7 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, int text_pos = 0; int style_active = 0; int entry = 0; +int color = m->d.color; if (text < text_end && m->box_flags & TWRP_BOX) { if (m->w.wrap_flag == 1) { @@ -404,9 +405,10 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, if (m->s[entry]->style_fontID == m->ftab[i]->fontID) av_bprintf(buf, "{\\fn%s}", m->ftab[i]->font); } -if (m->d.color != m->s[entry]->color) -av_bprintf(buf, "{\\1c&H%X&}", - RGB_TO_BGR(m->s[entry]->color)); +if (m->d.color != m->s[entry]->color) { +color = m->s[entry]->color; +av_bprintf(buf, "{\\1c&H%X&}", RGB_TO_BGR(color)); +} if (m->d.alpha != m->s[entry]->alpha) av_bprintf(buf, "{\\1a&H%02X&}", 255 - m->s[entry]->alpha); } @@ -414,6 +416,7 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, if (style_active) { av_bprintf(buf, "{\\r}"); style_active = 0; +color = m->d.color; } entry++; } @@ -435,9 +438,10 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, } if (text_pos == m->h.hlit_end) { if (m->box_flags & HCLR_BOX) { -av_bprintf(buf, "{\\2c&H00&}"); +av_bprintf(buf, "{\\2c&H%X&}", RGB_TO_BGR(m->d.color)); } else { -av_bprintf(buf, "{\\1c&HFF&}{\\2c&H00&}"); +av_bprintf(buf, "{\\1c&H%X&}{\\2c&H%X&}", + RGB_TO_BGR(color), RGB_TO_BGR(m->d.color)); } } } -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 07/23] lavc/movtextdec: add alpha default to ass header colors
--- libavcodec/movtextdec.c| 14 ++ tests/ref/fate/sub-movtext | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index 2481c71af6..eb9c7f5755 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -55,7 +55,9 @@ typedef struct { const char *font; uint8_t fontsize; int color; +uint8_t alpha; int back_color; +uint8_t back_alpha; uint8_t bold; uint8_t italic; uint8_t underline; @@ -186,7 +188,9 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) } // Background Color m->d.back_color = AV_RB24(tx3g_ptr); -tx3g_ptr += 4; +tx3g_ptr += 3; +m->d.back_alpha = AV_RB8(tx3g_ptr); +tx3g_ptr += 1; // BoxRecord tx3g_ptr += 8; // StyleRecord @@ -203,7 +207,9 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) m->d.fontsize = *tx3g_ptr++; // Primary color m->d.color = AV_RB24(tx3g_ptr); -tx3g_ptr += 4; +tx3g_ptr += 3; +m->d.alpha = AV_RB8(tx3g_ptr); +tx3g_ptr += 1; // FontRecord // FontRecord Size tx3g_ptr += 4; @@ -463,8 +469,8 @@ static int mov_text_init(AVCodecContext *avctx) { ret = mov_text_tx3g(avctx, m); if (ret == 0) { return ff_ass_subtitle_header(avctx, m->d.font, m->d.fontsize, -RGB_TO_BGR(m->d.color), -RGB_TO_BGR(m->d.back_color), +(255 - m->d.alpha) << 24 | RGB_TO_BGR(m->d.color), +(255 - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color), m->d.bold, m->d.italic, m->d.underline, ASS_DEFAULT_BORDERSTYLE, m->d.alignment); } else diff --git a/tests/ref/fate/sub-movtext b/tests/ref/fate/sub-movtext index 94ed22d318..6047060918 100644 --- a/tests/ref/fate/sub-movtext +++ b/tests/ref/fate/sub-movtext @@ -6,7 +6,7 @@ PlayResY: 288 [V4+ Styles] Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding -Style: Default,Serif,18,&Hff,&Hff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0 +Style: Default,Serif,18,&Hff,&Hff,&Hff00,&Hff00,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 06/23] lavc/movtextdec: make sure default font name is set
--- libavcodec/movtextdec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index 6c7d93702e..2481c71af6 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -52,7 +52,7 @@ typedef struct { uint16_t fontID; -char *font; +const char *font; uint8_t fontsize; int color; int back_color; @@ -251,6 +251,8 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) m->ftab_temp = NULL; tx3g_ptr = tx3g_ptr + font_length; } +// In case of broken header, init default font +m->d.font = ASS_DEFAULT_FONT; for (i = 0; i < m->ftab_entries; i++) { if (m->d.fontID == m->ftab[i]->fontID) m->d.font = m->ftab[i]->font; -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 04/23] lavc/movtextdec: handle changes to default style flags
Style flags were only being turned on. If the default was on and style record turned off, style flag remained on. --- libavcodec/movtextdec.c | 24 +++- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index d6896562c2..a3e37d013d 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -55,9 +55,9 @@ typedef struct { int fontsize; int color; int back_color; -int bold; -int italic; -int underline; +uint8_t bold; +uint8_t italic; +uint8_t underline; int alignment; } MovTextDefault; @@ -70,6 +70,9 @@ typedef struct { uint16_t style_start; uint16_t style_end; uint8_t style_flag; +uint8_t bold; +uint8_t italic; +uint8_t underline; uint8_t fontsize; uint16_t style_fontID; } StyleBox; @@ -313,6 +316,9 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt) m->s_temp->style_fontID = AV_RB16(tsmb); tsmb += 2; m->s_temp->style_flag = AV_RB8(tsmb); +m->s_temp->bold = !!(m->s_temp->style_flag & STYLE_FLAG_BOLD); +m->s_temp->italic = !!(m->s_temp->style_flag & STYLE_FLAG_ITALIC); +m->s_temp->underline = !!(m->s_temp->style_flag & STYLE_FLAG_UNDERLINE); tsmb++; m->s_temp->fontsize = AV_RB8(tsmb); av_dynarray_add(&m->s, &m->count_s, m->s_temp); @@ -373,12 +379,12 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, if ((m->box_flags & STYL_BOX) && entry < m->style_entries) { if (text_pos == m->s[entry]->style_start) { style_active = 1; -if (m->s[entry]->style_flag & STYLE_FLAG_BOLD) -av_bprintf(buf, "{\\b1}"); -if (m->s[entry]->style_flag & STYLE_FLAG_ITALIC) -av_bprintf(buf, "{\\i1}"); -if (m->s[entry]->style_flag & STYLE_FLAG_UNDERLINE) -av_bprintf(buf, "{\\u1}"); +if (m->s[entry]->bold ^ m->d.bold) +av_bprintf(buf, "{\\b%d}", m->s[entry]->bold); +if (m->s[entry]->italic ^ m->d.italic) +av_bprintf(buf, "{\\i%d}", m->s[entry]->italic); +if (m->s[entry]->underline ^ m->d.underline) +av_bprintf(buf, "{\\u%d}", m->s[entry]->underline); av_bprintf(buf, "{\\fs%d}", m->s[entry]->fontsize); for (i = 0; i < m->ftab_entries; i++) { if (m->s[entry]->style_fontID == m->ftab[i]->fontID) -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 05/23] lavc/movtextdec: only write fontsize, fontID tags if not default
--- libavcodec/movtextdec.c | 20 +++- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index a3e37d013d..6c7d93702e 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -51,8 +51,9 @@ #define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) typedef struct { +uint16_t fontID; char *font; -int fontsize; +uint8_t fontsize; int color; int back_color; uint8_t bold; @@ -146,7 +147,6 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) uint8_t *tx3g_ptr = avctx->extradata; int i, box_size, font_length; int8_t v_align, h_align; -int style_fontID; StyleBox s_default; m->count_f = 0; @@ -192,7 +192,7 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) // StyleRecord tx3g_ptr += 4; // fontID -style_fontID = AV_RB16(tx3g_ptr); +m->d.fontID = AV_RB16(tx3g_ptr); tx3g_ptr += 2; // face-style-flags s_default.style_flag = *tx3g_ptr++; @@ -252,7 +252,7 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) tx3g_ptr = tx3g_ptr + font_length; } for (i = 0; i < m->ftab_entries; i++) { -if (style_fontID == m->ftab[i]->fontID) +if (m->d.fontID == m->ftab[i]->fontID) m->d.font = m->ftab[i]->font; } return 0; @@ -385,11 +385,13 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, av_bprintf(buf, "{\\i%d}", m->s[entry]->italic); if (m->s[entry]->underline ^ m->d.underline) av_bprintf(buf, "{\\u%d}", m->s[entry]->underline); -av_bprintf(buf, "{\\fs%d}", m->s[entry]->fontsize); -for (i = 0; i < m->ftab_entries; i++) { -if (m->s[entry]->style_fontID == m->ftab[i]->fontID) -av_bprintf(buf, "{\\fn%s}", m->ftab[i]->font); -} +if (m->s[entry]->fontsize != m->d.fontsize) +av_bprintf(buf, "{\\fs%d}", m->s[entry]->fontsize); +if (m->s[entry]->style_fontID != m->d.fontID) +for (i = 0; i < m->ftab_entries; i++) { +if (m->s[entry]->style_fontID == m->ftab[i]->fontID) +av_bprintf(buf, "{\\fn%s}", m->ftab[i]->font); +} } if (text_pos == m->s[entry]->style_end) { if (style_active) { -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 03/23] lavc/movtextdec: fix bold, italic, underline flags
They should be 0 or 1 so that 0 or -1 is written to the ass header --- libavcodec/movtextdec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index 47a8401119..d6896562c2 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -193,9 +193,9 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) tx3g_ptr += 2; // face-style-flags s_default.style_flag = *tx3g_ptr++; -m->d.bold = s_default.style_flag & STYLE_FLAG_BOLD; -m->d.italic = s_default.style_flag & STYLE_FLAG_ITALIC; -m->d.underline = s_default.style_flag & STYLE_FLAG_UNDERLINE; +m->d.bold = !!(s_default.style_flag & STYLE_FLAG_BOLD); +m->d.italic = !!(s_default.style_flag & STYLE_FLAG_ITALIC); +m->d.underline = !!(s_default.style_flag & STYLE_FLAG_UNDERLINE); // fontsize m->d.fontsize = *tx3g_ptr++; // Primary color -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 02/23] lavc/movtextdec: simplify style record walk
It's not necessary to walk the style record list twice per subtitle character. style records are in order and do not overlap. --- libavcodec/movtextdec.c | 38 -- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index 05becaf64d..47a8401119 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -355,8 +355,9 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, { MovTextContext *m = avctx->priv_data; int i = 0; -int j = 0; int text_pos = 0; +int style_active = 0; +int entry = 0; if (text < text_end && m->box_flags & TWRP_BOX) { if (m->w.wrap_flag == 1) { @@ -369,26 +370,27 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, while (text < text_end) { int len; -if (m->box_flags & STYL_BOX) { -for (i = 0; i < m->style_entries; i++) { -if (m->s[i]->style_flag && text_pos == m->s[i]->style_end) { -av_bprintf(buf, "{\\r}"); +if ((m->box_flags & STYL_BOX) && entry < m->style_entries) { +if (text_pos == m->s[entry]->style_start) { +style_active = 1; +if (m->s[entry]->style_flag & STYLE_FLAG_BOLD) +av_bprintf(buf, "{\\b1}"); +if (m->s[entry]->style_flag & STYLE_FLAG_ITALIC) +av_bprintf(buf, "{\\i1}"); +if (m->s[entry]->style_flag & STYLE_FLAG_UNDERLINE) +av_bprintf(buf, "{\\u1}"); +av_bprintf(buf, "{\\fs%d}", m->s[entry]->fontsize); +for (i = 0; i < m->ftab_entries; i++) { +if (m->s[entry]->style_fontID == m->ftab[i]->fontID) +av_bprintf(buf, "{\\fn%s}", m->ftab[i]->font); } } -for (i = 0; i < m->style_entries; i++) { -if (m->s[i]->style_flag && text_pos == m->s[i]->style_start) { -if (m->s[i]->style_flag & STYLE_FLAG_BOLD) -av_bprintf(buf, "{\\b1}"); -if (m->s[i]->style_flag & STYLE_FLAG_ITALIC) -av_bprintf(buf, "{\\i1}"); -if (m->s[i]->style_flag & STYLE_FLAG_UNDERLINE) -av_bprintf(buf, "{\\u1}"); -av_bprintf(buf, "{\\fs%d}", m->s[i]->fontsize); -for (j = 0; j < m->ftab_entries; j++) { -if (m->s[i]->style_fontID == m->ftab[j]->fontID) -av_bprintf(buf, "{\\fn%s}", m->ftab[j]->font); -} +if (text_pos == m->s[entry]->style_end) { +if (style_active) { +av_bprintf(buf, "{\\r}"); +style_active = 0; } +entry++; } } if (m->box_flags & HLIT_BOX) { -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 01/23] lavc/movtextdec: fix ass header colors
A conversion from rgb to bgr is necessary --- libavcodec/movtextdec.c | 11 +++ 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index c38c5edce6..05becaf64d 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -48,6 +48,8 @@ #define TOP_CENTER 8 #define TOP_RIGHT 9 +#define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) + typedef struct { char *font; int fontsize; @@ -448,10 +450,11 @@ static int mov_text_init(AVCodecContext *avctx) { MovTextContext *m = avctx->priv_data; ret = mov_text_tx3g(avctx, m); if (ret == 0) { -return ff_ass_subtitle_header(avctx, m->d.font, m->d.fontsize, m->d.color, -m->d.back_color, m->d.bold, m->d.italic, -m->d.underline, ASS_DEFAULT_BORDERSTYLE, -m->d.alignment); +return ff_ass_subtitle_header(avctx, m->d.font, m->d.fontsize, +RGB_TO_BGR(m->d.color), +RGB_TO_BGR(m->d.back_color), +m->d.bold, m->d.italic, m->d.underline, +ASS_DEFAULT_BORDERSTYLE, m->d.alignment); } else return ff_ass_subtitle_header_default(avctx); } -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] movtext decode/encode improvements
Patch series adds more complete decoding and encoding of color, alpha, font size, font name, and style tags for movtext. It also fixes a number of bugs. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavformat/mov: restore use of mfra time as dts
This was inadvertantly removed in 4a9d32baca --- libavformat/mov.c | 5 + 1 file changed, 5 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 16a40debc7..eee98fb69c 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4813,6 +4813,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) pts = frag_stream_info->first_tfra_pts; av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64 ", using it for pts\n", pts); +} else if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE && +c->use_mfra_for == FF_MOV_FLAG_MFRA_DTS) { +dts = frag_stream_info->first_tfra_pts; +av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64 +", using it for dts\n", pts); } else if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE) { // FIXME: sidx earliest_presentation_time is *PTS*, s.b. // pts = frag_stream_info->sidx_pts; -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavformat/mov: fix multiple trun per traf
dts would start over at the beginning of each trun when they should be computed contiguously for each trun in a traf Fixes ticket 8070 --- libavformat/isom.h | 1 + libavformat/mov.c | 12 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 4943b80ccf..41a9c64c11 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -129,6 +129,7 @@ typedef struct MOVFragmentStreamInfo { int64_t sidx_pts; int64_t first_tfra_pts; int64_t tfdt_dts; +int64_t next_trun_dts; int index_entry; MOVEncryptionIndex *encryption_index; } MOVFragmentStreamInfo; diff --git a/libavformat/mov.c b/libavformat/mov.c index 8ed8b7f6e9..f96a7d8e39 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1335,6 +1335,7 @@ static int update_frag_index(MOVContext *c, int64_t offset) frag_stream_info[i].id = c->fc->streams[i]->id; frag_stream_info[i].sidx_pts = AV_NOPTS_VALUE; frag_stream_info[i].tfdt_dts = AV_NOPTS_VALUE; +frag_stream_info[i].next_trun_dts = AV_NOPTS_VALUE; frag_stream_info[i].first_tfra_pts = AV_NOPTS_VALUE; frag_stream_info[i].index_entry = -1; frag_stream_info[i].encryption_index = NULL; @@ -4609,6 +4610,7 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVFragment *frag = &c->fragment; MOVTrackExt *trex = NULL; int flags, track_id, i; +MOVFragmentStreamInfo * frag_stream_info; avio_r8(pb); /* version */ flags = avio_rb24(pb); @@ -4642,6 +4644,10 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_rb32(pb) : trex->flags; av_log(c->fc, AV_LOG_TRACE, "frag flags 0x%x\n", frag->flags); +frag_stream_info = get_current_frag_stream_info(&c->frag_index); +if (frag_stream_info) +frag_stream_info->next_trun_dts = AV_NOPTS_VALUE; + return 0; } @@ -4795,7 +4801,9 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) frag_stream_info = get_current_frag_stream_info(&c->frag_index); if (frag_stream_info) { -if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE && +if (frag_stream_info->next_trun_dts != AV_NOPTS_VALUE) { +dts = frag_stream_info->next_trun_dts - sc->time_offset; +} else if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE && c->use_mfra_for == FF_MOV_FLAG_MFRA_PTS) { pts = frag_stream_info->first_tfra_pts; av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64 @@ -4950,6 +4958,8 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->nb_frames_for_fps ++; } } +if (frag_stream_info) +frag_stream_info->next_trun_dts = dts + sc->time_offset; if (i < entries) { // EOF found before reading all entries. Fix the hole this would // leave in index_entries and ctts_data -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] mov: fix seek to next root atom in fragmented mp4
On Sun, 2020-03-29 at 22:38 +0200, Andreas Rheinhardt wrote: > John Stebbins: > > If some but not all moof's are referenced in an sidx, whole > > fragments > > were being skipped. > > > > Fixes tickets 7377, 7389, and 8502 > > May also fix 8070 but the sample links expired, so I can't test. > > Sample can be found here: > https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket8070/ > (You may probably thank Carl-Eugen for this.) > Thanks. So this patch *does not* fix 8070. I'll investigate... ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] mov: fix seek to next root atom in fragmented mp4
If some but not all moof's are referenced in an sidx, whole fragments were being skipped. Fixes tickets 7377, 7389, and 8502 May also fix 8070 but the sample links expired, so I can't test. --- libavformat/mov.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index f280f360b6..8ed8b7f6e9 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7724,7 +7724,8 @@ static int mov_switch_root(AVFormatContext *s, int64_t target, int index) mov->next_root_atom = 0; if (index < 0 || index >= mov->frag_index.nb_items) index = search_frag_moof_offset(&mov->frag_index, target); -if (index < mov->frag_index.nb_items) { +if (index < mov->frag_index.nb_items && +mov->frag_index.item[index].moof_offset == target) { if (index + 1 < mov->frag_index.nb_items) mov->next_root_atom = mov->frag_index.item[index + 1].moof_offset; if (mov->frag_index.item[index].headers_read) -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avformat/mov: fix sidx size being doubled in offset.
On 1/30/19 1:18 PM, Carl Eugen Hoyos wrote: 2019-01-30 19:44 GMT+01:00, no pls : From: mptcultist fixes an issue where if the video size was very specific, ffmpeg would hang from not filling the sidx_pts for all streams, due to not reading the last sidx lump. for #7572 Please wait for a review from John who has promised to look at this issue "on Wednesday". Carl Eugen Sorry I haven't had time to devote to this yet. This patch is incorrect however. offsets are relative to the anchor point which is the *end* of the sidx. See ISO 14496-12 section 8.16.3. "In the file containing the Segment Index box, the anchor point for a Segment Index box is the first byte after that box." ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 3/4] lavf/movenc: Fail when codec tag is invalid for format
On 09/07/2018 08:16 AM, James Almer wrote: > On 9/7/2018 12:09 PM, John Stebbins wrote: >> On 09/06/2018 03:40 PM, James Almer wrote: >>> On 8/27/2018 6:07 PM, John Stebbins wrote: >>>> On 08/27/2018 02:03 PM, James Almer wrote: >>>>> On 8/27/2018 5:48 PM, John Stebbins wrote: >>>>>> On 08/27/2018 01:29 PM, James Almer wrote: >>>>>>> On 8/27/2018 4:57 PM, John Stebbins wrote: >>>>>>>> Fixes ticket #6897 >>>>>>>> --- >>>>>>>> libavformat/movenc.c | 40 +--- >>>>>>>> 1 file changed, 29 insertions(+), 11 deletions(-) >>>>>>>> >>>>>>>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c >>>>>>>> index 8a3b651514..dd6281d210 100644 >>>>>>>> --- a/libavformat/movenc.c >>>>>>>> +++ b/libavformat/movenc.c >>>>>>>> @@ -1589,6 +1589,26 @@ static const AVCodecTag >>>>>>>> codec_cover_image_tags[] = { >>>>>>>> { AV_CODEC_ID_NONE, 0 }, >>>>>>>> }; >>>>>>>> >>>>>>>> +static int validate_codec_tag(const AVCodecTag *const *tags, >>>>>>>> + unsigned int tag, int codec_id) >>>>>>>> +{ >>>>>>>> +int i; >>>>>>>> + >>>>>>>> +/** >>>>>>>> + * Check that tag + id is in the table >>>>>>>> + */ >>>>>>>> +for (i = 0; tags && tags[i]; i++) { >>>>>>>> +const AVCodecTag *codec_tags = tags[i]; >>>>>>>> +while (codec_tags->id != AV_CODEC_ID_NONE) { >>>>>>>> +if (codec_tags->tag == tag && codec_tags->id == codec_id) >>>>>>>> { >>>>>>> Make both tag checks case insensitive using avpriv_toupper4(), then >>>>>>> return codec_tags->tag instead of 1 if the check succeeds. >>>>>> I've never seen mismatched case in these tags, but sure, why not... >>>>>> there's plenty I haven't seen. >>>>> AV1 in IVF is AV01, wheres in mp4 it's av01. That's the case i had in >>>>> mind when requesting this. >>>> Hmm, I should probably return codec_tags->tag in this case rather than tag >>>> since it is the expected capitalization for >>>> the container. I'll have to fix that (again). >>> What's the status of this? With that change i think it should be good to >>> go in. >> It's good as far as I'm concerned. I don't have commit privs. > Did you send the updated version returning codec_tags->tag? I can't find > it in my inbox. Otherwise I'd have pushed it. > Yup https://ffmpeg.org/pipermail/ffmpeg-devel/2018-August/233739.html -- John GnuPG fingerprint: D0EC B3DB C372 D1F1 0B01 83F0 49F1 D7B2 60D4 D0F7 signature.asc Description: OpenPGP digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 3/4] lavf/movenc: Fail when codec tag is invalid for format
On 09/06/2018 03:40 PM, James Almer wrote: > On 8/27/2018 6:07 PM, John Stebbins wrote: >> On 08/27/2018 02:03 PM, James Almer wrote: >>> On 8/27/2018 5:48 PM, John Stebbins wrote: >>>> On 08/27/2018 01:29 PM, James Almer wrote: >>>>> On 8/27/2018 4:57 PM, John Stebbins wrote: >>>>>> Fixes ticket #6897 >>>>>> --- >>>>>> libavformat/movenc.c | 40 +--- >>>>>> 1 file changed, 29 insertions(+), 11 deletions(-) >>>>>> >>>>>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c >>>>>> index 8a3b651514..dd6281d210 100644 >>>>>> --- a/libavformat/movenc.c >>>>>> +++ b/libavformat/movenc.c >>>>>> @@ -1589,6 +1589,26 @@ static const AVCodecTag codec_cover_image_tags[] >>>>>> = { >>>>>> { AV_CODEC_ID_NONE, 0 }, >>>>>> }; >>>>>> >>>>>> +static int validate_codec_tag(const AVCodecTag *const *tags, >>>>>> + unsigned int tag, int codec_id) >>>>>> +{ >>>>>> +int i; >>>>>> + >>>>>> +/** >>>>>> + * Check that tag + id is in the table >>>>>> + */ >>>>>> +for (i = 0; tags && tags[i]; i++) { >>>>>> +const AVCodecTag *codec_tags = tags[i]; >>>>>> +while (codec_tags->id != AV_CODEC_ID_NONE) { >>>>>> +if (codec_tags->tag == tag && codec_tags->id == codec_id) { >>>>> Make both tag checks case insensitive using avpriv_toupper4(), then >>>>> return codec_tags->tag instead of 1 if the check succeeds. >>>> I've never seen mismatched case in these tags, but sure, why not... >>>> there's plenty I haven't seen. >>> AV1 in IVF is AV01, wheres in mp4 it's av01. That's the case i had in >>> mind when requesting this. >> Hmm, I should probably return codec_tags->tag in this case rather than tag >> since it is the expected capitalization for >> the container. I'll have to fix that (again). > What's the status of this? With that change i think it should be good to > go in. It's good as far as I'm concerned. I don't have commit privs. -- John GnuPG fingerprint: D0EC B3DB C372 D1F1 0B01 83F0 49F1 D7B2 60D4 D0F7 signature.asc Description: OpenPGP digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/2] Use QT format for audio sample descriptors depending on stsd version.
On 09/06/2018 09:18 AM, Derek Buitenhuis wrote: > On 06/09/2018 17:13, Carl Eugen Hoyos wrote: >> Please mention ticket #7376 (and the Handbrake issue) in the commit >> message. > Wasn't aware there were tickets already, woops. > > Added locally. > > Looks like this also supersedes my earlier patch to fix the same problem... your solution is better, thanks ;) https://ffmpeg.org/pipermail/ffmpeg-devel/2018-August/233733.html -- John GnuPG fingerprint: D0EC B3DB C372 D1F1 0B01 83F0 49F1 D7B2 60D4 D0F7 signature.asc Description: OpenPGP digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavf/mov: factor out setting codec_id
Since it is performed in all cases now. --- libavformat/mov.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 3d4f6bcb21..4ee67cf500 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2508,22 +2508,19 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) "size=%"PRId64" 4CC=%s codec_type=%d\n", size, av_fourcc2str(format), st->codecpar->codec_type); +st->codecpar->codec_id = id; if (st->codecpar->codec_type==AVMEDIA_TYPE_VIDEO) { -st->codecpar->codec_id = id; mov_parse_stsd_video(c, pb, st, sc); } else if (st->codecpar->codec_type==AVMEDIA_TYPE_AUDIO) { -st->codecpar->codec_id = id; mov_parse_stsd_audio(c, pb, st, sc); if (st->codecpar->sample_rate < 0) { av_log(c->fc, AV_LOG_ERROR, "Invalid sample rate %d\n", st->codecpar->sample_rate); return AVERROR_INVALIDDATA; } } else if (st->codecpar->codec_type==AVMEDIA_TYPE_SUBTITLE){ -st->codecpar->codec_id = id; mov_parse_stsd_subtitle(c, pb, st, sc, size - (avio_tell(pb) - start_pos)); } else { -st->codecpar->codec_id = id; ret = mov_parse_stsd_data(c, pb, st, sc, size - (avio_tell(pb) - start_pos)); if (ret < 0) -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel