diff mbox series

[FFmpeg-devel] movenc: Ensure no separate moof written for empty track

Message ID 20210812044354.485278-1-sehuww@mail.scut.edu.cn
State Accepted
Commit 2b77a2f723cd0af441db26dd5ee632af3040e7cb
Headers show
Series [FFmpeg-devel] movenc: Ensure no separate moof written for empty track | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Hu Weiwen Aug. 12, 2021, 4:43 a.m. UTC
track->mdat_buf can be not NULL while the track is still empty if the
last packet write failed.

Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn>
---
 libavformat/movenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Martin Storsjö Aug. 12, 2021, 8:26 p.m. UTC | #1
On Thu, 12 Aug 2021, Hu Weiwen wrote:

> track->mdat_buf can be not NULL while the track is still empty if the
> last packet write failed.
>
> Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn>
> ---
> libavformat/movenc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index bcc202300bb..a460cd9adae 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -5422,7 +5422,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
>             duration = track->start_dts + track->track_duration -
>                        track->cluster[0].dts;
>         if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) {
> -            if (!track->mdat_buf)
> +            if (!track->entry)
>                 continue;
>             mdat_size = avio_tell(track->mdat_buf);
>             moof_tracks = i;
> -- 
> 2.25.1

Ok I guess.

If this situation happens (we allocate mdat_buf but fail to write a sample 
to it), I guess we can end up with some half-written packet at the start 
of it, which will be written as part of the next fragment. As long as byte 
offsets end up correct so the extra data at the start of the buffer is 
ignored I guess that'll work fine (I didn't check right now).

// Martin
Martin Storsjö Aug. 18, 2021, 10:22 a.m. UTC | #2
On Thu, 12 Aug 2021, Martin Storsjö wrote:

> On Thu, 12 Aug 2021, Hu Weiwen wrote:
>
>> track->mdat_buf can be not NULL while the track is still empty if the
>> last packet write failed.
>> 
>> Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn>
>> ---
>> libavformat/movenc.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
>> index bcc202300bb..a460cd9adae 100644
>> --- a/libavformat/movenc.c
>> +++ b/libavformat/movenc.c
>> @@ -5422,7 +5422,7 @@ static int mov_flush_fragment(AVFormatContext *s, int 
>> force)
>>             duration = track->start_dts + track->track_duration -
>>                        track->cluster[0].dts;
>>         if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) {
>> -            if (!track->mdat_buf)
>> +            if (!track->entry)
>>                 continue;
>>             mdat_size = avio_tell(track->mdat_buf);
>>             moof_tracks = i;
>> -- 
>> 2.25.1
>
> Ok I guess.

Pushed this patch too.

// Martin
diff mbox series

Patch

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index bcc202300bb..a460cd9adae 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -5422,7 +5422,7 @@  static int mov_flush_fragment(AVFormatContext *s, int force)
             duration = track->start_dts + track->track_duration -
                        track->cluster[0].dts;
         if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) {
-            if (!track->mdat_buf)
+            if (!track->entry)
                 continue;
             mdat_size = avio_tell(track->mdat_buf);
             moof_tracks = i;