[FFmpeg-devel] [PATCH] avcodec/mov: Allocate skipped_bytes_pos with av_realloc.

2017-08-31 Thread Mark Wachsler
Memory reallocated with av_reallocp_array is supposed to be allocated
with av_realloc, not av_malloc.
---
 libavcodec/h2645_parse.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index b0d9ff66f0..1b2534b2e6 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -318,7 +318,8 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t 
*buf, int length,
 
 nal = &pkt->nals[pkt->nb_nals];
 nal->skipped_bytes_pos_size = 1024; // initial buffer size
-nal->skipped_bytes_pos = 
av_malloc_array(nal->skipped_bytes_pos_size, sizeof(*nal->skipped_bytes_pos));
+nal->skipped_bytes_pos = av_realloc(NULL, 
nal->skipped_bytes_pos_size *
+   
sizeof(*nal->skipped_bytes_pos));
 if (!nal->skipped_bytes_pos)
 return AVERROR(ENOMEM);
 
-- 
2.14.1.581.gf28d330327-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] libavcodec/h264_parse: don't use uninitialized value when chroma_format_idc==0

2017-09-01 Thread Mark Wachsler
When parsing a monochrome file, chroma_log2_weight_denom was used without
being initialized, which could lead to a bogus error message being printed, e.g.
  [h264 @ 0x61a26480] chroma_log2_weight_denom 24576 is out of range
It also could result in warnings using AddressSanitizer.
---
 libavcodec/h264_parse.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 3d20075f6a..d9a3a0c154 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -34,21 +34,22 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS 
*sps,
 
 pwt->use_weight = 0;
 pwt->use_weight_chroma  = 0;
-pwt->luma_log2_weight_denom = get_ue_golomb(gb);
-if (sps->chroma_format_idc)
-pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
 
+pwt->luma_log2_weight_denom = get_ue_golomb(gb);
 if (pwt->luma_log2_weight_denom > 7U) {
 av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of 
range\n", pwt->luma_log2_weight_denom);
 pwt->luma_log2_weight_denom = 0;
 }
-if (pwt->chroma_log2_weight_denom > 7U) {
-av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of 
range\n", pwt->chroma_log2_weight_denom);
-pwt->chroma_log2_weight_denom = 0;
-}
+luma_def = 1 << pwt->luma_log2_weight_denom;
 
-luma_def   = 1 << pwt->luma_log2_weight_denom;
-chroma_def = 1 << pwt->chroma_log2_weight_denom;
+if (sps->chroma_format_idc) {
+pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
+if (pwt->chroma_log2_weight_denom > 7U) {
+av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out 
of range\n", pwt->chroma_log2_weight_denom);
+pwt->chroma_log2_weight_denom = 0;
+}
+chroma_def = 1 << pwt->chroma_log2_weight_denom;
+}
 
 for (list = 0; list < 2; list++) {
 pwt->luma_weight_flag[list]   = 0;
-- 
2.14.1.581.gf28d330327-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] libavcodec/h264_parse: don't use uninitialized value when chroma_format_idc==0

2017-09-07 Thread Mark Wachsler
When parsing a monochrome file, chroma_log2_weight_denom was used without
being initialized, which could lead to a bogus error message being printed, e.g.
  [h264 @ 0x61a26480] chroma_log2_weight_denom 24576 is out of range
It also could led to warnings using AddressSanitizer.
---
 libavcodec/h264_parse.c | 27 +++
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 3d20075f6a..a7c71d9bbb 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -34,21 +34,22 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS 
*sps,
 
 pwt->use_weight = 0;
 pwt->use_weight_chroma  = 0;
-pwt->luma_log2_weight_denom = get_ue_golomb(gb);
-if (sps->chroma_format_idc)
-pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
 
+pwt->luma_log2_weight_denom = get_ue_golomb(gb);
 if (pwt->luma_log2_weight_denom > 7U) {
 av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of 
range\n", pwt->luma_log2_weight_denom);
 pwt->luma_log2_weight_denom = 0;
 }
-if (pwt->chroma_log2_weight_denom > 7U) {
-av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of 
range\n", pwt->chroma_log2_weight_denom);
-pwt->chroma_log2_weight_denom = 0;
-}
+luma_def = 1 << pwt->luma_log2_weight_denom;
 
-luma_def   = 1 << pwt->luma_log2_weight_denom;
-chroma_def = 1 << pwt->chroma_log2_weight_denom;
+if (sps->chroma_format_idc) {
+pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
+if (pwt->chroma_log2_weight_denom > 7U) {
+av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out 
of range\n", pwt->chroma_log2_weight_denom);
+pwt->chroma_log2_weight_denom = 0;
+}
+chroma_def = 1 << pwt->chroma_log2_weight_denom;
+}
 
 for (list = 0; list < 2; list++) {
 pwt->luma_weight_flag[list]   = 0;
@@ -102,9 +103,11 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS 
*sps,
 if (picture_structure == PICT_FRAME) {
 pwt->luma_weight[16 + 2 * i][list][0] = pwt->luma_weight[16 + 
2 * i + 1][list][0] = pwt->luma_weight[i][list][0];
 pwt->luma_weight[16 + 2 * i][list][1] = pwt->luma_weight[16 + 
2 * i + 1][list][1] = pwt->luma_weight[i][list][1];
-for (j = 0; j < 2; j++) {
-pwt->chroma_weight[16 + 2 * i][list][j][0] = 
pwt->chroma_weight[16 + 2 * i + 1][list][j][0] = 
pwt->chroma_weight[i][list][j][0];
-pwt->chroma_weight[16 + 2 * i][list][j][1] = 
pwt->chroma_weight[16 + 2 * i + 1][list][j][1] = 
pwt->chroma_weight[i][list][j][1];
+if (sps->chroma_format_idc) {
+for (j = 0; j < 2; j++) {
+pwt->chroma_weight[16 + 2 * i][list][j][0] = 
pwt->chroma_weight[16 + 2 * i + 1][list][j][0] = 
pwt->chroma_weight[i][list][j][0];
+pwt->chroma_weight[16 + 2 * i][list][j][1] = 
pwt->chroma_weight[16 + 2 * i + 1][list][j][1] = 
pwt->chroma_weight[i][list][j][1];
+}
 }
 }
 }
-- 
2.14.1.581.gf28d330327-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavcodec/h264_parse: don't use uninitialized value when chroma_format_idc==0

2017-09-07 Thread Mark Wachsler
I have updated my patch to also fix the references to chroma_weight in the
MBAFF case, as suggested by Mark Thompson, but without erroring out on
invalid values.

On Thu, Sep 7, 2017 at 9:42 AM, Mark Wachsler  wrote:

> When parsing a monochrome file, chroma_log2_weight_denom was used without
> being initialized, which could lead to a bogus error message being
> printed, e.g.
>   [h264 @ 0x61a26480] chroma_log2_weight_denom 24576 is out of range
> It also could led to warnings using AddressSanitizer.
> ---
>  libavcodec/h264_parse.c | 27 +++
>  1 file changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
> index 3d20075f6a..a7c71d9bbb 100644
> --- a/libavcodec/h264_parse.c
> +++ b/libavcodec/h264_parse.c
> @@ -34,21 +34,22 @@ int ff_h264_pred_weight_table(GetBitContext *gb,
> const SPS *sps,
>
>  pwt->use_weight = 0;
>  pwt->use_weight_chroma  = 0;
> -pwt->luma_log2_weight_denom = get_ue_golomb(gb);
> -if (sps->chroma_format_idc)
> -pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
>
> +pwt->luma_log2_weight_denom = get_ue_golomb(gb);
>  if (pwt->luma_log2_weight_denom > 7U) {
>  av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of
> range\n", pwt->luma_log2_weight_denom);
>  pwt->luma_log2_weight_denom = 0;
>  }
> -if (pwt->chroma_log2_weight_denom > 7U) {
> -av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out
> of range\n", pwt->chroma_log2_weight_denom);
> -pwt->chroma_log2_weight_denom = 0;
> -}
> +luma_def = 1 << pwt->luma_log2_weight_denom;
>
> -luma_def   = 1 << pwt->luma_log2_weight_denom;
> -chroma_def = 1 << pwt->chroma_log2_weight_denom;
> +if (sps->chroma_format_idc) {
> +pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
> +if (pwt->chroma_log2_weight_denom > 7U) {
> +av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is
> out of range\n", pwt->chroma_log2_weight_denom);
> +pwt->chroma_log2_weight_denom = 0;
> +}
> +chroma_def = 1 << pwt->chroma_log2_weight_denom;
> +}
>
>  for (list = 0; list < 2; list++) {
>  pwt->luma_weight_flag[list]   = 0;
> @@ -102,9 +103,11 @@ int ff_h264_pred_weight_table(GetBitContext *gb,
> const SPS *sps,
>  if (picture_structure == PICT_FRAME) {
>  pwt->luma_weight[16 + 2 * i][list][0] =
> pwt->luma_weight[16 + 2 * i + 1][list][0] = pwt->luma_weight[i][list][0];
>  pwt->luma_weight[16 + 2 * i][list][1] =
> pwt->luma_weight[16 + 2 * i + 1][list][1] = pwt->luma_weight[i][list][1];
> -for (j = 0; j < 2; j++) {
> -pwt->chroma_weight[16 + 2 * i][list][j][0] =
> pwt->chroma_weight[16 + 2 * i + 1][list][j][0] =
> pwt->chroma_weight[i][list][j][0];
> -pwt->chroma_weight[16 + 2 * i][list][j][1] =
> pwt->chroma_weight[16 + 2 * i + 1][list][j][1] =
> pwt->chroma_weight[i][list][j][1];
> +if (sps->chroma_format_idc) {
> +for (j = 0; j < 2; j++) {
> +pwt->chroma_weight[16 + 2 * i][list][j][0] =
> pwt->chroma_weight[16 + 2 * i + 1][list][j][0] =
> pwt->chroma_weight[i][list][j][0];
> +pwt->chroma_weight[16 + 2 * i][list][j][1] =
> pwt->chroma_weight[16 + 2 * i + 1][list][j][1] =
> pwt->chroma_weight[i][list][j][1];
> +}
>  }
>  }
>  }
> --
> 2.14.1.581.gf28d330327-goog
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] Add system and real time to benchmarking.

2018-04-20 Thread Mark Wachsler
The -benchmark and -benchmark_all options now show user, system, and real time,
instead of just user time.
---
 fftools/ffmpeg.c | 50 ++--
 1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 4dbe72186d..d37171d567 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -120,8 +120,14 @@ const char *const forced_keyframes_const_names[] = {
 NULL
 };
 
+typedef struct TimeStamps {
+  int64_t real_usec;
+  int64_t user_usec;
+  int64_t sys_usec;
+} TimeStamps;
+
 static void do_video_stats(OutputStream *ost, int frame_size);
-static int64_t getutime(void);
+static TimeStamps get_time_stamps(void);
 static int64_t getmaxrss(void);
 static int ifilter_has_all_input_formats(FilterGraph *fg);
 
@@ -133,7 +139,7 @@ static int64_t decode_error_stat[2];
 
 static int want_sdp = 1;
 
-static int current_time;
+static TimeStamps current_time;
 AVIOContext *progress_avio = NULL;
 
 static uint8_t *subtitle_out;
@@ -653,7 +659,7 @@ static void abort_codec_experimental(AVCodec *c, int 
encoder)
 static void update_benchmark(const char *fmt, ...)
 {
 if (do_benchmark_all) {
-int64_t t = getutime();
+TimeStamps t = get_time_stamps();
 va_list va;
 char buf[1024];
 
@@ -661,7 +667,11 @@ static void update_benchmark(const char *fmt, ...)
 va_start(va, fmt);
 vsnprintf(buf, sizeof(buf), fmt, va);
 va_end(va);
-av_log(NULL, AV_LOG_INFO, "bench: %8"PRIu64" %s \n", t - 
current_time, buf);
+av_log(NULL, AV_LOG_INFO,
+   "bench: %8" PRIu64 " user %8" PRIu64 " sys %8" PRIu64 " 
real %s \n",
+   t.user_usec - current_time.user_usec,
+   t.sys_usec - current_time.sys_usec,
+   t.real_usec - current_time.real_usec, buf);
 }
 current_time = t;
 }
@@ -4715,23 +4725,30 @@ static int transcode(void)
 return ret;
 }
 
-
-static int64_t getutime(void)
-{
+static TimeStamps get_time_stamps(void) {
+  TimeStamps time_stamps;
+  time_stamps.real_usec = av_gettime_relative();
 #if HAVE_GETRUSAGE
 struct rusage rusage;
 
 getrusage(RUSAGE_SELF, &rusage);
-return (rusage.ru_utime.tv_sec * 100LL) + rusage.ru_utime.tv_usec;
+time_stamps.user_usec =
+(rusage.ru_utime.tv_sec * 100LL) + rusage.ru_utime.tv_usec;
+time_stamps.sys_usec =
+(rusage.ru_stime.tv_sec * 100LL) + rusage.ru_stime.tv_usec;
 #elif HAVE_GETPROCESSTIMES
 HANDLE proc;
 FILETIME c, e, k, u;
 proc = GetCurrentProcess();
 GetProcessTimes(proc, &c, &e, &k, &u);
-return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
+time_stamps.user_usec =
+((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
+time_stamps.sys_usec =
+((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
 #else
-return av_gettime_relative();
+time_stamps.user_usec = time_stamps.sys_usec = 0;
 #endif
+return time_stamps;
 }
 
 static int64_t getmaxrss(void)
@@ -4759,7 +4776,7 @@ static void log_callback_null(void *ptr, int level, const 
char *fmt, va_list vl)
 int main(int argc, char **argv)
 {
 int i, ret;
-int64_t ti;
+TimeStamps ti;
 
 init_dynload();
 
@@ -4811,12 +4828,17 @@ int main(int argc, char **argv)
 want_sdp = 0;
 }
 
-current_time = ti = getutime();
+current_time = ti = get_time_stamps();
 if (transcode() < 0)
 exit_program(1);
-ti = getutime() - ti;
 if (do_benchmark) {
-av_log(NULL, AV_LOG_INFO, "bench: utime=%0.3fs\n", ti / 100.0);
+  current_time = get_time_stamps();
+  int64_t utime = current_time.user_usec - ti.user_usec;
+  int64_t stime = current_time.sys_usec - ti.sys_usec;
+  int64_t rtime = current_time.real_usec - ti.real_usec;
+  av_log(NULL, AV_LOG_INFO,
+ "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
+ utime / 100.0, stime / 100.0, rtime / 100.0);
 }
 av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded, 
%"PRIu64" decoding errors\n",
decode_error_stat[0], decode_error_stat[1]);
-- 
2.17.0.484.g0c8726318c-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add system and real time to benchmarking.

2018-04-23 Thread Mark Wachsler
Ping.

On Fri, Apr 20, 2018 at 4:21 PM, Mark Wachsler  wrote:

> The -benchmark and -benchmark_all options now show user, system, and real
> time,
> instead of just user time.
> ---
>  fftools/ffmpeg.c | 50 ++--
>  1 file changed, 36 insertions(+), 14 deletions(-)
>
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 4dbe72186d..d37171d567 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -120,8 +120,14 @@ const char *const forced_keyframes_const_names[] = {
>  NULL
>  };
>
> +typedef struct TimeStamps {
> +  int64_t real_usec;
> +  int64_t user_usec;
> +  int64_t sys_usec;
> +} TimeStamps;
> +
>  static void do_video_stats(OutputStream *ost, int frame_size);
> -static int64_t getutime(void);
> +static TimeStamps get_time_stamps(void);
>  static int64_t getmaxrss(void);
>  static int ifilter_has_all_input_formats(FilterGraph *fg);
>
> @@ -133,7 +139,7 @@ static int64_t decode_error_stat[2];
>
>  static int want_sdp = 1;
>
> -static int current_time;
> +static TimeStamps current_time;
>  AVIOContext *progress_avio = NULL;
>
>  static uint8_t *subtitle_out;
> @@ -653,7 +659,7 @@ static void abort_codec_experimental(AVCodec *c, int
> encoder)
>  static void update_benchmark(const char *fmt, ...)
>  {
>  if (do_benchmark_all) {
> -int64_t t = getutime();
> +TimeStamps t = get_time_stamps();
>  va_list va;
>  char buf[1024];
>
> @@ -661,7 +667,11 @@ static void update_benchmark(const char *fmt, ...)
>  va_start(va, fmt);
>  vsnprintf(buf, sizeof(buf), fmt, va);
>  va_end(va);
> -av_log(NULL, AV_LOG_INFO, "bench: %8"PRIu64" %s \n", t -
> current_time, buf);
> +av_log(NULL, AV_LOG_INFO,
> +   "bench: %8" PRIu64 " user %8" PRIu64 " sys %8" PRIu64
> " real %s \n",
> +   t.user_usec - current_time.user_usec,
> +   t.sys_usec - current_time.sys_usec,
> +   t.real_usec - current_time.real_usec, buf);
>  }
>  current_time = t;
>  }
> @@ -4715,23 +4725,30 @@ static int transcode(void)
>  return ret;
>  }
>
> -
> -static int64_t getutime(void)
> -{
> +static TimeStamps get_time_stamps(void) {
> +  TimeStamps time_stamps;
> +  time_stamps.real_usec = av_gettime_relative();
>  #if HAVE_GETRUSAGE
>  struct rusage rusage;
>
>  getrusage(RUSAGE_SELF, &rusage);
> -return (rusage.ru_utime.tv_sec * 100LL) + rusage.ru_utime.tv_usec;
> +time_stamps.user_usec =
> +(rusage.ru_utime.tv_sec * 100LL) + rusage.ru_utime.tv_usec;
> +time_stamps.sys_usec =
> +(rusage.ru_stime.tv_sec * 100LL) + rusage.ru_stime.tv_usec;
>  #elif HAVE_GETPROCESSTIMES
>  HANDLE proc;
>  FILETIME c, e, k, u;
>  proc = GetCurrentProcess();
>  GetProcessTimes(proc, &c, &e, &k, &u);
> -return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
> +time_stamps.user_usec =
> +((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
> +time_stamps.sys_usec =
> +((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
>  #else
> -return av_gettime_relative();
> +time_stamps.user_usec = time_stamps.sys_usec = 0;
>  #endif
> +return time_stamps;
>  }
>
>  static int64_t getmaxrss(void)
> @@ -4759,7 +4776,7 @@ static void log_callback_null(void *ptr, int level,
> const char *fmt, va_list vl)
>  int main(int argc, char **argv)
>  {
>  int i, ret;
> -int64_t ti;
> +TimeStamps ti;
>
>  init_dynload();
>
> @@ -4811,12 +4828,17 @@ int main(int argc, char **argv)
>  want_sdp = 0;
>  }
>
> -current_time = ti = getutime();
> +current_time = ti = get_time_stamps();
>  if (transcode() < 0)
>  exit_program(1);
> -ti = getutime() - ti;
>  if (do_benchmark) {
> -av_log(NULL, AV_LOG_INFO, "bench: utime=%0.3fs\n", ti /
> 100.0);
> +  current_time = get_time_stamps();
> +  int64_t utime = current_time.user_usec - ti.user_usec;
> +  int64_t stime = current_time.sys_usec - ti.sys_usec;
> +  int64_t rtime = current_time.real_usec - ti.real_usec;
> +  av_log(NULL, AV_LOG_INFO,
> + "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
> + utime / 100.0, stime / 100.0, rtime / 100.0);
>  }
>  av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded,
> %"PRIu64" decoding errors\n",
> decode_error_stat[0], decode_error_stat[1]);
> --
> 2.17.0.484.g0c8726318c-goog
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add system and real time to benchmarking.

2018-04-26 Thread Mark Wachsler
Friendly ping. Could someone please take a look? Thanks!

On Mon, Apr 23, 2018 at 2:29 PM, Mark Wachsler  wrote:

> Ping.
>
> On Fri, Apr 20, 2018 at 4:21 PM, Mark Wachsler 
> wrote:
>
>> The -benchmark and -benchmark_all options now show user, system, and real
>> time,
>> instead of just user time.
>> ---
>>  fftools/ffmpeg.c | 50 ++--
>>  1 file changed, 36 insertions(+), 14 deletions(-)
>>
>> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
>> index 4dbe72186d..d37171d567 100644
>> --- a/fftools/ffmpeg.c
>> +++ b/fftools/ffmpeg.c
>> @@ -120,8 +120,14 @@ const char *const forced_keyframes_const_names[] = {
>>  NULL
>>  };
>>
>> +typedef struct TimeStamps {
>> +  int64_t real_usec;
>> +  int64_t user_usec;
>> +  int64_t sys_usec;
>> +} TimeStamps;
>> +
>>  static void do_video_stats(OutputStream *ost, int frame_size);
>> -static int64_t getutime(void);
>> +static TimeStamps get_time_stamps(void);
>>  static int64_t getmaxrss(void);
>>  static int ifilter_has_all_input_formats(FilterGraph *fg);
>>
>> @@ -133,7 +139,7 @@ static int64_t decode_error_stat[2];
>>
>>  static int want_sdp = 1;
>>
>> -static int current_time;
>> +static TimeStamps current_time;
>>  AVIOContext *progress_avio = NULL;
>>
>>  static uint8_t *subtitle_out;
>> @@ -653,7 +659,7 @@ static void abort_codec_experimental(AVCodec *c, int
>> encoder)
>>  static void update_benchmark(const char *fmt, ...)
>>  {
>>  if (do_benchmark_all) {
>> -int64_t t = getutime();
>> +TimeStamps t = get_time_stamps();
>>  va_list va;
>>  char buf[1024];
>>
>> @@ -661,7 +667,11 @@ static void update_benchmark(const char *fmt, ...)
>>  va_start(va, fmt);
>>  vsnprintf(buf, sizeof(buf), fmt, va);
>>  va_end(va);
>> -av_log(NULL, AV_LOG_INFO, "bench: %8"PRIu64" %s \n", t -
>> current_time, buf);
>> +av_log(NULL, AV_LOG_INFO,
>> +   "bench: %8" PRIu64 " user %8" PRIu64 " sys %8" PRIu64
>> " real %s \n",
>> +   t.user_usec - current_time.user_usec,
>> +   t.sys_usec - current_time.sys_usec,
>> +   t.real_usec - current_time.real_usec, buf);
>>  }
>>  current_time = t;
>>  }
>> @@ -4715,23 +4725,30 @@ static int transcode(void)
>>  return ret;
>>  }
>>
>> -
>> -static int64_t getutime(void)
>> -{
>> +static TimeStamps get_time_stamps(void) {
>> +  TimeStamps time_stamps;
>> +  time_stamps.real_usec = av_gettime_relative();
>>  #if HAVE_GETRUSAGE
>>  struct rusage rusage;
>>
>>  getrusage(RUSAGE_SELF, &rusage);
>> -return (rusage.ru_utime.tv_sec * 100LL) +
>> rusage.ru_utime.tv_usec;
>> +time_stamps.user_usec =
>> +(rusage.ru_utime.tv_sec * 100LL) + rusage.ru_utime.tv_usec;
>> +time_stamps.sys_usec =
>> +(rusage.ru_stime.tv_sec * 100LL) + rusage.ru_stime.tv_usec;
>>  #elif HAVE_GETPROCESSTIMES
>>  HANDLE proc;
>>  FILETIME c, e, k, u;
>>  proc = GetCurrentProcess();
>>  GetProcessTimes(proc, &c, &e, &k, &u);
>> -return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
>> +time_stamps.user_usec =
>> +((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
>> +time_stamps.sys_usec =
>> +((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
>>  #else
>> -return av_gettime_relative();
>> +time_stamps.user_usec = time_stamps.sys_usec = 0;
>>  #endif
>> +return time_stamps;
>>  }
>>
>>  static int64_t getmaxrss(void)
>> @@ -4759,7 +4776,7 @@ static void log_callback_null(void *ptr, int level,
>> const char *fmt, va_list vl)
>>  int main(int argc, char **argv)
>>  {
>>  int i, ret;
>> -int64_t ti;
>> +TimeStamps ti;
>>
>>  init_dynload();
>>
>> @@ -4811,12 +4828,17 @@ int main(int argc, char **argv)
>>  want_sdp = 0;
>>  }
>>
>> -current_time = ti = getutime();
>> +current_time = ti = get_time_stamps();
>>  if (transcode() < 0)
>>  exit_program(1);
>> -ti = getutime() - ti;
>>  if (do_benchmark) {
>> -av_log(NULL, AV_LOG_INFO, "bench: utime=%0.3fs\n", ti /
>> 100.0);
>> +  current_time = get_time_stamps();
>> +  int64_t utime = current_time.user_usec - ti.user_usec;
>> +  int64_t stime = current_time.sys_usec - ti.sys_usec;
>> +  int64_t rtime = current_time.real_usec - ti.real_usec;
>> +  av_log(NULL, AV_LOG_INFO,
>> + "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
>> + utime / 100.0, stime / 100.0, rtime / 100.0);
>>  }
>>  av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded,
>> %"PRIu64" decoding errors\n",
>> decode_error_stat[0], decode_error_stat[1]);
>> --
>> 2.17.0.484.g0c8726318c-goog
>>
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add system and real time to benchmarking.

2018-04-26 Thread Mark Wachsler
-benchmark_all separately measures time spent encoding video, decoding
video, encoding audio, and decoding audio. You can't do that with
/usr/bin/time.

It is true that -benchmark could be replaced with /usr/bin/time, but that's
always been true. It seemed to make sense to -benchmark and -benchmark_all
continue to measure the same things.

Regards,
Mark

On Thu, Apr 26, 2018 at 12:28 PM, wm4  wrote:

> On Fri, 20 Apr 2018 16:21:13 -0400
> Mark Wachsler  wrote:
>
> > The -benchmark and -benchmark_all options now show user, system, and
> real time,
> > instead of just user time.
> > ---
> >  fftools/ffmpeg.c | 50 ++--
> >  1 file changed, 36 insertions(+), 14 deletions(-)
> >
> > diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> > index 4dbe72186d..d37171d567 100644
> > --- a/fftools/ffmpeg.c
> > +++ b/fftools/ffmpeg.c
> > @@ -120,8 +120,14 @@ const char *const forced_keyframes_const_names[] = {
> >  NULL
> >  };
> >
> > +typedef struct TimeStamps {
> > +  int64_t real_usec;
> > +  int64_t user_usec;
> > +  int64_t sys_usec;
> > +} TimeStamps;
> > +
> >  static void do_video_stats(OutputStream *ost, int frame_size);
> > -static int64_t getutime(void);
> > +static TimeStamps get_time_stamps(void);
> >  static int64_t getmaxrss(void);
> >  static int ifilter_has_all_input_formats(FilterGraph *fg);
> >
> > @@ -133,7 +139,7 @@ static int64_t decode_error_stat[2];
> >
> >  static int want_sdp = 1;
> >
> > -static int current_time;
> > +static TimeStamps current_time;
> >  AVIOContext *progress_avio = NULL;
> >
> >  static uint8_t *subtitle_out;
> > @@ -653,7 +659,7 @@ static void abort_codec_experimental(AVCodec *c,
> int encoder)
> >  static void update_benchmark(const char *fmt, ...)
> >  {
> >  if (do_benchmark_all) {
> > -int64_t t = getutime();
> > +TimeStamps t = get_time_stamps();
> >  va_list va;
> >  char buf[1024];
> >
> > @@ -661,7 +667,11 @@ static void update_benchmark(const char *fmt, ...)
> >  va_start(va, fmt);
> >  vsnprintf(buf, sizeof(buf), fmt, va);
> >  va_end(va);
> > -av_log(NULL, AV_LOG_INFO, "bench: %8"PRIu64" %s \n", t -
> current_time, buf);
> > +av_log(NULL, AV_LOG_INFO,
> > +   "bench: %8" PRIu64 " user %8" PRIu64 " sys %8"
> PRIu64 " real %s \n",
> > +   t.user_usec - current_time.user_usec,
> > +   t.sys_usec - current_time.sys_usec,
> > +   t.real_usec - current_time.real_usec, buf);
> >  }
> >  current_time = t;
> >  }
> > @@ -4715,23 +4725,30 @@ static int transcode(void)
> >  return ret;
> >  }
> >
> > -
> > -static int64_t getutime(void)
> > -{
> > +static TimeStamps get_time_stamps(void) {
> > +  TimeStamps time_stamps;
> > +  time_stamps.real_usec = av_gettime_relative();
> >  #if HAVE_GETRUSAGE
> >  struct rusage rusage;
> >
> >  getrusage(RUSAGE_SELF, &rusage);
> > -return (rusage.ru_utime.tv_sec * 100LL) +
> rusage.ru_utime.tv_usec;
> > +time_stamps.user_usec =
> > +(rusage.ru_utime.tv_sec * 100LL) + rusage.ru_utime.tv_usec;
> > +time_stamps.sys_usec =
> > +(rusage.ru_stime.tv_sec * 100LL) + rusage.ru_stime.tv_usec;
> >  #elif HAVE_GETPROCESSTIMES
> >  HANDLE proc;
> >  FILETIME c, e, k, u;
> >  proc = GetCurrentProcess();
> >  GetProcessTimes(proc, &c, &e, &k, &u);
> > -return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
> > +time_stamps.user_usec =
> > +((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
> > +time_stamps.sys_usec =
> > +((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
> >  #else
> > -return av_gettime_relative();
> > +time_stamps.user_usec = time_stamps.sys_usec = 0;
> >  #endif
> > +return time_stamps;
> >  }
> >
> >  static int64_t getmaxrss(void)
> > @@ -4759,7 +4776,7 @@ static void log_callback_null(void *ptr, int
> level, const char *fmt, va_list vl)
> >  int main(int argc, char **argv)
> >  {
> >  int i, ret;
> > -int64_t ti;
> > +TimeStamps ti;
> >
> >  init_dynload();
> >
> > @@ -4811,12 +4828,17 @@ int main(int argc, 

[FFmpeg-devel] [PATCH] fftools/ffmpeg: Add system time and real time to benchmarking.

2018-04-27 Thread Mark Wachsler
The -benchmark and -benchmark_all options now show user, system, and real time,
instead of just user time.
---
 fftools/ffmpeg.c | 49 +++-
 1 file changed, 36 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 4dbe72186d..4036058591 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -120,8 +120,14 @@ const char *const forced_keyframes_const_names[] = {
 NULL
 };
 
+typedef struct BenchmarkTimeStamps {
+int64_t real_usec;
+int64_t user_usec;
+int64_t sys_usec;
+} BenchmarkTimeStamps;
+
 static void do_video_stats(OutputStream *ost, int frame_size);
-static int64_t getutime(void);
+static BenchmarkTimeStamps get_benchmark_time_stamps(void);
 static int64_t getmaxrss(void);
 static int ifilter_has_all_input_formats(FilterGraph *fg);
 
@@ -133,7 +139,7 @@ static int64_t decode_error_stat[2];
 
 static int want_sdp = 1;
 
-static int current_time;
+static BenchmarkTimeStamps current_time;
 AVIOContext *progress_avio = NULL;
 
 static uint8_t *subtitle_out;
@@ -653,7 +659,7 @@ static void abort_codec_experimental(AVCodec *c, int 
encoder)
 static void update_benchmark(const char *fmt, ...)
 {
 if (do_benchmark_all) {
-int64_t t = getutime();
+BenchmarkTimeStamps t = get_benchmark_time_stamps();
 va_list va;
 char buf[1024];
 
@@ -661,7 +667,11 @@ static void update_benchmark(const char *fmt, ...)
 va_start(va, fmt);
 vsnprintf(buf, sizeof(buf), fmt, va);
 va_end(va);
-av_log(NULL, AV_LOG_INFO, "bench: %8"PRIu64" %s \n", t - 
current_time, buf);
+av_log(NULL, AV_LOG_INFO,
+   "bench: %8" PRIu64 " user %8" PRIu64 " sys %8" PRIu64 " 
real %s \n",
+   t.user_usec - current_time.user_usec,
+   t.sys_usec - current_time.sys_usec,
+   t.real_usec - current_time.real_usec, buf);
 }
 current_time = t;
 }
@@ -4715,23 +4725,31 @@ static int transcode(void)
 return ret;
 }
 
-
-static int64_t getutime(void)
+static BenchmarkTimeStamps get_benchmark_time_stamps(void)
 {
+BenchmarkTimeStamps time_stamps;
+time_stamps.real_usec = av_gettime_relative();
 #if HAVE_GETRUSAGE
 struct rusage rusage;
 
 getrusage(RUSAGE_SELF, &rusage);
-return (rusage.ru_utime.tv_sec * 100LL) + rusage.ru_utime.tv_usec;
+time_stamps.user_usec =
+(rusage.ru_utime.tv_sec * 100LL) + rusage.ru_utime.tv_usec;
+time_stamps.sys_usec =
+(rusage.ru_stime.tv_sec * 100LL) + rusage.ru_stime.tv_usec;
 #elif HAVE_GETPROCESSTIMES
 HANDLE proc;
 FILETIME c, e, k, u;
 proc = GetCurrentProcess();
 GetProcessTimes(proc, &c, &e, &k, &u);
-return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
+time_stamps.user_usec =
+((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
+time_stamps.sys_usec =
+((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
 #else
-return av_gettime_relative();
+time_stamps.user_usec = time_stamps.sys_usec = 0;
 #endif
+return time_stamps;
 }
 
 static int64_t getmaxrss(void)
@@ -4759,7 +4777,7 @@ static void log_callback_null(void *ptr, int level, const 
char *fmt, va_list vl)
 int main(int argc, char **argv)
 {
 int i, ret;
-int64_t ti;
+BenchmarkTimeStamps ti;
 
 init_dynload();
 
@@ -4811,12 +4829,17 @@ int main(int argc, char **argv)
 want_sdp = 0;
 }
 
-current_time = ti = getutime();
+current_time = ti = get_benchmark_time_stamps();
 if (transcode() < 0)
 exit_program(1);
-ti = getutime() - ti;
 if (do_benchmark) {
-av_log(NULL, AV_LOG_INFO, "bench: utime=%0.3fs\n", ti / 100.0);
+current_time = get_benchmark_time_stamps();
+int64_t utime = current_time.user_usec - ti.user_usec;
+int64_t stime = current_time.sys_usec - ti.sys_usec;
+int64_t rtime = current_time.real_usec - ti.real_usec;
+av_log(NULL, AV_LOG_INFO,
+   "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
+   utime / 100.0, stime / 100.0, rtime / 100.0);
 }
 av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded, 
%"PRIu64" decoding errors\n",
decode_error_stat[0], decode_error_stat[1]);
-- 
2.17.0.441.gb46fe60e1d-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel