[FFmpeg-devel] [PATCH 2/3] lavf/srtenc: do not print more line breaks than necessary.

Clément Bœsch ubitux at gmail.com
Sun Oct 21 20:26:46 CEST 2012


On Sun, Oct 21, 2012 at 03:29:07AM +0200, Clément Bœsch wrote:
> ---
>  libavformat/srtenc.c         | 12 ++++++++++--
>  tests/ref/fate/sub-subripenc |  2 +-
>  2 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/srtenc.c b/libavformat/srtenc.c
> index 42a264e..d92f559 100644
> --- a/libavformat/srtenc.c
> +++ b/libavformat/srtenc.c
> @@ -78,8 +78,16 @@ static int srt_write_packet(AVFormatContext *avf, AVPacket *pkt)
>                         (int)(e /    1000) % 60, (int)(e %  1000));
>      }
>      avio_write(avf->pb, pkt->data, pkt->size);
> -    if (write_ts)
> -        avio_write(avf->pb, "\n\n", 2);
> +    if (write_ts) {
> +        int i, linebreaks = 2;
> +        for (i = sizeof("\r\n\r\n") - 1; i > 0; i--) {
> +            char c = pkt->data[pkt->size - i];
> +            if (pkt->size >= i && c == '\r' || c == '\n')
> +                linebreaks -= c == '\n';
> +        }
> +        for (i = 0; i < linebreaks; i++)
> +            avio_write(avf->pb, "\n", 1);
> +    }
>      avio_flush(avf->pb);
>      return 0;
>  }
> diff --git a/tests/ref/fate/sub-subripenc b/tests/ref/fate/sub-subripenc
> index 7daa4f5..4e459a5 100644
> --- a/tests/ref/fate/sub-subripenc
> +++ b/tests/ref/fate/sub-subripenc
> @@ -1 +1 @@
> -bd520f85238abf9df292374aed54681a
> +c376f926f375df897898d147eb0ace0c

Just FYI: the test here changes because multiple \n at the end are
stripped.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121021/8421dc5a/attachment.asc>


More information about the ffmpeg-devel mailing list