diff mbox

[FFmpeg-devel,v4] avformat/movenc: split empty text sample when duration overflow

Message ID 20191008013443.8404-1-junli1026@gmail.com
State New
Headers show

Commit Message

Jun Li Oct. 8, 2019, 1:34 a.m. UTC
Fix #7637
One empty/end sample is created and inserted between two caption lines when there is a gap.
This patch is to split the sample into multiple ones when its duration is too long (>= INT_MAX)

Signed-off-by: Jun Li <junli1026@gmail.com>
---
 libavformat/movenc.c                          | 26 ++++++++++++++-----
 tests/fate/subtitles.mak                      |  6 +++++
 tests/ref/fate/binsub-movtextenc-long-dur     |  1 +
 .../fate/binsub-movtextenc-long-dur-timebase  |  1 +
 4 files changed, 28 insertions(+), 6 deletions(-)
 create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur
 create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur-timebase

Comments

Jun Li Oct. 8, 2019, 1:36 a.m. UTC | #1
On Mon, Oct 7, 2019 at 6:34 PM Jun Li <junli1026@gmail.com> wrote:

> Fix #7637
> One empty/end sample is created and inserted between two caption lines
> when there is a gap.
> This patch is to split the sample into multiple ones when its duration is
> too long (>= INT_MAX)
>
> Signed-off-by: Jun Li <junli1026@gmail.com>
> ---
>  libavformat/movenc.c                          | 26 ++++++++++++++-----
>  tests/fate/subtitles.mak                      |  6 +++++
>  tests/ref/fate/binsub-movtextenc-long-dur     |  1 +
>  .../fate/binsub-movtextenc-long-dur-timebase  |  1 +
>  4 files changed, 28 insertions(+), 6 deletions(-)
>  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur
>  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur-timebase
>
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 715bec1c2f..5dc2a19c3c 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -5750,7 +5750,8 @@ static int mov_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>           *
>           * 2) For each subtitle track, check if the current packet's
>           * dts is past the duration of the last subtitle sample. If
> -         * so, we now need to write an end sample for that subtitle.
> +         * so, we now need to write one or multiple end samples for
> +         * that subtitle.
>           *
>           * This must be done conditionally to allow for subtitles that
>           * immediately replace each other, in which case an end sample
> @@ -5764,11 +5765,24 @@ static int mov_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>              int ret;
>
>              if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT &&
> -                trk->track_duration < pkt->dts &&
> -                (trk->entry == 0 || !trk->last_sample_is_subtitle_end)) {
> -                ret = mov_write_subtitle_end_packet(s, i,
> trk->track_duration);
> -                if (ret < 0) return ret;
> -                trk->last_sample_is_subtitle_end = 1;
> +                trk->track_duration < pkt->dts) {
> +                int max_duration = INT_MAX - 1;
> +                if (trk->entry == 0 || !trk->last_sample_is_subtitle_end)
> {
> +                    ret = mov_write_subtitle_end_packet(s, i,
> trk->track_duration);
> +                    if (ret < 0)
> +                        return ret;
> +                    trk->last_sample_is_subtitle_end = 1;
> +                }
> +                if (trk->last_sample_is_subtitle_end &&
> +                    pkt->dts - trk->track_duration > max_duration) {
> +                    int64_t dts = trk->track_duration;
> +                    while(pkt->dts - dts > max_duration) {
> +                        dts += max_duration;
> +                        ret = mov_write_subtitle_end_packet(s, i, dts);
> +                        if (ret < 0)
> +                            return ret;
> +                    }
> +                }
>              }
>          }
>
> diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
> index 0042902161..4c2b34c431 100644
> --- a/tests/fate/subtitles.mak
> +++ b/tests/fate/subtitles.mak
> @@ -34,6 +34,12 @@ fate-sub-movtext: CMD = fmtstdout ass -i
> $(TARGET_SAMPLES)/sub/MovText_capabilit
>  FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc
>  fate-binsub-movtextenc: CMD = md5 -i
> $(TARGET_SAMPLES)/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text
> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>
> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
> fate-binsub-movtextenc-long-dur
> +fate-binsub-movtextenc-long-dur: CMD = md5 -i
> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
> +
> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
> fate-binsub-movtextenc-long-dur-timebase
> +fate-binsub-movtextenc-long-dur-timebase: CMD = md5 -i
> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
> -time_base 1000 -f mp4 -flags +bitexact -fflags +bitexact -movflags
> frag_keyframe+empty_moov
> +
>  FATE_SUBTITLES_ASS-$(call DEMDEC, MPL2, MPL2) += fate-sub-mpl2
>  fate-sub-mpl2: CMD = fmtstdout ass -i
> $(TARGET_SAMPLES)/sub/MPL2_capability_tester.txt
>
> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur
> b/tests/ref/fate/binsub-movtextenc-long-dur
> new file mode 100644
> index 0000000000..eb8a3f8fc7
> --- /dev/null
> +++ b/tests/ref/fate/binsub-movtextenc-long-dur
> @@ -0,0 +1 @@
> +7f78c11bb4a6b16335540ef31ba10219
> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur-timebase
> b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
> new file mode 100644
> index 0000000000..185dcc0aab
> --- /dev/null
> +++ b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
> @@ -0,0 +1 @@
> +349d78698cc1226d33d4e6699dbf46d9
> --
> 2.17.1
>
>
Test file attached.
Jun Li Oct. 9, 2019, 10:42 p.m. UTC | #2
On Mon, Oct 7, 2019 at 6:36 PM Jun Li <junli1026@gmail.com> wrote:

>
>
> On Mon, Oct 7, 2019 at 6:34 PM Jun Li <junli1026@gmail.com> wrote:
>
>> Fix #7637
>> One empty/end sample is created and inserted between two caption lines
>> when there is a gap.
>> This patch is to split the sample into multiple ones when its duration is
>> too long (>= INT_MAX)
>>
>> Signed-off-by: Jun Li <junli1026@gmail.com>
>> ---
>>  libavformat/movenc.c                          | 26 ++++++++++++++-----
>>  tests/fate/subtitles.mak                      |  6 +++++
>>  tests/ref/fate/binsub-movtextenc-long-dur     |  1 +
>>  .../fate/binsub-movtextenc-long-dur-timebase  |  1 +
>>  4 files changed, 28 insertions(+), 6 deletions(-)
>>  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur
>>  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>
>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
>> index 715bec1c2f..5dc2a19c3c 100644
>> --- a/libavformat/movenc.c
>> +++ b/libavformat/movenc.c
>> @@ -5750,7 +5750,8 @@ static int mov_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>>           *
>>           * 2) For each subtitle track, check if the current packet's
>>           * dts is past the duration of the last subtitle sample. If
>> -         * so, we now need to write an end sample for that subtitle.
>> +         * so, we now need to write one or multiple end samples for
>> +         * that subtitle.
>>           *
>>           * This must be done conditionally to allow for subtitles that
>>           * immediately replace each other, in which case an end sample
>> @@ -5764,11 +5765,24 @@ static int mov_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>>              int ret;
>>
>>              if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT &&
>> -                trk->track_duration < pkt->dts &&
>> -                (trk->entry == 0 || !trk->last_sample_is_subtitle_end)) {
>> -                ret = mov_write_subtitle_end_packet(s, i,
>> trk->track_duration);
>> -                if (ret < 0) return ret;
>> -                trk->last_sample_is_subtitle_end = 1;
>> +                trk->track_duration < pkt->dts) {
>> +                int max_duration = INT_MAX - 1;
>> +                if (trk->entry == 0 ||
>> !trk->last_sample_is_subtitle_end) {
>> +                    ret = mov_write_subtitle_end_packet(s, i,
>> trk->track_duration);
>> +                    if (ret < 0)
>> +                        return ret;
>> +                    trk->last_sample_is_subtitle_end = 1;
>> +                }
>> +                if (trk->last_sample_is_subtitle_end &&
>> +                    pkt->dts - trk->track_duration > max_duration) {
>> +                    int64_t dts = trk->track_duration;
>> +                    while(pkt->dts - dts > max_duration) {
>> +                        dts += max_duration;
>> +                        ret = mov_write_subtitle_end_packet(s, i, dts);
>> +                        if (ret < 0)
>> +                            return ret;
>> +                    }
>> +                }
>>              }
>>          }
>>
>> diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
>> index 0042902161..4c2b34c431 100644
>> --- a/tests/fate/subtitles.mak
>> +++ b/tests/fate/subtitles.mak
>> @@ -34,6 +34,12 @@ fate-sub-movtext: CMD = fmtstdout ass -i
>> $(TARGET_SAMPLES)/sub/MovText_capabilit
>>  FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc
>>  fate-binsub-movtextenc: CMD = md5 -i
>> $(TARGET_SAMPLES)/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text
>> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>>
>> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
>> fate-binsub-movtextenc-long-dur
>> +fate-binsub-movtextenc-long-dur: CMD = md5 -i
>> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
>> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>> +
>> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
>> fate-binsub-movtextenc-long-dur-timebase
>> +fate-binsub-movtextenc-long-dur-timebase: CMD = md5 -i
>> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
>> -time_base 1000 -f mp4 -flags +bitexact -fflags +bitexact -movflags
>> frag_keyframe+empty_moov
>> +
>>  FATE_SUBTITLES_ASS-$(call DEMDEC, MPL2, MPL2) += fate-sub-mpl2
>>  fate-sub-mpl2: CMD = fmtstdout ass -i
>> $(TARGET_SAMPLES)/sub/MPL2_capability_tester.txt
>>
>> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur
>> b/tests/ref/fate/binsub-movtextenc-long-dur
>> new file mode 100644
>> index 0000000000..eb8a3f8fc7
>> --- /dev/null
>> +++ b/tests/ref/fate/binsub-movtextenc-long-dur
>> @@ -0,0 +1 @@
>> +7f78c11bb4a6b16335540ef31ba10219
>> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>> b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>> new file mode 100644
>> index 0000000000..185dcc0aab
>> --- /dev/null
>> +++ b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>> @@ -0,0 +1 @@
>> +349d78698cc1226d33d4e6699dbf46d9
>> --
>> 2.17.1
>>
>>
> Test file attached.
>

Ping
Jun Li Oct. 18, 2019, 6:56 p.m. UTC | #3
On Wed, Oct 9, 2019 at 3:42 PM Jun Li <junli1026@gmail.com> wrote:

>
>
> On Mon, Oct 7, 2019 at 6:36 PM Jun Li <junli1026@gmail.com> wrote:
>
>>
>>
>> On Mon, Oct 7, 2019 at 6:34 PM Jun Li <junli1026@gmail.com> wrote:
>>
>>> Fix #7637
>>> One empty/end sample is created and inserted between two caption lines
>>> when there is a gap.
>>> This patch is to split the sample into multiple ones when its duration
>>> is too long (>= INT_MAX)
>>>
>>> Signed-off-by: Jun Li <junli1026@gmail.com>
>>> ---
>>>  libavformat/movenc.c                          | 26 ++++++++++++++-----
>>>  tests/fate/subtitles.mak                      |  6 +++++
>>>  tests/ref/fate/binsub-movtextenc-long-dur     |  1 +
>>>  .../fate/binsub-movtextenc-long-dur-timebase  |  1 +
>>>  4 files changed, 28 insertions(+), 6 deletions(-)
>>>  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur
>>>  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>
>>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
>>> index 715bec1c2f..5dc2a19c3c 100644
>>> --- a/libavformat/movenc.c
>>> +++ b/libavformat/movenc.c
>>> @@ -5750,7 +5750,8 @@ static int mov_write_packet(AVFormatContext *s,
>>> AVPacket *pkt)
>>>           *
>>>           * 2) For each subtitle track, check if the current packet's
>>>           * dts is past the duration of the last subtitle sample. If
>>> -         * so, we now need to write an end sample for that subtitle.
>>> +         * so, we now need to write one or multiple end samples for
>>> +         * that subtitle.
>>>           *
>>>           * This must be done conditionally to allow for subtitles that
>>>           * immediately replace each other, in which case an end sample
>>> @@ -5764,11 +5765,24 @@ static int mov_write_packet(AVFormatContext *s,
>>> AVPacket *pkt)
>>>              int ret;
>>>
>>>              if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT &&
>>> -                trk->track_duration < pkt->dts &&
>>> -                (trk->entry == 0 || !trk->last_sample_is_subtitle_end))
>>> {
>>> -                ret = mov_write_subtitle_end_packet(s, i,
>>> trk->track_duration);
>>> -                if (ret < 0) return ret;
>>> -                trk->last_sample_is_subtitle_end = 1;
>>> +                trk->track_duration < pkt->dts) {
>>> +                int max_duration = INT_MAX - 1;
>>> +                if (trk->entry == 0 ||
>>> !trk->last_sample_is_subtitle_end) {
>>> +                    ret = mov_write_subtitle_end_packet(s, i,
>>> trk->track_duration);
>>> +                    if (ret < 0)
>>> +                        return ret;
>>> +                    trk->last_sample_is_subtitle_end = 1;
>>> +                }
>>> +                if (trk->last_sample_is_subtitle_end &&
>>> +                    pkt->dts - trk->track_duration > max_duration) {
>>> +                    int64_t dts = trk->track_duration;
>>> +                    while(pkt->dts - dts > max_duration) {
>>> +                        dts += max_duration;
>>> +                        ret = mov_write_subtitle_end_packet(s, i, dts);
>>> +                        if (ret < 0)
>>> +                            return ret;
>>> +                    }
>>> +                }
>>>              }
>>>          }
>>>
>>> diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
>>> index 0042902161..4c2b34c431 100644
>>> --- a/tests/fate/subtitles.mak
>>> +++ b/tests/fate/subtitles.mak
>>> @@ -34,6 +34,12 @@ fate-sub-movtext: CMD = fmtstdout ass -i
>>> $(TARGET_SAMPLES)/sub/MovText_capabilit
>>>  FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc
>>>  fate-binsub-movtextenc: CMD = md5 -i
>>> $(TARGET_SAMPLES)/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text
>>> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>>>
>>> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
>>> fate-binsub-movtextenc-long-dur
>>> +fate-binsub-movtextenc-long-dur: CMD = md5 -i
>>> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
>>> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>>> +
>>> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
>>> fate-binsub-movtextenc-long-dur-timebase
>>> +fate-binsub-movtextenc-long-dur-timebase: CMD = md5 -i
>>> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
>>> -time_base 1000 -f mp4 -flags +bitexact -fflags +bitexact -movflags
>>> frag_keyframe+empty_moov
>>> +
>>>  FATE_SUBTITLES_ASS-$(call DEMDEC, MPL2, MPL2) += fate-sub-mpl2
>>>  fate-sub-mpl2: CMD = fmtstdout ass -i
>>> $(TARGET_SAMPLES)/sub/MPL2_capability_tester.txt
>>>
>>> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur
>>> b/tests/ref/fate/binsub-movtextenc-long-dur
>>> new file mode 100644
>>> index 0000000000..eb8a3f8fc7
>>> --- /dev/null
>>> +++ b/tests/ref/fate/binsub-movtextenc-long-dur
>>> @@ -0,0 +1 @@
>>> +7f78c11bb4a6b16335540ef31ba10219
>>> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>> b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>> new file mode 100644
>>> index 0000000000..185dcc0aab
>>> --- /dev/null
>>> +++ b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>> @@ -0,0 +1 @@
>>> +349d78698cc1226d33d4e6699dbf46d9
>>> --
>>> 2.17.1
>>>
>>>
>> Test file attached.
>>
>
> Ping
>

PingX2
Jun Li Oct. 25, 2019, 2:34 a.m. UTC | #4
On Fri, Oct 18, 2019 at 11:56 AM Jun Li <junli1026@gmail.com> wrote:

>
>
> On Wed, Oct 9, 2019 at 3:42 PM Jun Li <junli1026@gmail.com> wrote:
>
>>
>>
>> On Mon, Oct 7, 2019 at 6:36 PM Jun Li <junli1026@gmail.com> wrote:
>>
>>>
>>>
>>> On Mon, Oct 7, 2019 at 6:34 PM Jun Li <junli1026@gmail.com> wrote:
>>>
>>>> Fix #7637
>>>> One empty/end sample is created and inserted between two caption lines
>>>> when there is a gap.
>>>> This patch is to split the sample into multiple ones when its duration
>>>> is too long (>= INT_MAX)
>>>>
>>>> Signed-off-by: Jun Li <junli1026@gmail.com>
>>>> ---
>>>>  libavformat/movenc.c                          | 26 ++++++++++++++-----
>>>>  tests/fate/subtitles.mak                      |  6 +++++
>>>>  tests/ref/fate/binsub-movtextenc-long-dur     |  1 +
>>>>  .../fate/binsub-movtextenc-long-dur-timebase  |  1 +
>>>>  4 files changed, 28 insertions(+), 6 deletions(-)
>>>>  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur
>>>>  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>>
>>>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
>>>> index 715bec1c2f..5dc2a19c3c 100644
>>>> --- a/libavformat/movenc.c
>>>> +++ b/libavformat/movenc.c
>>>> @@ -5750,7 +5750,8 @@ static int mov_write_packet(AVFormatContext *s,
>>>> AVPacket *pkt)
>>>>           *
>>>>           * 2) For each subtitle track, check if the current packet's
>>>>           * dts is past the duration of the last subtitle sample. If
>>>> -         * so, we now need to write an end sample for that subtitle.
>>>> +         * so, we now need to write one or multiple end samples for
>>>> +         * that subtitle.
>>>>           *
>>>>           * This must be done conditionally to allow for subtitles that
>>>>           * immediately replace each other, in which case an end sample
>>>> @@ -5764,11 +5765,24 @@ static int mov_write_packet(AVFormatContext *s,
>>>> AVPacket *pkt)
>>>>              int ret;
>>>>
>>>>              if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT &&
>>>> -                trk->track_duration < pkt->dts &&
>>>> -                (trk->entry == 0 ||
>>>> !trk->last_sample_is_subtitle_end)) {
>>>> -                ret = mov_write_subtitle_end_packet(s, i,
>>>> trk->track_duration);
>>>> -                if (ret < 0) return ret;
>>>> -                trk->last_sample_is_subtitle_end = 1;
>>>> +                trk->track_duration < pkt->dts) {
>>>> +                int max_duration = INT_MAX - 1;
>>>> +                if (trk->entry == 0 ||
>>>> !trk->last_sample_is_subtitle_end) {
>>>> +                    ret = mov_write_subtitle_end_packet(s, i,
>>>> trk->track_duration);
>>>> +                    if (ret < 0)
>>>> +                        return ret;
>>>> +                    trk->last_sample_is_subtitle_end = 1;
>>>> +                }
>>>> +                if (trk->last_sample_is_subtitle_end &&
>>>> +                    pkt->dts - trk->track_duration > max_duration) {
>>>> +                    int64_t dts = trk->track_duration;
>>>> +                    while(pkt->dts - dts > max_duration) {
>>>> +                        dts += max_duration;
>>>> +                        ret = mov_write_subtitle_end_packet(s, i, dts);
>>>> +                        if (ret < 0)
>>>> +                            return ret;
>>>> +                    }
>>>> +                }
>>>>              }
>>>>          }
>>>>
>>>> diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
>>>> index 0042902161..4c2b34c431 100644
>>>> --- a/tests/fate/subtitles.mak
>>>> +++ b/tests/fate/subtitles.mak
>>>> @@ -34,6 +34,12 @@ fate-sub-movtext: CMD = fmtstdout ass -i
>>>> $(TARGET_SAMPLES)/sub/MovText_capabilit
>>>>  FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc
>>>>  fate-binsub-movtextenc: CMD = md5 -i
>>>> $(TARGET_SAMPLES)/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text
>>>> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>>>>
>>>> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
>>>> fate-binsub-movtextenc-long-dur
>>>> +fate-binsub-movtextenc-long-dur: CMD = md5 -i
>>>> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
>>>> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>>>> +
>>>> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
>>>> fate-binsub-movtextenc-long-dur-timebase
>>>> +fate-binsub-movtextenc-long-dur-timebase: CMD = md5 -i
>>>> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
>>>> -time_base 1000 -f mp4 -flags +bitexact -fflags +bitexact -movflags
>>>> frag_keyframe+empty_moov
>>>> +
>>>>  FATE_SUBTITLES_ASS-$(call DEMDEC, MPL2, MPL2) += fate-sub-mpl2
>>>>  fate-sub-mpl2: CMD = fmtstdout ass -i
>>>> $(TARGET_SAMPLES)/sub/MPL2_capability_tester.txt
>>>>
>>>> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur
>>>> b/tests/ref/fate/binsub-movtextenc-long-dur
>>>> new file mode 100644
>>>> index 0000000000..eb8a3f8fc7
>>>> --- /dev/null
>>>> +++ b/tests/ref/fate/binsub-movtextenc-long-dur
>>>> @@ -0,0 +1 @@
>>>> +7f78c11bb4a6b16335540ef31ba10219
>>>> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>> b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>> new file mode 100644
>>>> index 0000000000..185dcc0aab
>>>> --- /dev/null
>>>> +++ b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>> @@ -0,0 +1 @@
>>>> +349d78698cc1226d33d4e6699dbf46d9
>>>> --
>>>> 2.17.1
>>>>
>>>>
>>> Test file attached.
>>>
>>
>> Ping
>>
>
> PingX2
>

Pingx3
Liu Steven Oct. 25, 2019, 4:28 a.m. UTC | #5
> 在 2019年10月25日,上午10:34,Jun Li <junli1026@gmail.com> 写道:
> 
> On Fri, Oct 18, 2019 at 11:56 AM Jun Li <junli1026@gmail.com> wrote:
> 
>> 
>> 
>> On Wed, Oct 9, 2019 at 3:42 PM Jun Li <junli1026@gmail.com> wrote:
>> 
>>> 
>>> 
>>> On Mon, Oct 7, 2019 at 6:36 PM Jun Li <junli1026@gmail.com> wrote:
>>> 
>>>> 
>>>> 
>>>> On Mon, Oct 7, 2019 at 6:34 PM Jun Li <junli1026@gmail.com> wrote:
>>>> 
>>>>> Fix #7637
>>>>> One empty/end sample is created and inserted between two caption lines
>>>>> when there is a gap.
>>>>> This patch is to split the sample into multiple ones when its duration
>>>>> is too long (>= INT_MAX)
>>>>> 
>>>>> Signed-off-by: Jun Li <junli1026@gmail.com>
>>>>> ---
>>>>> libavformat/movenc.c                          | 26 ++++++++++++++-----
>>>>> tests/fate/subtitles.mak                      |  6 +++++
>>>>> tests/ref/fate/binsub-movtextenc-long-dur     |  1 +
>>>>> .../fate/binsub-movtextenc-long-dur-timebase  |  1 +
>>>>> 4 files changed, 28 insertions(+), 6 deletions(-)
>>>>> create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur
>>>>> create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>>> 
>>>>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
>>>>> index 715bec1c2f..5dc2a19c3c 100644
>>>>> --- a/libavformat/movenc.c
>>>>> +++ b/libavformat/movenc.c
>>>>> @@ -5750,7 +5750,8 @@ static int mov_write_packet(AVFormatContext *s,
>>>>> AVPacket *pkt)
>>>>>          *
>>>>>          * 2) For each subtitle track, check if the current packet's
>>>>>          * dts is past the duration of the last subtitle sample. If
>>>>> -         * so, we now need to write an end sample for that subtitle.
>>>>> +         * so, we now need to write one or multiple end samples for
>>>>> +         * that subtitle.
>>>>>          *
>>>>>          * This must be done conditionally to allow for subtitles that
>>>>>          * immediately replace each other, in which case an end sample
>>>>> @@ -5764,11 +5765,24 @@ static int mov_write_packet(AVFormatContext *s,
>>>>> AVPacket *pkt)
>>>>>             int ret;
>>>>> 
>>>>>             if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT &&
>>>>> -                trk->track_duration < pkt->dts &&
>>>>> -                (trk->entry == 0 ||
>>>>> !trk->last_sample_is_subtitle_end)) {
>>>>> -                ret = mov_write_subtitle_end_packet(s, i,
>>>>> trk->track_duration);
>>>>> -                if (ret < 0) return ret;
>>>>> -                trk->last_sample_is_subtitle_end = 1;
>>>>> +                trk->track_duration < pkt->dts) {
>>>>> +                int max_duration = INT_MAX - 1;
>>>>> +                if (trk->entry == 0 ||
>>>>> !trk->last_sample_is_subtitle_end) {
>>>>> +                    ret = mov_write_subtitle_end_packet(s, i,
>>>>> trk->track_duration);
>>>>> +                    if (ret < 0)
>>>>> +                        return ret;
>>>>> +                    trk->last_sample_is_subtitle_end = 1;
>>>>> +                }
>>>>> +                if (trk->last_sample_is_subtitle_end &&
>>>>> +                    pkt->dts - trk->track_duration > max_duration) {
>>>>> +                    int64_t dts = trk->track_duration;
>>>>> +                    while(pkt->dts - dts > max_duration) {
>>>>> +                        dts += max_duration;
>>>>> +                        ret = mov_write_subtitle_end_packet(s, i, dts);
>>>>> +                        if (ret < 0)
>>>>> +                            return ret;
>>>>> +                    }
>>>>> +                }
>>>>>             }
>>>>>         }
>>>>> 
>>>>> diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
>>>>> index 0042902161..4c2b34c431 100644
>>>>> --- a/tests/fate/subtitles.mak
>>>>> +++ b/tests/fate/subtitles.mak
>>>>> @@ -34,6 +34,12 @@ fate-sub-movtext: CMD = fmtstdout ass -i
>>>>> $(TARGET_SAMPLES)/sub/MovText_capabilit
>>>>> FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc
>>>>> fate-binsub-movtextenc: CMD = md5 -i
>>>>> $(TARGET_SAMPLES)/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text
>>>>> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>>>>> 
>>>>> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
>>>>> fate-binsub-movtextenc-long-dur
>>>>> +fate-binsub-movtextenc-long-dur: CMD = md5 -i
>>>>> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
>>>>> -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
>>>>> +
>>>>> +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) +=
>>>>> fate-binsub-movtextenc-long-dur-timebase
>>>>> +fate-binsub-movtextenc-long-dur-timebase: CMD = md5 -i
>>>>> $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text
>>>>> -time_base 1000 -f mp4 -flags +bitexact -fflags +bitexact -movflags
>>>>> frag_keyframe+empty_moov
>>>>> +
>>>>> FATE_SUBTITLES_ASS-$(call DEMDEC, MPL2, MPL2) += fate-sub-mpl2
>>>>> fate-sub-mpl2: CMD = fmtstdout ass -i
>>>>> $(TARGET_SAMPLES)/sub/MPL2_capability_tester.txt
>>>>> 
>>>>> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur
>>>>> b/tests/ref/fate/binsub-movtextenc-long-dur
>>>>> new file mode 100644
>>>>> index 0000000000..eb8a3f8fc7
>>>>> --- /dev/null
>>>>> +++ b/tests/ref/fate/binsub-movtextenc-long-dur
>>>>> @@ -0,0 +1 @@
>>>>> +7f78c11bb4a6b16335540ef31ba10219
>>>>> diff --git a/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>>> b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>>> new file mode 100644
>>>>> index 0000000000..185dcc0aab
>>>>> --- /dev/null
>>>>> +++ b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
>>>>> @@ -0,0 +1 @@
>>>>> +349d78698cc1226d33d4e6699dbf46d9
>>>>> --
>>>>> 2.17.1
>>>>> 
>>>>> 
>>>> Test file attached.
>>>> 
>>> 
>>> Ping
>>> 
>> 
>> PingX2
>> 
> 
> Pingx3

Wait, let me test it, and wait other reviewers’ comments :D
> _______________________________________________
> 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".
diff mbox

Patch

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 715bec1c2f..5dc2a19c3c 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -5750,7 +5750,8 @@  static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
          *
          * 2) For each subtitle track, check if the current packet's
          * dts is past the duration of the last subtitle sample. If
-         * so, we now need to write an end sample for that subtitle.
+         * so, we now need to write one or multiple end samples for
+         * that subtitle.
          *
          * This must be done conditionally to allow for subtitles that
          * immediately replace each other, in which case an end sample
@@ -5764,11 +5765,24 @@  static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
             int ret;
 
             if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT &&
-                trk->track_duration < pkt->dts &&
-                (trk->entry == 0 || !trk->last_sample_is_subtitle_end)) {
-                ret = mov_write_subtitle_end_packet(s, i, trk->track_duration);
-                if (ret < 0) return ret;
-                trk->last_sample_is_subtitle_end = 1;
+                trk->track_duration < pkt->dts) {
+                int max_duration = INT_MAX - 1;
+                if (trk->entry == 0 || !trk->last_sample_is_subtitle_end) {
+                    ret = mov_write_subtitle_end_packet(s, i, trk->track_duration);
+                    if (ret < 0)
+                        return ret;
+                    trk->last_sample_is_subtitle_end = 1;
+                }
+                if (trk->last_sample_is_subtitle_end &&
+                    pkt->dts - trk->track_duration > max_duration) {
+                    int64_t dts = trk->track_duration;
+                    while(pkt->dts - dts > max_duration) {
+                        dts += max_duration;
+                        ret = mov_write_subtitle_end_packet(s, i, dts);
+                        if (ret < 0)
+                            return ret;
+                    }
+                }
             }
         }
 
diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
index 0042902161..4c2b34c431 100644
--- a/tests/fate/subtitles.mak
+++ b/tests/fate/subtitles.mak
@@ -34,6 +34,12 @@  fate-sub-movtext: CMD = fmtstdout ass -i $(TARGET_SAMPLES)/sub/MovText_capabilit
 FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc
 fate-binsub-movtextenc: CMD = md5 -i $(TARGET_SAMPLES)/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
 
+FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc-long-dur
+fate-binsub-movtextenc-long-dur: CMD = md5 -i $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
+
+FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc-long-dur-timebase
+fate-binsub-movtextenc-long-dur-timebase: CMD = md5 -i $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text -time_base 1000 -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov
+
 FATE_SUBTITLES_ASS-$(call DEMDEC, MPL2, MPL2) += fate-sub-mpl2
 fate-sub-mpl2: CMD = fmtstdout ass -i $(TARGET_SAMPLES)/sub/MPL2_capability_tester.txt
 
diff --git a/tests/ref/fate/binsub-movtextenc-long-dur b/tests/ref/fate/binsub-movtextenc-long-dur
new file mode 100644
index 0000000000..eb8a3f8fc7
--- /dev/null
+++ b/tests/ref/fate/binsub-movtextenc-long-dur
@@ -0,0 +1 @@ 
+7f78c11bb4a6b16335540ef31ba10219
diff --git a/tests/ref/fate/binsub-movtextenc-long-dur-timebase b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
new file mode 100644
index 0000000000..185dcc0aab
--- /dev/null
+++ b/tests/ref/fate/binsub-movtextenc-long-dur-timebase
@@ -0,0 +1 @@ 
+349d78698cc1226d33d4e6699dbf46d9