[FFmpeg-cvslog] avformat/movenc: Explicitly address potential division by zero.
ffmpeg | branch: master | Lucas Cooper | Thu Apr 27 15:08:29 2017 -0700| [77bc507f6f001b9f5fa75c664106261bd8f2c971] | committer: Michael Niedermayer avformat/movenc: Explicitly address potential division by zero. find_fps attempts to infer framerate from AVCodec's timebase. When this results in a frame rate that isn't explicitly marked as supported in av_timecode_check_frame_rate, find_fps returns the AVStream's avg_frame_rate, which, per avformat.h, _may_ be set (or not). mov_get_mpeg2_xdcam_codec_tag, mov_get_h264_codec_tag and find_compressor attempt to call av_q2d on the return value of find_fps, which in the above case, may result in division by zero and therefore, an undefined frame rate when NaN is converted to int. Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=77bc507f6f001b9f5fa75c664106261bd8f2c971 --- libavformat/movenc.c | 15 --- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index e6e2313c53..d20d272f89 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1321,12 +1321,21 @@ static AVRational find_fps(AVFormatContext *s, AVStream *st) return rate; } +static int defined_frame_rate(AVFormatContext *s, AVStream *st) +{ +AVRational rational_framerate = find_fps(s, st); +int rate = 0; +if (rational_framerate.den != 0) +rate = av_q2d(rational_framerate); +return rate; +} + static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag = track->par->codec_tag; int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; -int rate = av_q2d(find_fps(s, st)); +int rate = defined_frame_rate(s, st); if (!tag) tag = MKTAG('m', '2', 'v', '1'); //fallback tag @@ -1388,7 +1397,7 @@ static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track) int tag = track->par->codec_tag; int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; -int rate = av_q2d(find_fps(s, st)); +int rate = defined_frame_rate(s, st); if (!tag) tag = MKTAG('a', 'v', 'c', 'i'); //fallback tag @@ -1850,7 +1859,7 @@ static void find_compressor(char * compressor_name, int len, MOVTrack *track) } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) { int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; -int rate = av_q2d(find_fps(NULL, st)); +int rate = defined_frame_rate(NULL, st); av_strlcatf(compressor_name, len, "XDCAM"); if (track->par->format == AV_PIX_FMT_YUV422P) { av_strlcatf(compressor_name, len, " HD422"); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] avfilter: Add new format for PSNR stats log
ffmpeg | branch: master | Lucas Cooper | Mon Jul 25 11:54:37 2016 -0700| [bc9ce5f6bec01cea4c291e5a339d3c08d89700f0] | committer: Michael Niedermayer avfilter: Add new format for PSNR stats log Add an AVOption stats_version with a new header for V2 stats, which specifies the stats log version and lists the fields that will be present in the log (to ease parsing). The primary motivation is to facilitate the addition of optional fields to the log without breaking backwards compatibility, while making the logs easier to parse. Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bc9ce5f6bec01cea4c291e5a339d3c08d89700f0 --- libavfilter/vf_psnr.c | 16 1 file changed, 16 insertions(+) diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c index 0c8d0f1..3bec747 100644 --- a/libavfilter/vf_psnr.c +++ b/libavfilter/vf_psnr.c @@ -43,6 +43,8 @@ typedef struct PSNRContext { uint64_t nb_frames; FILE *stats_file; char *stats_file_str; +int stats_version; +int stats_header_written; int max[4], average_max; int is_rgb; uint8_t rgba_map[4]; @@ -60,6 +62,7 @@ typedef struct PSNRContext { static const AVOption psnr_options[] = { {"stats_file", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, {"f", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, +{"stats_version", "Set the format version for the stats file.", OFFSET(stats_version), AV_OPT_TYPE_INT,{.i64=1},1, 2, FLAGS }, { NULL } }; @@ -169,6 +172,19 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, set_meta(metadata, "lavfi.psnr.psnr_avg", 0, get_psnr(mse, 1, s->average_max)); if (s->stats_file) { +if (s->stats_version == 2 && !s->stats_header_written) { +fprintf(s->stats_file, "psnr_log_version:2 fields:n"); +fprintf(s->stats_file, ",mse_avg"); +for (j = 0; j < s->nb_components; j++) { +fprintf(s->stats_file, ",mse_%c", s->comps[j]); +} +fprintf(s->stats_file, ",psnr_avg"); +for (j = 0; j < s->nb_components; j++) { +fprintf(s->stats_file, ",psnr_%c", s->comps[j]); +} +fprintf(s->stats_file, "\n"); +s->stats_header_written = 1; +} fprintf(s->stats_file, "n:%"PRId64" mse_avg:%0.2f ", s->nb_frames, mse); for (j = 0; j < s->nb_components; j++) { c = s->is_rgb ? s->rgba_map[j] : j; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] doc/filters: Add stats_version documentation to PSNR filter
ffmpeg | branch: master | Lucas Cooper | Mon Aug 1 09:50:59 2016 -0700| [3d7ea1d39e09d22b88c056b16dd04d1c49940012] | committer: Michael Niedermayer doc/filters: Add stats_version documentation to PSNR filter Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3d7ea1d39e09d22b88c056b16dd04d1c49940012 --- doc/filters.texi | 20 +++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/filters.texi b/doc/filters.texi index c47dfee..923d481 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10692,13 +10692,31 @@ The description of the accepted parameters follows. If specified the filter will use the named file to save the PSNR of each individual frame. When filename equals "-" the data is sent to standard output. + +@item stats_version +Specifies which version of the stats file format to use. Details of +each format are written below. +Default value is 1. @end table The file printed if @var{stats_file} is selected, contains a sequence of key/value pairs of the form @var{key}:@var{value} for each compared couple of frames. -A description of each shown parameter follows: +If a @var{stats_version} greater than 1 is specified, a header line precedes +the list of per-frame-pair stats, with key value pairs following the frame +format with the following parameters: + +@table @option +@item psnr_log_version +The version of the log file format. Will match @var{stats_version}. + +@item fields +A comma separated list of the per-frame-pair parameters included in +the log. +@end table + +A description of each shown per-frame-pair parameter follows: @table @option @item n ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] avfilter/vf_psnr: Add max value output option to psnr stats log.
ffmpeg | branch: master | Lucas Cooper | Wed Aug 31 12:40:41 2016 -0700| [aabe12eba3758d6f393ba754a54307d5c705084c] | committer: Michael Niedermayer avfilter/vf_psnr: Add max value output option to psnr stats log. This allows retroactive calculation/aggregation of PSNR from the stats log. Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=aabe12eba3758d6f393ba754a54307d5c705084c --- doc/filters.texi | 10 ++ libavfilter/vf_psnr.c | 20 2 files changed, 30 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index b50d7a6..88c6f65 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10832,6 +10832,12 @@ standard output. Specifies which version of the stats file format to use. Details of each format are written below. Default value is 1. + +@item stats_add_max +Determines whether the max value is output to the stats log. +Default value is 0. +Requires stats_version >= 2. If this is set and stats_version < 2, +the filter will return an error. @end table The file printed if @var{stats_file} is selected, contains a sequence of @@ -10868,6 +10874,10 @@ frames for the component specified by the suffix. @item psnr_y, psnr_u, psnr_v, psnr_r, psnr_g, psnr_b, psnr_a Peak Signal to Noise ratio of the compared frames for the component specified by the suffix. + +@item max_avg, max_y, max_u, max_v +Maximum allowed value for each channel, and average over all +channels. @end table For example: diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c index 3bec747..320f433 100644 --- a/libavfilter/vf_psnr.c +++ b/libavfilter/vf_psnr.c @@ -45,6 +45,7 @@ typedef struct PSNRContext { char *stats_file_str; int stats_version; int stats_header_written; +int stats_add_max; int max[4], average_max; int is_rgb; uint8_t rgba_map[4]; @@ -63,6 +64,7 @@ static const AVOption psnr_options[] = { {"stats_file", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, {"f", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, {"stats_version", "Set the format version for the stats file.", OFFSET(stats_version), AV_OPT_TYPE_INT,{.i64=1},1, 2, FLAGS }, +{"output_max", "Add raw stats (max values) to the output log.", OFFSET(stats_add_max), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, { NULL } }; @@ -182,6 +184,12 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, for (j = 0; j < s->nb_components; j++) { fprintf(s->stats_file, ",psnr_%c", s->comps[j]); } +if (s->stats_add_max) { +fprintf(s->stats_file, ",max_avg"); +for (j = 0; j < s->nb_components; j++) { +fprintf(s->stats_file, ",max_%c", s->comps[j]); +} +} fprintf(s->stats_file, "\n"); s->stats_header_written = 1; } @@ -196,6 +204,13 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, fprintf(s->stats_file, "psnr_%c:%0.2f ", s->comps[j], get_psnr(comp_mse[c], 1, s->max[c])); } +if (s->stats_version == 2 && s->stats_add_max) { +fprintf(s->stats_file, "max_avg:%d ", s->average_max); +for (j = 0; j < s->nb_components; j++) { +c = s->is_rgb ? s->rgba_map[j] : j; +fprintf(s->stats_file, "max_%c:%d ", s->comps[j], s->max[c]); +} +} fprintf(s->stats_file, "\n"); } @@ -210,6 +225,11 @@ static av_cold int init(AVFilterContext *ctx) s->max_mse = -INFINITY; if (s->stats_file_str) { +if (s->stats_version < 2 && s->stats_add_max) { +av_log(ctx, AV_LOG_ERROR, +"stats_add_max was specified but stats_version < 2.\n" ); +return AVERROR(EINVAL); +} if (!strcmp(s->stats_file_str, "-")) { s->stats_file = stdout; } else { ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] avcodec/nvenc: Add encoder stats
ffmpeg | branch: master | Lucas Cooper | Mon Mar 7 15:47:56 2016 -0800| [fd55470c657ffd7cd5ac00a53ecd3224aa99d83b] | committer: Timo Rothenpieler avcodec/nvenc: Add encoder stats Signed-off-by: Timo Rothenpieler > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fd55470c657ffd7cd5ac00a53ecd3224aa99d83b --- libavcodec/nvenc.c | 21 ++--- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 5d78930..c001c9e 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1186,6 +1186,8 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencOut NVENCSTATUS nv_status; int res = 0; +enum AVPictureType pict_type; + switch (avctx->codec->id) { case AV_CODEC_ID_H264: slice_mode_data = ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData; @@ -1230,28 +1232,33 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencOut switch (lock_params.pictureType) { case NV_ENC_PIC_TYPE_IDR: pkt->flags |= AV_PKT_FLAG_KEY; -#if FF_API_CODED_FRAME -FF_DISABLE_DEPRECATION_WARNINGS case NV_ENC_PIC_TYPE_I: -avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; +pict_type = AV_PICTURE_TYPE_I; break; case NV_ENC_PIC_TYPE_P: -avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P; +pict_type = AV_PICTURE_TYPE_P; break; case NV_ENC_PIC_TYPE_B: -avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B; +pict_type = AV_PICTURE_TYPE_B; break; case NV_ENC_PIC_TYPE_BI: -avctx->coded_frame->pict_type = AV_PICTURE_TYPE_BI; +pict_type = AV_PICTURE_TYPE_BI; break; default: av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered, expect the output to be broken.\n"); av_log(avctx, AV_LOG_ERROR, "Please report this error and include as much information on how to reproduce it as possible.\n"); res = AVERROR_EXTERNAL; goto error; +} + +#if FF_API_CODED_FRAME +FF_DISABLE_DEPRECATION_WARNINGS +avctx->coded_frame->pict_type = pict_type; FF_ENABLE_DEPRECATION_WARNINGS #endif -} + +ff_side_data_set_encoder_stats(pkt, +(lock_params.frameAvgQP - 1) * FF_QP2LAMBDA, NULL, 0, pict_type); pkt->pts = lock_params.outputTimeStamp; pkt->dts = timestamp_queue_dequeue(&ctx->timestamp_list); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog