[PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream
- Make ffmpeg to output stats for each video streams and each ouptut file ffmpeg output log in print_report. - The report of video/audio sizes is clear as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files. Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 182 ++++++++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 81 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5a19a09d9a..4aa6c1d3e4 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1526,17 +1526,28 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; + AVFormatContext *oc; for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } + switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1545,25 +1556,37 @@ static void print_final_stats(int64_t total_size) } extra_size += ost->enc_ctx->extradata_size; data_size += ost->data_size; - if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) + + if ((ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); + + if (data_size && total_size>0 && total_size >= data_size) + percent = 100.0 * (total_size - data_size) / data_size; + + av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ", + video_size / 1024.0, + audio_size / 1024.0, + subtitle_size / 1024.0, + other_size / 1024.0, + extra_size / 1024.0); + + if (percent >= 0.0) + av_log(NULL, AV_LOG_INFO, "%f%%", percent); + else + av_log(NULL, AV_LOG_INFO, "unknown"); + av_log(NULL, AV_LOG_INFO, "\n"); + } } - if (data_size && total_size>0 && total_size >= data_size) - percent = 100.0 * (total_size - data_size) / data_size; - av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ", - video_size / 1024.0, - audio_size / 1024.0, - subtitle_size / 1024.0, - other_size / 1024.0, - extra_size / 1024.0); - if (percent >= 0.0) - av_log(NULL, AV_LOG_INFO, "%f%%", percent); - else - av_log(NULL, AV_LOG_INFO, "unknown"); - av_log(NULL, AV_LOG_INFO, "\n"); /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1676,13 +1699,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, 1); @@ -1693,12 +1709,12 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO && (is_last_report || !is_last_report && !vid)) { float fps; frame_number = ost->frame_number; @@ -1750,75 +1766,80 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->file_index, ost->index, p); } vid = 1; - } - /* compute min output value */ - if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) - pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), + + /* compute min output value */ + if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) + pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), ost->st->time_base, AV_TIME_BASE_Q)); - if (is_last_report) - nb_frames_drop += ost->last_dropped; - } + if (is_last_report) + nb_frames_drop += ost->last_dropped; - secs = FFABS(pts) / AV_TIME_BASE; - us = FFABS(pts) % AV_TIME_BASE; - mins = secs / 60; - secs %= 60; - hours = mins / 60; - mins %= 60; - hours_sign = (pts < 0) ? "-" : ""; + total_size = ost->data_size; - bitrate = pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1; - speed = t != 0.0 ? (double)pts / AV_TIME_BASE / t : -1; + secs = FFABS(pts) / AV_TIME_BASE; + us = FFABS(pts) % AV_TIME_BASE; + mins = secs / 60; + secs %= 60; + hours = mins / 60; + mins %= 60; + hours_sign = (pts < 0) ? "-" : ""; - if (total_size < 0) av_bprintf(&buf, "size=N/A time="); - else av_bprintf(&buf, "size=%8.0fkB time=", total_size / 1024.0); - if (pts == AV_NOPTS_VALUE) { - av_bprintf(&buf, "N/A "); - } else { - av_bprintf(&buf, "%s%02d:%02d:%02d.%02d ", - hours_sign, hours, mins, secs, (100 * us) / AV_TIME_BASE); - } + bitrate = pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1; + speed = t != 0.0 ? (double)pts / AV_TIME_BASE / t : -1; - if (bitrate < 0) { - av_bprintf(&buf, "bitrate=N/A"); - av_bprintf(&buf_script, "bitrate=N/A\n"); - }else{ - av_bprintf(&buf, "bitrate=%6.1fkbits/s", bitrate); - av_bprintf(&buf_script, "bitrate=%6.1fkbits/s\n", bitrate); - } + if (total_size < 0) av_bprintf(&buf, "size=N/A time="); + else av_bprintf(&buf, "size=%8.0fkB time=", total_size / 1024.0); + if (pts == AV_NOPTS_VALUE) { + av_bprintf(&buf, "N/A "); + } else { + av_bprintf(&buf, "%s%02d:%02d:%02d.%02d ", + hours_sign, hours, mins, secs, (100 * us) / AV_TIME_BASE); + } - if (total_size < 0) av_bprintf(&buf_script, "total_size=N/A\n"); - else av_bprintf(&buf_script, "total_size=%"PRId64"\n", total_size); - if (pts == AV_NOPTS_VALUE) { - av_bprintf(&buf_script, "out_time_ms=N/A\n"); - av_bprintf(&buf_script, "out_time=N/A\n"); - } else { - av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts); - av_bprintf(&buf_script, "out_time=%s%02d:%02d:%02d.%06d\n", - hours_sign, hours, mins, secs, us); - } + if (bitrate < 0) { + av_bprintf(&buf, "bitrate=N/A"); + av_bprintf(&buf_script, "bitrate=N/A\n"); + }else{ + av_bprintf(&buf, "bitrate=%6.1fkbits/s", bitrate); + av_bprintf(&buf_script, "bitrate=%6.1fkbits/s\n", bitrate); + } + + if (total_size < 0) av_bprintf(&buf_script, "total_size=N/A\n"); + else av_bprintf(&buf_script, "total_size=%"PRId64"\n", total_size); + if (pts == AV_NOPTS_VALUE) { + av_bprintf(&buf_script, "out_time_ms=N/A\n"); + av_bprintf(&buf_script, "out_time=N/A\n"); + } else { + av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts); + av_bprintf(&buf_script, "out_time=%s%02d:%02d:%02d.%06d\n", + hours_sign, hours, mins, secs, us); + } - if (nb_frames_dup || nb_frames_drop) - av_bprintf(&buf, " dup=%d drop=%d", nb_frames_dup, nb_frames_drop); - av_bprintf(&buf_script, "dup_frames=%d\n", nb_frames_dup); - av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop); + if (nb_frames_dup || nb_frames_drop) + av_bprintf(&buf, " dup=%d drop=%d", nb_frames_dup, nb_frames_drop); + av_bprintf(&buf_script, "dup_frames=%d\n", nb_frames_dup); + av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop); - if (speed < 0) { - av_bprintf(&buf, " speed=N/A"); - av_bprintf(&buf_script, "speed=N/A\n"); - } else { - av_bprintf(&buf, " speed=%4.3gx", speed); - av_bprintf(&buf_script, "speed=%4.3gx\n", speed); + if (speed < 0) { + av_bprintf(&buf, " speed=N/A"); + av_bprintf(&buf_script, "speed=N/A\n"); + } else { + av_bprintf(&buf, " speed=%4.3gx", speed); + av_bprintf(&buf_script, "speed=%4.3gx\n", speed); + } + + if (is_last_report) + av_bprintf(&buf, "\n"); + } } - + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else av_log(NULL, AV_LOG_INFO, "%s %c", buf.str, end); - - fflush(stderr); + fflush(stderr); } av_bprint_finalize(&buf, NULL); @@ -1835,9 +1856,8 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti "Error closing progress log, loss of information possible: %s\n", av_err2str(ret)); } } - if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) -- 2.17.0.441.gb46fe60e1d-goog
On Fri, May 18, 2018 at 04:54:25PM -0700, Wang Cao wrote:
- Make ffmpeg to output stats for each video streams and each ouptut file ffmpeg output log in print_report. - The report of video/audio sizes is clear as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files.
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 182 ++++++++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 81 deletions(-)
This causes the report to disappear for ./ffmpeg -i ~/tickets/1660/alaw_2.aif -f null - file should be in the ticket on trac, if not, say so and ill figure out where the file is [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Those who are best at talking, realize last or never when they are wrong.
Sorry the ticket doesn't contain alaw_2.aif as in https://trac.ffmpeg.org/ticket/1660 On Fri, May 18, 2018 at 8:13 PM, Michael Niedermayer <michael@niedermayer.cc
wrote:
On Fri, May 18, 2018 at 04:54:25PM -0700, Wang Cao wrote:
- Make ffmpeg to output stats for each video streams and each ouptut file ffmpeg output log in print_report. - The report of video/audio sizes is clear as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files.
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 182 ++++++++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 81 deletions(-)
This causes the report to disappear for ./ffmpeg -i ~/tickets/1660/alaw_2.aif -f null -
file should be in the ticket on trac, if not, say so and ill figure out where the file is
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Those who are best at talking, realize last or never when they are wrong.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
-- Wang Cao
On Mon, May 21, 2018 at 02:36:28PM -0700, Wang Cao wrote:
Sorry the ticket doesn't contain alaw_2.aif as in https://trac.ffmpeg.org/ticket/1660
the issue is reproduceable with alaw.aif from the ticket [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends. -- Gandalf
On Fri, May 18, 2018 at 16:54:25 -0700, Wang Cao wrote: Apart from the functional changes:
data_size += ost->data_size; - if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) + + if ((ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1)
- if (nb_frames_dup || nb_frames_drop) - av_bprintf(&buf, " dup=%d drop=%d", nb_frames_dup, nb_frames_drop); - av_bprintf(&buf_script, "dup_frames=%d\n", nb_frames_dup); - av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop); + if (nb_frames_dup || nb_frames_drop) + av_bprintf(&buf, " dup=%d drop=%d", nb_frames_dup, nb_frames_drop); + av_bprintf(&buf_script, "dup_frames=%d\n", nb_frames_dup); + av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop);
- - fflush(stderr); + fflush(stderr); }
} - if (is_last_report)
A lot of your changes are cosmetic (empty lines, re-indentation) and do not belong into a functional patch, if at all. Furthermore, some large sections are reindented due to moving into or out of a block. Please avoid that, and make the indentations in a subsequent patch, to ease review. Thanks, Moritz
- Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. - The report of video/audio sizes is clear as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files. Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 65 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5a19a09d9a..0b98521852 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1526,17 +1526,28 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; + AVFormatContext *oc; for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } + switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1545,25 +1556,37 @@ static void print_final_stats(int64_t total_size) } extra_size += ost->enc_ctx->extradata_size; data_size += ost->data_size; + if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } - + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); + if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; - + av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ", video_size / 1024.0, audio_size / 1024.0, subtitle_size / 1024.0, other_size / 1024.0, extra_size / 1024.0); + if (percent >= 0.0) av_log(NULL, AV_LOG_INFO, "%f%%", percent); else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } + + /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1676,13 +1699,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, 1); @@ -1693,12 +1709,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1750,14 +1767,16 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->file_index, ost->index, p); } vid = 1; - } + } + /* compute min output value */ if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), - ost->st->time_base, AV_TIME_BASE_Q)); + ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_dropped; - } + + total_size = ost->data_size; secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1810,14 +1829,18 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf, " speed=%4.3gx", speed); av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } - + + if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else av_log(NULL, AV_LOG_INFO, "%s %c", buf.str, end); - fflush(stderr); } av_bprint_finalize(&buf, NULL); @@ -1835,9 +1858,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti "Error closing progress log, loss of information possible: %s\n", av_err2str(ret)); } } - + if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) -- 2.17.0.441.gb46fe60e1d-goog
On Tue, May 22, 2018 at 03:40:54PM -0700, Wang Cao wrote:
- Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. - The report of video/audio sizes is clear as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files.
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 65 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 21 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5a19a09d9a..0b98521852 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1526,17 +1526,28 @@ static int reap_filters(int flush) return 0; }
-static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; + AVFormatContext *oc;
for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } + switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1545,25 +1556,37 @@ static void print_final_stats(int64_t total_size) } extra_size += ost->enc_ctx->extradata_size; data_size += ost->data_size; + if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } - + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); + if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size;
- +
Adding trailing whitespace
av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ", video_size / 1024.0, audio_size / 1024.0, subtitle_size / 1024.0, other_size / 1024.0, extra_size / 1024.0); + if (percent >= 0.0)
not related, whitespace change
av_log(NULL, AV_LOG_INFO, "%f%%", percent); else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } + +
/* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1676,13 +1699,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
t = (cur_time-timer_start) / 1000000.0;
- - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, 1); @@ -1693,12 +1709,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA;
- if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps;
frame_number = ost->frame_number; @@ -1750,14 +1767,16 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->file_index, ost->index, p); } vid = 1; - } + } +
/* compute min output value */ if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), - ost->st->time_base, AV_TIME_BASE_Q)); + ost->st->time_base, AV_TIME_BASE_Q));
unrelated and incorrect indention change
if (is_last_report) nb_frames_drop += ost->last_dropped; - } + + total_size = ost->data_size;
secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1810,14 +1829,18 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf, " speed=%4.3gx", speed); av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } - + + if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else av_log(NULL, AV_LOG_INFO, "%s %c", buf.str, end); - fflush(stderr); } av_bprint_finalize(&buf, NULL); @@ -1835,9 +1858,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti "Error closing progress log, loss of information possible: %s\n", av_err2str(ret)); } } - +
unlreated addition of trailing whitespace please look at and cleanup the patch [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB When the tyrant has disposed of foreign enemies by conquest or treaty, and there is nothing more to fear from them, then he is always stirring up some war or other, in order that the people may require a leader. -- Plato
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4ac6903cc..1eaf344552 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,27 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; + AVFormatContext *oc; for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1552,7 +1562,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1584,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1680,13 +1698,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, 1); @@ -1697,12 +1708,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1761,7 +1773,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_dropped; - } + total_size = ost->data_size; secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1815,8 +1827,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } + if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1841,7 +1858,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) -- 2.18.0.rc1.242.g61856ae69a-goog
On Thu, Jun 14, 2018 at 08:35:48PM +0800, Wang Cao wrote:
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-)
this adds some warnings: CC fftools/ffmpeg.o fftools/ffmpeg.c:1533:13: warning: function declaration isn’t a prototype [-Wstrict-prototypes] static void print_final_stats() ^ fftools/ffmpeg.c: In function ‘print_report’: fftools/ffmpeg.c:1672:22: warning: unused variable ‘oc’ [-Wunused-variable] AVFormatContext *oc; ^ also the commit message should not be one very long line thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB What does censorship reveal? It reveals fear. -- Julian Assange
Thanks for letting me know about this. I actually submitted another patch without long commit message. I will clean up according to your feedback after getting feedbacks from other people. On Sat, Jun 16, 2018 at 2:52 AM Michael Niedermayer <michael@niedermayer.cc> wrote:
On Thu, Jun 14, 2018 at 08:35:48PM +0800, Wang Cao wrote:
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-)
this adds some warnings:
CC fftools/ffmpeg.o fftools/ffmpeg.c:1533:13: warning: function declaration isn’t a prototype [-Wstrict-prototypes] static void print_final_stats() ^ fftools/ffmpeg.c: In function ‘print_report’: fftools/ffmpeg.c:1672:22: warning: unused variable ‘oc’ [-Wunused-variable] AVFormatContext *oc; ^
also the commit message should not be one very long line
thx
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
What does censorship reveal? It reveals fear. -- Julian Assange _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
-- Wang Cao
Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The report of video/audio sizes is clear now as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files. Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4ac6903cc..1eaf344552 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,27 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; + AVFormatContext *oc; for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1552,7 +1562,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1584,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1680,13 +1698,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, 1); @@ -1697,12 +1708,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1761,7 +1773,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_dropped; - } + total_size = ost->data_size; secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1815,8 +1827,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } + if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1841,7 +1858,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) -- 2.18.0.rc1.244.gcf134e6275-goog
On Fri, Jun 15, 2018 at 13:37:31 +0800, Wang Cao wrote:
Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The report of video/audio sizes is clear now as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files.
(This needs some cleaing up of the grammar, but that's beside the point right now.) Somehow, this changes the stats while running. I no longer see the overall stats. If I map video first, I see only the video stats, but it seems like the audio stats flicker through. If I map audio first, I see a duplicated line (extended), which shows video and audio stat lines side by side. I don't think this is what you intended. You only wanted to show the *final* stats differently, correct? If it is intended, I'd like to point out that the status line does not have enough space on most screens to hold twice or more of its current content. I would still like to see overall stats, also at the end, because it says something about e.g. the total size. In the summary report, per file and per stream stats may be nice though. Moritz
For example: with (-psnr) frame= 450 fps=315 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=10.5x (video stats) size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=10.6x (audio stats) If there are multiple files, stats of the second output would be concatenated after the first one. Is this a acceptable behavior?
For example: with (-psnr) frame= 450 fps=315 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=10.5x (video stats) size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=10.6x (audio stats) frame= 450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=3.74x size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=3.77x q=0.0 frame= 450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=3.77x q=0.0 frame= 450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=3.77x video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871% video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871% video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871%
Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The report of video/audio sizes is clear now as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files. Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4ac6903cc..1842ccd543 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,27 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; + AVFormatContext *oc; for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1552,7 +1562,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1584,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1680,13 +1698,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, 1); @@ -1697,12 +1708,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1761,7 +1773,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_dropped; - } + total_size = ost->data_size; secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1815,8 +1827,15 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } + if (is_last_report) + av_bprintf(&buf, "\n"); + else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + av_bprintf(&buf, "\r"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1841,7 +1860,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) -- 2.18.0.rc1.244.gcf134e6275-goog
On Wed, Jun 20, 2018 at 05:25:32PM +0800, Wang Cao wrote:
For example: with (-psnr) frame= 450 fps=315 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=10.5x (video stats) size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=10.6x (audio stats)
frame= 450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=3.74x size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=3.77x q=0.0 frame= 450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=3.77x q=0.0 frame= 450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x size= 107kB time=00:00:15.13 bitrate= 58.0kbits/s speed=3.77x video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871% video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871% video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871%
how does the user know which is which output ? also some users may want just one line summarizing all [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Awnsering whenever a program halts or runs forever is On a turing machine, in general impossible (turings halting problem). On any real computer, always possible as a real computer has a finite number of states N, and will either halt in less than N cycles or never halt.
On 21-06-2018 09:40 PM, Michael Niedermayer wrote:
how does the user know which is which output ?
also some users may want just one line summarizing all
Agreed. Better if each line is identified. Regards, Gyan
On Fri, Jun 15, 2018 at 01:37:31PM +0800, Wang Cao wrote:
Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The report of video/audio sizes is clear now as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files.
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4ac6903cc..1eaf344552 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,27 @@ static int reap_filters(int flush) return 0; }
-static void print_final_stats(int64_t total_size) +static void print_final_stats() {
there are some new warnings: fftools/ffmpeg.c:1533:13: warning: function declaration isn’t a prototype [-Wstrict-prototypes] static void print_final_stats() ^ fftools/ffmpeg.c: In function ‘print_report’: fftools/ffmpeg.c:1672:22: warning: unused variable ‘oc’ [-Wunused-variable] AVFormatContext *oc; ^ [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Does the universe only have a finite lifespan? No, its going to go on forever, its just that you wont like living in it. -- Hiranya Peiri
Thanks for pointing this out. I have modified the code according to your comments.
Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The report of video/audio sizes is clear now as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files. Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 52 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4ac6903cc..321f7a6017 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,27 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats(void) { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; + AVFormatContext *oc; for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1552,7 +1562,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1584,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1651,7 +1669,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti { AVBPrint buf, buf_script; OutputStream *ost; - AVFormatContext *oc; int64_t total_size; AVCodecContext *enc; int frame_number, vid, i; @@ -1680,13 +1697,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, 1); @@ -1697,12 +1707,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1759,9 +1770,11 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), ost->st->time_base, AV_TIME_BASE_Q)); - if (is_last_report) + if (is_last_report) { nb_frames_drop += ost->last_dropped; - } + } + + total_size = ost->data_size; secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1815,8 +1828,15 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } + if (is_last_report) + av_bprintf(&buf, "\n"); + else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + av_bprintf(&buf, "\r"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1841,7 +1861,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) -- 2.18.0.rc2.346.g013aa6912e-goog
Friendly ping. Thanks!
On Fri, Jun 22, 2018 at 04:03:38PM +0800, Wang Cao wrote:
Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The report of video/audio sizes is clear now as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files.
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 52 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-)
This changes the printed values ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -qscale 2 -vframes 3 -an test2.avi frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% vs. frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% the file is the same [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If a bugfix only changes things apparently unrelated to the bug with no further explanation, that is a good sign that the bugfix is wrong.
This changes the printed values ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -qscale 2 -vframes 3 -an test2.avi frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% vs. frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% the file is the same
Thanks for pointing this out! I have noticed the change in the stats but I think the change is correct. Before my patch, the bitrate calculation is based on total_size as in
oc = output_files[0]->ctx; total_size = avio_size(oc->pb);
If I understand this correctly, the size of whole file will be used to calculate the bitrate which considers probably header overhead. I changed it to
total_size = ost->data_size;
Therefore only the size of the stream under consideration will be used for calculation. Please correct me if my understanding is wrong. Thanks! On Fri, Jun 29, 2018 at 1:58 PM Michael Niedermayer <michael@niedermayer.cc> wrote:
On Fri, Jun 22, 2018 at 04:03:38PM +0800, Wang Cao wrote:
Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The report of video/audio sizes is clear now as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files.
Signed-off-by: Wang Cao <wangcao@google.com> --- fftools/ffmpeg.c | 52 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-)
This changes the printed values ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -qscale 2 -vframes 3 -an test2.avi
frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063%
vs.
frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063%
the file is the same
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If a bugfix only changes things apparently unrelated to the bug with no further explanation, that is a good sign that the bugfix is wrong. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
-- Wang Cao
On Wed, Jul 11, 2018 at 03:47:45PM -0700, Wang Cao wrote:
This changes the printed values ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -qscale 2 -vframes 3 -an test2.avi frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% vs. frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% the file is the same
Thanks for pointing this out! I have noticed the change in the stats but I think the change is correct. Before my patch, the bitrate calculation is based on total_size as in
oc = output_files[0]->ctx; total_size = avio_size(oc->pb);
If I understand this correctly, the size of whole file will be used to calculate the bitrate which considers probably header overhead.
I changed it to
total_size = ost->data_size;
Therefore only the size of the stream under consideration will be used for calculation.
Please correct me if my understanding is wrong. Thanks!
Do i understand correctly that you suggest to remove the display of the filesize and file bitrate ? And in its place would be a display of a randomly picked stream bitrate ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you fake or manipulate statistics in a paper in physics you will never get a job again. If you fake or manipulate statistics in a paper in medicin you will get a job for life at the pharma industry.
Sorry I probably confused you a little bit. I was not suggesting removing anything. I tried to convince you that there is some issue with the bitrate calculation.
From your original comments:
This changes the printed values ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -qscale 2 -vframes 3 -an test2.avi frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% vs. frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% the file is the same
After my change:
frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x
Before my change(master branch)
frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x
The size is different (51 vs 57) because I display the stream size instead of the total file size. I think stream size is more suitable in this context with "frame, fps, time". For bitrate, I use the stream size to calculate it and I think it's more accurate. On Thu, Jul 12, 2018 at 5:01 AM Michael Niedermayer <michael@niedermayer.cc> wrote:
On Wed, Jul 11, 2018 at 03:47:45PM -0700, Wang Cao wrote:
This changes the printed values ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -qscale 2 -vframes 3 -an test2.avi frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% vs. frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.128063% the file is the same
Thanks for pointing this out! I have noticed the change in the stats but I think the change is correct. Before my patch, the bitrate calculation is based on total_size as in
oc = output_files[0]->ctx; total_size = avio_size(oc->pb);
If I understand this correctly, the size of whole file will be used to calculate the bitrate which considers probably header overhead.
I changed it to
total_size = ost->data_size;
Therefore only the size of the stream under consideration will be used for calculation.
Please correct me if my understanding is wrong. Thanks!
Do i understand correctly that you suggest to remove the display of the filesize and file bitrate ? And in its place would be a display of a randomly picked stream bitrate ?
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If you fake or manipulate statistics in a paper in physics you will never get a job again. If you fake or manipulate statistics in a paper in medicin you will get a job for life at the pharma industry. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
-- Wang Cao
2018-07-12 20:56 GMT+02:00, Wang Cao <doubleecao@gmail.com>:
After my change:
frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x
Before my change(master branch)
frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x
The size is different (51 vs 57) because I display the stream size instead of the total file size. I think stream size is more suitable in this context with "frame, fps, time". For bitrate, I use the stream size to calculate it and I think it's more accurate.
I believe users will expect that "size" shows the file size, especially since this was done for more than a decade. Carl Eugen
I believe users will expect that "size" shows the file size, especially since this was done for more than a decade.
If this is the convention, I believe it should be kept as it was. On the other hand, I believe "bitrate" should be calculated through stream size not the file size. On Thu, Jul 12, 2018 at 2:18 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
2018-07-12 20:56 GMT+02:00, Wang Cao <doubleecao@gmail.com>:
After my change:
frame= 3 fps=0.0 q=2.0 Lsize= 51kB time=00:00:00.12 bitrate=3495.7kbits/s speed= 12x
Before my change(master branch)
frame= 3 fps=0.0 q=2.0 Lsize= 57kB time=00:00:00.12 bitrate=3884.7kbits/s speed=11.2x
The size is different (51 vs 57) because I display the stream size instead of the total file size. I think stream size is more suitable in this context with "frame, fps, time". For bitrate, I use the stream size to calculate it and I think it's more accurate.
I believe users will expect that "size" shows the file size, especially since this was done for more than a decade.
Carl Eugen _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
-- Wang Cao
On Thu, Jul 12, 2018 at 04:31:11PM -0700, Wang Cao wrote:
I believe users will expect that "size" shows the file size, especially since this was done for more than a decade.
If this is the convention, I believe it should be kept as it was. On the other hand, I believe "bitrate" should be calculated through stream size not the file size.
if theres a file with 5 video streams it doesnt make sense to summarize teh file with the bitrate of 1 stream Also the user has no indication of this change, the number is just different theres nothing informing him that it is no longer the files bitrate [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The worst form of inequality is to try to make unequal things equal. -- Aristotle
if theres a file with 5 video streams it doesnt make sense to summarize teh file with the bitrate of 1 stream Also the user has no indication of this change, the number is just different theres nothing informing him that it is no longer the files bitrate
I was thinking to output stats for each video/audio stream one line by another. It seems this would be a huge change to users who are not aware. Keeping the old file bitrate looks good to me. Can I extend this to output file bitrate for each output file? -- Wang Cao
On 17-07-2018 02:38 AM, Wang Cao wrote:
I was thinking to output stats for each video/audio stream one line by another. It seems this would be a huge change to users who are not aware. Keeping the old file bitrate looks good to me. Can I extend this to output file bitrate for each output file?
Why not keep the current stats as is, and add an option for verbose stats? At the next major release, we can consider making them the default. Per-stream bitrate may be useful for those encoding HLS/DASH variants. Regards, Gyan
From: Wang Cao <doubleecao@gmail.com> Add an option "detail_stats" to ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The format of stats is unchanged. Signed-off-by: Wang Cao <wangcao@google.com> --- doc/ffmpeg.texi | 4 ++++ fftools/ffmpeg.c | 53 +++++++++++++++++++++++++++++++------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 4 +++- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 3717f22d42..53a5be9791 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output formats to be rtp). Allows discarding specific streams or frames of streams at the demuxer. Not all demuxers support this. +@item -detail_stats (@emph{global}) +Allows printing stats for each output stream and output file at the end of +processing. + @table @option @item none Discard no frame. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2459374f08..2bd057ace1 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,28 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; - - for (i = 0; i < nb_output_streams; i++) { + int nb_display_streams = enable_detail_stats ? nb_output_streams : 1; + AVFormatContext *oc; + + for (i = 0; i < nb_display_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1552,7 +1563,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1585,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1680,13 +1699,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); @@ -1697,12 +1709,14 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + // Only print the stats for the first stream during processing + if ((is_last_report && (enable_detail_stats && vid || !vid)) || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1761,7 +1775,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_dropped; - } + total_size = avio_size(output_files[ost->file_index]->ctx->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(output_files[ost->file_index]->ctx->pb); secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1815,8 +1831,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } + if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1841,7 +1862,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..275f128435 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -610,6 +610,7 @@ extern char *videotoolbox_pixfmt; extern int filter_nbthreads; extern int filter_complex_nbthreads; extern int vstats_version; +extern int enable_detail_stats; extern const AVIOInterruptCB int_cb; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 58ec13e5a8..c71cf97ad9 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -110,7 +110,7 @@ float max_error_rate = 2.0/3; int filter_nbthreads = 0; int filter_complex_nbthreads = 0; int vstats_version = 2; - +int enable_detail_stats = 0; static int intra_only = 0; static int file_overwrite = 0; @@ -3529,6 +3529,8 @@ const OptionDef options[] = { "this option is deprecated, use the yadif filter instead" }, { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr }, "calculate PSNR of compressed frames" }, + { "detail_stats", OPT_BOOL | OPT_EXPERT, { &enable_detail_stats }, + "allow stats report for each output" }, { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats }, "dump video coding statistics to file" }, { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file }, -- 2.18.0.1017.ga543ac7ca45-goog
On Thu, Aug 23, 2018 at 12:43:25PM -0700, Wang Cao wrote:
From: Wang Cao <doubleecao@gmail.com>
Add an option "detail_stats" to ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The format of stats is unchanged.
Signed-off-by: Wang Cao <wangcao@google.com> --- doc/ffmpeg.texi | 4 ++++ fftools/ffmpeg.c | 53 +++++++++++++++++++++++++++++++------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 4 +++- 4 files changed, 45 insertions(+), 17 deletions(-)
breaks fate: make fate-flv-add_keyframe_index -j12 Segmentation fault (core dumped) make: *** [fate-flv-add_keyframe_index] Error 139 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have never wished to cater to the crowd; for what I know they do not approve, and what they approve I do not know. -- Epicurus
From: Wang Cao <doubleecao@gmail.com> Add an option "detail_stats" to ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The format of stats is unchanged. Signed-off-by: Wang Cao <wangcao@google.com> --- Run after "make fate" and all tests passed. doc/ffmpeg.texi | 4 ++++ fftools/ffmpeg.c | 56 +++++++++++++++++++++++++++++++------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 4 +++- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 3717f22d42..53a5be9791 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output formats to be rtp). Allows discarding specific streams or frames of streams at the demuxer. Not all demuxers support this. +@item -detail_stats (@emph{global}) +Allows printing stats for each output stream and output file at the end of +processing. + @table @option @item none Discard no frame. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2459374f08..c268be20d4 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,31 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; - - for (i = 0; i < nb_output_streams; i++) { + int nb_display_streams = 0; + AVFormatContext *oc; + + if (nb_output_streams > 0) { + nb_display_streams = enable_detail_stats ? nb_output_streams : 1; + } + for (i = 0; i < nb_display_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1552,7 +1566,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1588,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1680,13 +1702,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); @@ -1697,12 +1712,14 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + // Only print the stats for the first stream during processing + if ((is_last_report && (enable_detail_stats && vid || !vid)) || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1761,7 +1778,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_dropped; - } + total_size = avio_size(output_files[ost->file_index]->ctx->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(output_files[ost->file_index]->ctx->pb); secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1815,8 +1834,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } + if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1841,7 +1865,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..275f128435 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -610,6 +610,7 @@ extern char *videotoolbox_pixfmt; extern int filter_nbthreads; extern int filter_complex_nbthreads; extern int vstats_version; +extern int enable_detail_stats; extern const AVIOInterruptCB int_cb; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 58ec13e5a8..c71cf97ad9 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -110,7 +110,7 @@ float max_error_rate = 2.0/3; int filter_nbthreads = 0; int filter_complex_nbthreads = 0; int vstats_version = 2; - +int enable_detail_stats = 0; static int intra_only = 0; static int file_overwrite = 0; @@ -3529,6 +3529,8 @@ const OptionDef options[] = { "this option is deprecated, use the yadif filter instead" }, { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr }, "calculate PSNR of compressed frames" }, + { "detail_stats", OPT_BOOL | OPT_EXPERT, { &enable_detail_stats }, + "allow stats report for each output" }, { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats }, "dump video coding statistics to file" }, { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file }, -- 2.19.0.rc0.228.g281dcd1b4d0-goog
On Mon, Aug 27, 2018 at 11:48:46PM -0700, Wang Cao wrote:
From: Wang Cao <doubleecao@gmail.com>
Add an option "detail_stats" to ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The format of stats is unchanged.
this changes -progress output ./ffmpeg -progress progress -i mm-small-short.mp4 -f null - stream_0_0_q=-0.0 bitrate=N/A total_size=N/A -out_time_us=1002667 -out_time_ms=1002667 -out_time=00:00:01.002667 +out_time_us=1000000 +out_time_ms=1000000 +out_time=00:00:01.000000 dup_frames=0 drop_frames=0 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you fake or manipulate statistics in a paper in physics you will never get a job again. If you fake or manipulate statistics in a paper in medicin you will get a job for life at the pharma industry.
From: Wang Cao <doubleecao@gmail.com> - Add an option "detail_stats" to ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. - Make print_final_stats only output stats for one output instead of aggregate stats. Signed-off-by: Wang Cao <wangcao@google.com> --- When creating multiple outputs, the original was to aggregate size of all output files together and I find this may not be intuitive to users and choose to output the stats for the first output file instead. Using -detail_stats to ouptut stats for other output files. doc/ffmpeg.texi | 4 +++ fftools/ffmpeg.c | 72 +++++++++++++++++++++++++++++++------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 4 ++- 4 files changed, 59 insertions(+), 22 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 3717f22d42..53a5be9791 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output formats to be rtp). Allows discarding specific streams or frames of streams at the demuxer. Not all demuxers support this. +@item -detail_stats (@emph{global}) +Allows printing stats for each output stream and output file at the end of +processing. + @table @option @item none Discard no frame. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index da4259a9a8..7286e75c36 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,31 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; - - for (i = 0; i < nb_output_streams; i++) { + int nb_display_streams = 0; + AVFormatContext *oc; + + if (nb_output_streams > 0) { + nb_display_streams = enable_detail_stats ? nb_output_streams : 1; + } + for (i = 0; i < nb_display_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1552,7 +1566,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_display_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1588,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1680,16 +1702,18 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); + + /* need to collect final pts upfront because final stats depend on pts*/ + for (i = 0; i < nb_output_streams; i++) { + ost = output_streams[i]; + /* compute min output value */ + if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) + pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), + ost->st->time_base, AV_TIME_BASE_Q)); + } for (i = 0; i < nb_output_streams; i++) { float q = -1; ost = output_streams[i]; @@ -1697,12 +1721,14 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + // Only print the stats for the first video stream during processing + if ((is_last_report && (enable_detail_stats && vid || !vid)) || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1753,15 +1779,14 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "stream_%d_%d_psnr_all=%2.2f\n", ost->file_index, ost->index, p); } - vid = 1; } - /* compute min output value */ - if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) - pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), - ost->st->time_base, AV_TIME_BASE_Q)); + vid = 1; + if (is_last_report) nb_frames_drop += ost->last_dropped; - } + total_size = avio_size(output_files[ost->file_index]->ctx->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(output_files[ost->file_index]->ctx->pb); secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1817,8 +1842,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } + if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1843,7 +1873,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..275f128435 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -610,6 +610,7 @@ extern char *videotoolbox_pixfmt; extern int filter_nbthreads; extern int filter_complex_nbthreads; extern int vstats_version; +extern int enable_detail_stats; extern const AVIOInterruptCB int_cb; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index d4851a2cd8..172459be22 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -110,7 +110,7 @@ float max_error_rate = 2.0/3; int filter_nbthreads = 0; int filter_complex_nbthreads = 0; int vstats_version = 2; - +int enable_detail_stats = 0; static int intra_only = 0; static int file_overwrite = 0; @@ -3545,6 +3545,8 @@ const OptionDef options[] = { "this option is deprecated, use the yadif filter instead" }, { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr }, "calculate PSNR of compressed frames" }, + { "detail_stats", OPT_BOOL | OPT_EXPERT, { &enable_detail_stats }, + "allow stats report for each output" }, { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats }, "dump video coding statistics to file" }, { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file }, -- 2.19.1.331.ge82ca0e54c-goog
Friendly ping! On Tue, Oct 16, 2018 at 3:39 PM Wang Cao <doubleecao@gmail.com> wrote:
From: Wang Cao <doubleecao@gmail.com>
- Add an option "detail_stats" to ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. - Make print_final_stats only output stats for one output instead of aggregate stats.
Signed-off-by: Wang Cao <wangcao@google.com> --- When creating multiple outputs, the original was to aggregate size of all output files together and I find this may not be intuitive to users and choose to output the stats for the first output file instead. Using -detail_stats to ouptut stats for other output files.
doc/ffmpeg.texi | 4 +++ fftools/ffmpeg.c | 72 +++++++++++++++++++++++++++++++------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 4 ++- 4 files changed, 59 insertions(+), 22 deletions(-)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 3717f22d42..53a5be9791 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output formats to be rtp). Allows discarding specific streams or frames of streams at the demuxer. Not all demuxers support this.
+@item -detail_stats (@emph{global}) +Allows printing stats for each output stream and output file at the end of +processing. + @table @option @item none Discard no frame. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index da4259a9a8..7286e75c36 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,31 @@ static int reap_filters(int flush) return 0; }
-static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; - - for (i = 0; i < nb_output_streams; i++) { + int nb_display_streams = 0; + AVFormatContext *oc; + + if (nb_output_streams > 0) { + nb_display_streams = enable_detail_stats ? nb_output_streams : 1; + } + for (i = 0; i < nb_display_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1552,7 +1566,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_display_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb);
if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1588,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + }
/* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1680,16 +1702,18 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
t = (cur_time-timer_start) / 1000000.0;
- - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); + + /* need to collect final pts upfront because final stats depend on pts*/ + for (i = 0; i < nb_output_streams; i++) { + ost = output_streams[i]; + /* compute min output value */ + if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) + pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), + ost->st->time_base, AV_TIME_BASE_Q)); + } for (i = 0; i < nb_output_streams; i++) { float q = -1; ost = output_streams[i]; @@ -1697,12 +1721,14 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA;
- if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + // Only print the stats for the first video stream during processing + if ((is_last_report && (enable_detail_stats && vid || !vid)) || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps;
frame_number = ost->frame_number; @@ -1753,15 +1779,14 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "stream_%d_%d_psnr_all=%2.2f\n", ost->file_index, ost->index, p); } - vid = 1; } - /* compute min output value */ - if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) - pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), - ost->st->time_base, AV_TIME_BASE_Q)); + vid = 1; + if (is_last_report) nb_frames_drop += ost->last_dropped; - } + total_size = avio_size(output_files[ost->file_index]->ctx->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(output_files[ost->file_index]->ctx->pb);
secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1817,8 +1842,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); }
+ if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1843,7 +1873,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti }
if (is_last_report) - print_final_stats(total_size); + print_final_stats(); }
static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..275f128435 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -610,6 +610,7 @@ extern char *videotoolbox_pixfmt; extern int filter_nbthreads; extern int filter_complex_nbthreads; extern int vstats_version; +extern int enable_detail_stats;
extern const AVIOInterruptCB int_cb;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index d4851a2cd8..172459be22 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -110,7 +110,7 @@ float max_error_rate = 2.0/3; int filter_nbthreads = 0; int filter_complex_nbthreads = 0; int vstats_version = 2; - +int enable_detail_stats = 0;
static int intra_only = 0; static int file_overwrite = 0; @@ -3545,6 +3545,8 @@ const OptionDef options[] = { "this option is deprecated, use the yadif filter instead" }, { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr }, "calculate PSNR of compressed frames" }, + { "detail_stats", OPT_BOOL | OPT_EXPERT, { &enable_detail_stats }, + "allow stats report for each output" }, { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats }, "dump video coding statistics to file" }, { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file }, -- 2.19.1.331.ge82ca0e54c-goog
-- Wang Cao
On Mon, Nov 12, 2018 at 01:10:55PM -0800, Wang Cao wrote:
Friendly ping!
i tried the code and for example -i matrixbench_mpeg2.mpg -map 0:a -map 0:a -map 0:a -map 0:a -map 0:v -map 0:v test.nut -map 0:a -map 0:a -map 0:v -map 0:a -map 0:v -map 0:v test2.nut generates when i stop it: cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1 [nut @ 0x3b419c0] Multiple keyframes with same PTSts/s speed=5.42x Last message repeated 6 times [nut @ 0x3b5abc0] Multiple keyframes with same PTS Last message repeated 271 times size= 5285kB time=00:00:44.56 bitrate= 971.6kbits/s speed=5.39x size= 5285kB time=00:00:44.56 bitrate= 971.6kbits/s speed=5.39x size= 5285kB time=00:00:44.56 bitrate= 971.6kbits/s speed=5.39x size= 5285kB time=00:00:44.56 bitrate= 971.6kbits/s speed=5.39x q=31.0 frame= 1115 fps=135 q=31.0 Lsize= 5285kB time=00:00:44.56 bitrate= 971.6kbits/s speed=5.39x q=31.0 frame= 1115 fps=135 q=31.0 Lsize= 5285kB time=00:00:44.56 bitrate= 971.6kbits/s speed=5.39x size= 6285kB time=00:00:44.56 bitrate=1155.5kbits/s speed=5.39x size= 6285kB time=00:00:44.56 bitrate=1155.5kbits/s speed=5.39x q=31.0 frame= 1115 fps=135 q=31.0 Lsize= 6285kB time=00:00:44.56 bitrate=1155.5kbits/s speed=5.39x size= 6285kB time=00:00:44.56 bitrate=1155.5kbits/s speed=5.39x q=31.0 frame= 1115 fps=135 q=31.0 Lsize= 6285kB time=00:00:44.56 bitrate=1155.5kbits/s speed=5.39x q=31.0 frame= 1115 fps=135 q=31.0 Lsize= 6285kB time=00:00:44.56 bitrate=1155.5kbits/s speed=5.39x video:3083kB audio:2147kB subtitle:0kB other streams:0kB global headers:16kB muxing overhead: 1.048231% video:4625kB audio:1610kB subtitle:0kB other streams:0kB global headers:12kB muxing overhead: 0.803826% Its not easy to read this and know which line represents which stream also this is the same audio stream stored 7 times yet the statistics look nonsensical, one would expect 7 identical bitrates and in fact not 971kbit/sec for a vorbis audio stream with default encoding parameters [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you fake or manipulate statistics in a paper in physics you will never get a job again. If you fake or manipulate statistics in a paper in medicin you will get a job for life at the pharma industry.
participants (5)
-
Carl Eugen Hoyos -
Gyan Doshi -
Michael Niedermayer -
Moritz Barsnick -
Wang Cao