Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avformat/flvenc: fix EOS tag
@ 2023-02-06 21:25 Zhao Zhili
  2023-02-07  2:16 ` Steven Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Zhao Zhili @ 2023-02-06 21:25 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Zhao Zhili

From: Zhao Zhili <zhilizhao@tencent.com>

FLV spec only has AVC end of sequence tag, and the EOS tag has a
CodecID as other video data packet. MPEG4 doesn't conformance to
the spec, but it's there for a decade. So only 'fix' the EOS tag
rather than remove it completely.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
---
 libavformat/flvenc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 128ae8ebc0..8830c03044 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -235,13 +235,16 @@ static void put_timestamp(AVIOContext *pb, int64_t ts) {
     avio_w8(pb, (ts >> 24) & 0x7F);
 }
 
-static void put_avc_eos_tag(AVIOContext *pb, unsigned ts)
+static void put_eos_tag(AVIOContext *pb, unsigned ts, enum AVCodecID codec_id)
 {
+    uint32_t tag = ff_codec_get_tag(flv_video_codec_ids, codec_id);
+    /* ub[4] FrameType = 1, ub[4] CodecId */
+    tag |= 1 << 4;
     avio_w8(pb, FLV_TAG_TYPE_VIDEO);
     avio_wb24(pb, 5);               /* Tag Data Size */
     put_timestamp(pb, ts);
     avio_wb24(pb, 0);               /* StreamId = 0 */
-    avio_w8(pb, 23);                /* ub[4] FrameType = 1, ub[4] CodecId = 7 */
+    avio_w8(pb, tag);
     avio_w8(pb, 2);                 /* AVC end of sequence */
     avio_wb24(pb, 0);               /* Always 0 for AVC EOS. */
     avio_wb32(pb, 16);              /* Size of FLV tag */
@@ -783,7 +786,7 @@ end:
             FLVStreamContext *sc = s->streams[i]->priv_data;
             if (par->codec_type == AVMEDIA_TYPE_VIDEO &&
                     (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4))
-                put_avc_eos_tag(pb, sc->last_ts);
+                put_eos_tag(pb, sc->last_ts, par->codec_id);
         }
     }
 
-- 
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-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avformat/flvenc: fix EOS tag
  2023-02-06 21:25 [FFmpeg-devel] [PATCH] avformat/flvenc: fix EOS tag Zhao Zhili
@ 2023-02-07  2:16 ` Steven Liu
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Liu @ 2023-02-07  2:16 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Steven Liu, Zhao Zhili



> 2023年2月7日 05:25,Zhao Zhili <quinkblack@foxmail.com> 写道:
> 
> From: Zhao Zhili <zhilizhao@tencent.com>
> 
> FLV spec only has AVC end of sequence tag, and the EOS tag has a
> CodecID as other video data packet. MPEG4 doesn't conformance to
> the spec, but it's there for a decade. So only 'fix' the EOS tag
> rather than remove it completely.
> 
> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
> ---
> libavformat/flvenc.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
> index 128ae8ebc0..8830c03044 100644
> --- a/libavformat/flvenc.c
> +++ b/libavformat/flvenc.c
> @@ -235,13 +235,16 @@ static void put_timestamp(AVIOContext *pb, int64_t ts) {
>     avio_w8(pb, (ts >> 24) & 0x7F);
> }
> 
> -static void put_avc_eos_tag(AVIOContext *pb, unsigned ts)
> +static void put_eos_tag(AVIOContext *pb, unsigned ts, enum AVCodecID codec_id)
> {
> +    uint32_t tag = ff_codec_get_tag(flv_video_codec_ids, codec_id);
> +    /* ub[4] FrameType = 1, ub[4] CodecId */
> +    tag |= 1 << 4;
>     avio_w8(pb, FLV_TAG_TYPE_VIDEO);
>     avio_wb24(pb, 5);               /* Tag Data Size */
>     put_timestamp(pb, ts);
>     avio_wb24(pb, 0);               /* StreamId = 0 */
> -    avio_w8(pb, 23);                /* ub[4] FrameType = 1, ub[4] CodecId = 7 */
> +    avio_w8(pb, tag);
>     avio_w8(pb, 2);                 /* AVC end of sequence */
>     avio_wb24(pb, 0);               /* Always 0 for AVC EOS. */
>     avio_wb32(pb, 16);              /* Size of FLV tag */
> @@ -783,7 +786,7 @@ end:
>             FLVStreamContext *sc = s->streams[i]->priv_data;
>             if (par->codec_type == AVMEDIA_TYPE_VIDEO &&
>                     (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4))
> -                put_avc_eos_tag(pb, sc->last_ts);
> +                put_eos_tag(pb, sc->last_ts, par->codec_id);
>         }
>     }
> 
> -- 
> 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-request@ffmpeg.org with subject "unsubscribe".
> 

LGTM


Thanks

Steven Liu

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-07  2:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-06 21:25 [FFmpeg-devel] [PATCH] avformat/flvenc: fix EOS tag Zhao Zhili
2023-02-07  2:16 ` Steven Liu

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git