diff mbox series

[FFmpeg-devel] flvdec: fix size desync when reading timestamp offsets

Message ID 20230724234123.1054-1-h.leppkes@gmail.com
State Accepted
Commit 6dd5f9509334f53a4217540d430360d49578ecee
Headers show
Series [FFmpeg-devel] flvdec: fix size desync when reading timestamp offsets | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Hendrik Leppkes July 24, 2023, 11:41 p.m. UTC
The size offset was previously being accounted for in flv_set_video_codec
for h264 and mpeg4, instead of being directly accounted for in the spot
where its read, which desynced on HEVC streams.

For clarity, move the size offset directly to the parsing, similar to
how its done for all other header fields.
---
 libavformat/flvdec.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Timo Rothenpieler July 25, 2023, 12:10 a.m. UTC | #1
On 25.07.2023 01:41, Hendrik Leppkes wrote:
> The size offset was previously being accounted for in flv_set_video_codec
> for h264 and mpeg4, instead of being directly accounted for in the spot
> where its read, which desynced on HEVC streams.
> 
> For clarity, move the size offset directly to the parsing, similar to
> how its done for all other header fields.
> ---
>   libavformat/flvdec.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
> index a6a94a4021..3fe21622f7 100644
> --- a/libavformat/flvdec.c
> +++ b/libavformat/flvdec.c
> @@ -407,11 +407,9 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
>       case FLV_CODECID_H264:
>           par->codec_id = AV_CODEC_ID_H264;
>           vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
> -        ret = 3;     // not 4, reading packet type will consume one byte
>           break;
>       case FLV_CODECID_MPEG4:
>           par->codec_id = AV_CODEC_ID_MPEG4;
> -        ret = 3;
>           break;
>       default:
>           avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
> @@ -1321,6 +1319,7 @@ retry_duration:
>                          "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
>                   dts = pts = AV_NOPTS_VALUE;
>               }
> +            size -= 3;
>           }
>           if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
>               st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_HEVC ||

tested with both h264 and hevc input, works fine
diff mbox series

Patch

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index a6a94a4021..3fe21622f7 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -407,11 +407,9 @@  static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
     case FLV_CODECID_H264:
         par->codec_id = AV_CODEC_ID_H264;
         vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
-        ret = 3;     // not 4, reading packet type will consume one byte
         break;
     case FLV_CODECID_MPEG4:
         par->codec_id = AV_CODEC_ID_MPEG4;
-        ret = 3;
         break;
     default:
         avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
@@ -1321,6 +1319,7 @@  retry_duration:
                        "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
                 dts = pts = AV_NOPTS_VALUE;
             }
+            size -= 3;
         }
         if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
             st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_HEVC ||