[FFmpeg-devel] [PATCH] avformat/flvenc: add flv live stream flag
Michael Niedermayer
michael at niedermayer.cc
Sat Oct 1 00:58:40 EEST 2016
On Fri, Sep 30, 2016 at 01:23:37PM +0800, Steven Liu wrote:
> 2016-09-30 0:53 GMT+08:00 Michael Niedermayer <michael at niedermayer.cc>:
>
> > On Thu, Sep 29, 2016 at 09:25:35PM +0800, Steven Liu wrote:
> > > patch update
> > >
> > > merge 1/2 and 2/2 into one patch
> >
> > > doc/muxers.texi | 5 +++++
> > > libavformat/flvenc.c | 50 +++++++++++++++++++++++++++++-
> > --------------------
> > > 2 files changed, 34 insertions(+), 21 deletions(-)
> > > f2c4c83d362faf1819b3aa72fc5608603f824dc1 0001-avformat-flvenc-add-flv-
> > live-stream-flag.patch
> > > From 7f5ff0d89c19e1683f91befb77ba4a7bf7b66252 Mon Sep 17 00:00:00 2001
> > > From: Steven Liu <lingjiujianke at gmail.com>
> > > Date: Thu, 29 Sep 2016 21:20:34 +0800
> > > Subject: [PATCH] avformat/flvenc: add flv live stream flag
> > >
> > > If the flv format is used for live stream on publish
> > > ffmpeg should not update dutration and filesize at the end.
> > > because the live stream is sent metadata at first step.
> > >
> > > Reviewed-by: Carl Eugen Hoyos <cehoyos at ag.or.at>
> > > Signed-off-by: Steven Liu <lingjiujianke at gmail.com>
> > > ---
> > > doc/muxers.texi | 5 +++++
> > > libavformat/flvenc.c | 50 +++++++++++++++++++++++++++++-
> > --------------------
> > > 2 files changed, 34 insertions(+), 21 deletions(-)
> > >
> > > diff --git a/doc/muxers.texi b/doc/muxers.texi
> > > index 27d1038..aa20656 100644
> > > --- a/doc/muxers.texi
> > > +++ b/doc/muxers.texi
> > > @@ -148,6 +148,11 @@ Place AAC sequence header based on audio stream
> > data.
> > > @item no_sequence_end
> > > Disable sequence end tag.
> > > @end table
> > > +
> > > + at item live_stream
> > > +Disable the duration and filesize update in the flv metadata.
> > > + at end table
> > > +
> > > @end table
> > >
> > > @anchor{framecrc}
> > > diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
> > > index 99903f5..cd9ca84 100644
> > > --- a/libavformat/flvenc.c
> > > +++ b/libavformat/flvenc.c
> > > @@ -64,6 +64,7 @@ static const AVCodecTag flv_audio_codec_ids[] = {
> > > typedef enum {
> > > FLV_AAC_SEQ_HEADER_DETECT = (1 << 0),
> > > FLV_NO_SEQUENCE_END = (1 << 1),
> > > + FLV_LIVE_STREAM = (1 << 2),
> > > } FLVFlags;
> > >
> > > typedef struct FLVContext {
> > > @@ -234,17 +235,18 @@ static void write_metadata(AVFormatContext *s,
> > unsigned int ts)
> > > metadata_count_pos = avio_tell(pb);
> > > metadata_count = 4 * !!flv->video_par +
> > > 5 * !!flv->audio_par +
> > > - 1 * !!flv->data_par +
> > > - 2; // +2 for duration and file size
> > > + 1 * !!flv->data_par;
> > >
> > > avio_wb32(pb, metadata_count);
> > >
> > > - put_amf_string(pb, "duration");
> > > - flv->duration_offset = avio_tell(pb);
> > > -
> > > - // fill in the guessed duration, it'll be corrected later if
> > incorrect
> > > - put_amf_double(pb, s->duration / AV_TIME_BASE);
> > > + if (!(flv->flags & FLV_LIVE_STREAM)) {
> > > + put_amf_string(pb, "duration");
> > > + flv->duration_offset = avio_tell(pb);
> > >
> > > + // fill in the guessed duration, it'll be corrected later if
> > incorrect
> > > + put_amf_double(pb, s->duration / AV_TIME_BASE);
> > > + metadata_count++;
> > > + }
> > > if (flv->video_par) {
> > > put_amf_string(pb, "width");
> > > put_amf_double(pb, flv->video_par->width);
> > > @@ -319,10 +321,12 @@ static void write_metadata(AVFormatContext *s,
> > unsigned int ts)
> > > metadata_count++;
> > > }
> > >
> > > - put_amf_string(pb, "filesize");
> > > - flv->filesize_offset = avio_tell(pb);
> > > - put_amf_double(pb, 0); // delayed write
> > > -
> > > + if (!(flv->flags & FLV_LIVE_STREAM)) {
> > > + put_amf_string(pb, "filesize");
> > > + flv->filesize_offset = avio_tell(pb);
> > > + put_amf_double(pb, 0); // delayed write
> > > + metadata_count++
> > > + }
> > > put_amf_string(pb, "");
> > > avio_w8(pb, AMF_END_OF_OBJECT);
> > >
> > > @@ -543,16 +547,19 @@ static int flv_write_trailer(AVFormatContext *s)
> > >
> > > file_size = avio_tell(pb);
> > >
> > > - /* update information */
> > > - if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0)
> > > - av_log(s, AV_LOG_WARNING, "Failed to update header with correct
> > duration.\n");
> > > - else
> > > - put_amf_double(pb, flv->duration / (double)1000);
> > > - if (avio_seek(pb, flv->filesize_offset, SEEK_SET) < 0)
> > > - av_log(s, AV_LOG_WARNING, "Failed to update header with correct
> > filesize.\n");
> > > - else
> > > - put_amf_double(pb, file_size);
> > > -
> > > + if (!(flv->flags & FLV_LIVE_STREAM)) {
> > > + /* update information */
> > > + if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0) {
> > > + av_log(s, AV_LOG_WARNING, "Failed to update header with
> > correct duration.\n");
> > > + } else {
> > > + put_amf_double(pb, flv->duration / (double)1000);
> > > + }
> > > + if (avio_seek(pb, flv->filesize_offset, SEEK_SET) < 0) {
> > > + av_log(s, AV_LOG_WARNING, "Failed to update header with
> > correct filesize.\n");
> > > + } else {
> > > + put_amf_double(pb, file_size);
> > > + }
> > > + }
> > > avio_seek(pb, file_size, SEEK_SET);
> > > return 0;
> > > }
> >
> > > @@ -729,6 +736,7 @@ 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" },
> > > { "no_sequence_end", "disable sequence end for FLV", 0,
> > AV_OPT_TYPE_CONST, {.i64 = FLV_NO_SEQUENCE_END}, INT_MIN, INT_MAX,
> > AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
> > > + { "live_stream", "used for flv live stream mode", 0,
> > AV_OPT_TYPE_CONST, {.i64 = FLV_LIVE_STREAM}, INT_MIN, INT_MAX,
> > AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
> > > { NULL },
> >
> > i may misunderstand the intend but you can use
> > pb->seekable
> > to identify if the output protocol supports seeking
> > (a live stream where data was already sent could not support seeking)
> >
> > OTOH
> > if the intend is to create files on seekable media that lack duration/
> > filesize then the patch should be ok
> >
> > [...]
> >
> > --
> > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > Dictatorship naturally arises out of democracy, and the most aggravated
> > form of tyranny and slavery out of the most extreme liberty. -- Plato
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > patch update
> doc/muxers.texi | 3 ++
> libavformat/flvenc.c | 54 +++++++++++++++++++++++++++++----------------------
> 2 files changed, 34 insertions(+), 23 deletions(-)
> 5b7364317d29f08c57dd2fc05a0bf22c20e38917 0001-avformat-flvenc-add-flv-stream-seekable-flag.patch
> From 205db2105d5edb7aaff1f76529b1c9954459a4e3 Mon Sep 17 00:00:00 2001
> From: Steven Liu <lingjiujianke at gmail.com>
> Date: Fri, 30 Sep 2016 13:16:55 +0800
> Subject: [PATCH] avformat/flvenc: add flv stream seekable flag
>
> If the flv format is used for live stream on publish
> ffmpeg should not update dutration and filesize at the end
> if the stream non-seekable
>
> Reviewed-by: Carl Eugen Hoyos <cehoyos at ag.or.at>
> Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
> Signed-off-by: Steven Liu <lingjiujianke at gmail.com>
> ---
> doc/muxers.texi | 3 +++
> libavformat/flvenc.c | 54 ++++++++++++++++++++++++++++++----------------------
> 2 files changed, 34 insertions(+), 23 deletions(-)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 27d1038..2890a8a 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -147,6 +147,9 @@ Place AAC sequence header based on audio stream data.
>
> @item no_sequence_end
> Disable sequence end tag.
> +
> + at item flv_stream_seekable
> +create the duration and filesize in the flv metadata.
> @end table
> @end table
>
> diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
> index 99903f5..7c00cf1 100644
> --- a/libavformat/flvenc.c
> +++ b/libavformat/flvenc.c
> @@ -64,6 +64,7 @@ static const AVCodecTag flv_audio_codec_ids[] = {
> typedef enum {
> FLV_AAC_SEQ_HEADER_DETECT = (1 << 0),
> FLV_NO_SEQUENCE_END = (1 << 1),
> + FLV_STREAM_SEEKABLE = (1 << 2),
stream seekability is not a flag you can set it is in
pb->seekable
also this patch breaks fate
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160930/172fb5e3/attachment.sig>
More information about the ffmpeg-devel
mailing list