[FFmpeg-devel] [PATCH] avformat/srtenc: split write time into function for better readability

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Wed Apr 29 12:12:21 EEST 2020


lance.lmwang at gmail.com:
> From: Limin Wang <lance.lmwang at gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
> ---
>  libavformat/srtenc.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/srtenc.c b/libavformat/srtenc.c
> index d811a4da0e..ca127354ed 100644
> --- a/libavformat/srtenc.c
> +++ b/libavformat/srtenc.c
> @@ -34,6 +34,20 @@ typedef struct SRTContext{
>      unsigned index;
>  } SRTContext;
>  
> +static void srt_write_time(AVIOContext *pb, int64_t millisec)
> +{
> +    int64_t sec = millisec / 1000;
> +    int64_t min = sec / 60;
> +    int64_t hour = min / 60;;

Superfluous ';'; also, you can align on '=' (above and below).

> +
> +    millisec -= 1000 * sec;
> +    sec -= 60 * min;
> +    min -= 60 * hour;
> +> +    avio_printf(pb, "%02"PRId64":%02"PRId64":%02"PRId64",%03"PRId64"",
> +            hour, min, sec, millisec);

hour should be left-aligned with pb.

> +}
> +
>  static int srt_write_header(AVFormatContext *avf)
>  {
>      SRTContext *srt = avf->priv_data;
> @@ -85,12 +99,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          return 0;
>      }
>      e = s + d;
> -    avio_printf(avf->pb, "%d\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d",
> -                   srt->index,
> -                   (int)(s / 3600000),      (int)(s / 60000) % 60,
> -                   (int)(s /    1000) % 60, (int)(s %  1000),
> -                   (int)(e / 3600000),      (int)(e / 60000) % 60,
> -                   (int)(e /    1000) % 60, (int)(e %  1000));
> +    avio_printf(avf->pb, "%d\n", srt->index);
> +    srt_write_time(avf->pb, s);
> +    avio_printf(avf->pb, " --> ");
> +    srt_write_time(avf->pb, e);
>      if (p)
>          avio_printf(avf->pb, "  X1:%03d X2:%03d Y1:%03d Y2:%03d",
>                      x1, x2, y1, y2);
> 



More information about the ffmpeg-devel mailing list