[FFmpeg-devel] [PATCH V1] lavf/flvenc: add automatic bitstream filtering
mypopy at gmail.com
mypopy at gmail.com
Tue Jun 25 05:48:52 EEST 2019
On Sat, Jun 22, 2019 at 5:54 PM Steven Liu <lq at chinaffmpeg.org> wrote:
>
>
>
> > 在 2019年6月22日,17:04,Jun Zhao <mypopydev at gmail.com> 写道:
> >
> > From: Jun Zhao <barryjzhao at tencent.com>
> >
> > add automatic bitstream filtering when mux AAC
> >
> > Signed-off-by: Jun Zhao <barryjzhao at tencent.com>
> > ---
> > libavformat/flvenc.c | 27 ++++++++++++++++++++++++---
> > 1 files changed, 24 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
> > index e4863f1..fb1dede 100644
> > --- a/libavformat/flvenc.c
> > +++ b/libavformat/flvenc.c
> > @@ -653,11 +653,9 @@ end:
> > return ret;
> > }
> >
> > -
> > -static int flv_write_header(AVFormatContext *s)
> > +static int flv_init(struct AVFormatContext *s)
> > {
> > int i;
> > - AVIOContext *pb = s->pb;
> > FLVContext *flv = s->priv_data;
> >
> > for (i = 0; i < s->nb_streams; i++) {
> > @@ -736,6 +734,15 @@ static int flv_write_header(AVFormatContext *s)
> >
> > flv->delay = AV_NOPTS_VALUE;
> >
> > + return 0;
> > +}
> > +
> > +static int flv_write_header(AVFormatContext *s)
> > +{
> > + int i;
> > + AVIOContext *pb = s->pb;
> > + FLVContext *flv = s->priv_data;
> > +
> > avio_write(pb, "FLV", 3);
> > avio_w8(pb, 1);
> > avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!flv->audio_par +
> > @@ -1074,6 +1081,18 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
> > return pb->error;
> > }
> >
> > +static int flv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
> > +{
> > + int ret = 1;
> > + AVStream *st = s->streams[pkt->stream_index];
> > +
> > + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
> > + if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0)
> > + ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
> > + }
> > + return ret;
> > +}
> > +
> > static const AVOption options[] = {
> > { "flvflags", "FLV muxer flags", offsetof(FLVContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
> > { "aac_seq_header_detect", "Put AAC sequence header based on stream data", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_AAC_SEQ_HEADER_DETECT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
> > @@ -1099,9 +1118,11 @@ AVOutputFormat ff_flv_muxer = {
> > .priv_data_size = sizeof(FLVContext),
> > .audio_codec = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_ADPCM_SWF,
> > .video_codec = AV_CODEC_ID_FLV1,
> > + .init = flv_init,
> > .write_header = flv_write_header,
> > .write_packet = flv_write_packet,
> > .write_trailer = flv_write_trailer,
> > + .check_bitstream= flv_check_bitstream,
> > .codec_tag = (const AVCodecTag* const []) {
> > flv_video_codec_ids, flv_audio_codec_ids, 0
> > },
> > --
> > 1.7.1
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe”.
>
> LGTM
>
> Don’t forget add add Reported-by: Yabo Wei
>
Pushed and add the Reported-by, Tks
More information about the ffmpeg-devel
mailing list