ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 4785|回复: 2

[Linux] ffmpeg log 疑问

[复制链接]
发表于 2016-11-30 18:50:19 | 显示全部楼层 |阅读模式
ffmpeg转码的时候会不断的调用print_report(0, timer_start, cur_time);函数对转码状态进行报告,如果此处传入的参数是0,说明就不会输出dup=0 drop=1509937这两选项,但是我的转码长时间跑的话跑的跑的就开始打印这两项信息了,看代码怎么也不应该打印这两项信息!!非常不解,有可能是我的代码看的不到位,请各位帮忙给看下,谢谢

[C++] 纯文本查看 复制代码
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
{
    char buf[1024];
    AVBPrint buf_script;
    OutputStream *ost;
    AVFormatContext *oc;
    int64_t total_size;
    AVCodecContext *enc;
    int frame_number, vid, i;
    double bitrate;
    double speed;
    int64_t pts = INT64_MIN + 1;
    static int64_t last_time = -1;
    static int qp_histogram[52];
    int hours, mins, secs, us;
    int ret;
    float t;

    if (!print_stats && !is_last_report && !progress_avio)
        return;

    if (!is_last_report) {
        if (last_time == -1) {
            last_time = cur_time;
            return;
        }
        if ((cur_time - last_time) < 500000)
            return;
        last_time = cur_time;
    }

    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);

    buf[0] = '\0';
    vid = 0;
    av_bprint_init(&buf_script, 0, 1);
    for (i = 0; i < nb_output_streams; i++) {
        float q = -1;
        ost = output_streams[i];
        enc = ost->enc_ctx;
        if (!ost->stream_copy)
            q = ost->quality / (float) FF_QP2LAMBDA;

        if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
            snprintf(buf + strlen(buf), sizeof(buf) - strlen(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) {
            float fps;

            frame_number = ost->frame_number;
            fps = t > 1 ? frame_number / t : 0;
            snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3.*f q=%3.1f ",
                     frame_number, fps < 9.95, fps, q);
            av_bprintf(&buf_script, "frame=%d\n", frame_number);
            av_bprintf(&buf_script, "fps=%.1f\n", fps);
            av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n",
                       ost->file_index, ost->index, q);
            if (is_last_report)
                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L");
            if (qp_hist) {
                int j;
                int qp = lrintf(q);
                if (qp >= 0 && qp < FF_ARRAY_ELEMS(qp_histogram))
                    qp_histogram[qp]++;
                for (j = 0; j < 32; j++)
                    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", av_log2(qp_histogram[j] + 1));
            }

            if ((enc->flags & AV_CODEC_FLAG_PSNR) && (ost->pict_type != AV_PICTURE_TYPE_NONE || is_last_report)) {
                int j;
                double error, error_sum = 0;
                double scale, scale_sum = 0;
                double p;
                char type[3] = { 'Y','U','V' };
                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "PSNR=");
                for (j = 0; j < 3; j++) {
                    if (is_last_report) {
                        error = enc->error[j];
                        scale = enc->width * enc->height * 255.0 * 255.0 * frame_number;
                    } else {
                        error = ost->error[j];
                        scale = enc->width * enc->height * 255.0 * 255.0;
                    }
                    if (j)
                        scale /= 4;
                    error_sum += error;
                    scale_sum += scale;
                    p = psnr(error / scale);
                    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], p);
                    av_bprintf(&buf_script, "stream_%d_%d_psnr_%c=%2.2f\n",
                               ost->file_index, ost->index, type[j] | 32, p);
                }
                p = psnr(error_sum / scale_sum);
                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum / scale_sum));
                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));
        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;

    bitrate = pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1;
    speed = t != 0.0 ? (double)pts / AV_TIME_BASE / t : -1;

    if (total_size < 0) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
                                 "size=N/A time=");
    else                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
                                 "size=%8.0fkB time=", total_size / 1024.0);
    if (pts < 0)
        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "-");
    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
             "%02d:%02d:%02d.%02d ", hours, mins, secs,
             (100 * us) / AV_TIME_BASE);

    if (bitrate < 0) {
        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),"bitrate=N/A");
        av_bprintf(&buf_script, "bitrate=N/A\n");
    }else{
        snprintf(buf + strlen(buf), sizeof(buf) - strlen(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);
    av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts);
    av_bprintf(&buf_script, "out_time=%02d:%02d:%02d.%06d\n",
               hours, mins, secs, us);

    if (nb_frames_dup || nb_frames_drop)
        snprintf(buf + strlen(buf), sizeof(buf) - strlen(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) {
        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf)," speed=N/A");
        av_bprintf(&buf_script, "speed=N/A\n");
    } else {
        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf)," speed=%4.3gx", speed);
        av_bprintf(&buf_script, "speed=%4.3gx\n", speed);
    }

    if (print_stats || is_last_report) {
        const char end = is_last_report ? '\n' : '\r';
        if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
            fprintf(stderr, "%s    %c", buf, end);
        } else
            av_log(NULL, AV_LOG_INFO, "%s    %c", buf, end);

    fflush(stderr);
    }

    if (progress_avio) {
        av_bprintf(&buf_script, "progress=%s\n",
                   is_last_report ? "end" : "continue");
        avio_write(progress_avio, buf_script.str,
                   FFMIN(buf_script.len, buf_script.size - 1));
        avio_flush(progress_avio);
        av_bprint_finalize(&buf_script, NULL);
        if (is_last_report) {
            if ((ret = avio_closep(&progress_avio)) < 0)
                av_log(NULL, AV_LOG_ERROR,
                       "Error closing progress log, loss of information possible: %s\n", av_err2str(ret));
        }
    }

    if (is_last_report)
        print_final_stats(total_size);
}




日志打印信息:
[C++] 纯文本查看 复制代码
frame=4100498 fps= 25 q=18.0 size=89792657kB time=45:33:42.97 bitrate=4484.6kbits/s speed=   1x    
frame=4100514 fps= 25 q=15.0 size=89792872kB time=45:33:43.70 bitrate=4484.6kbits/s speed=   1x    
frame=4100518 fps= 25 q=20.0 size=89793197kB time=45:33:44.08 bitrate=4484.6kbits/s speed=   1x    
frame=4100540 fps= 25 q=15.0 size=89793459kB time=45:33:44.66 bitrate=4484.6kbits/s speed=   1x    
frame=4100545 fps= 25 q=14.0 size=89793549kB time=45:33:45.21 bitrate=4484.6kbits/s speed=   1x    
frame=4100565 fps= 25 q=16.0 size=89794069kB time=45:33:45.72 bitrate=4484.6kbits/s speed=   1x    
frame=4100574 fps= 25 q=15.0 size=89794185kB time=45:33:46.24 bitrate=4484.6kbits/s speed=   1x    
frame=4100588 fps= 25 q=18.0 size=89794625kB time=45:33:46.58 bitrate=4484.6kbits/s speed=   1x    
frame=4100604 fps= 25 q=15.0 size=89794841kB time=45:33:47.26 bitrate=4484.6kbits/s speed=   1x    
frame=4100610 fps= 25 q=21.0 size=89795189kB time=45:33:47.66 bitrate=4484.6kbits/s speed=   1x    
frame=4100630 fps= 25 q=15.0 size=89795426kB time=45:33:48.30 bitrate=4484.6kbits/s speed=   1x    
frame=4100635 fps= 25 q=15.0 size=89795519kB time=45:33:48.82 bitrate=4484.6kbits/s speed=   1x    
[mpegts @ 0x36417e0] DTS 10284683486 < 10391368972 out of order
[ac3 @ 0x38407a0] exponent 25 is out-of-range
[ac3 @ 0x38407a0] error decoding the audio block
[ac3 @ 0x38407a0] frame sync error
Error while decoding stream #0:1: Invalid data found when processing input
frame=4100653 fps= 25 q=16.0 size=89796010kB time=45:33:49.26 bitrate=4484.6kbits/s speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:49.82 bitrate=4484.6kbits/s dup=0 drop=9 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:50.27 bitrate=4484.6kbits/s dup=0 drop=23 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:50.78 bitrate=4484.6kbits/s dup=0 drop=35 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:51.29 bitrate=4484.6kbits/s dup=0 drop=47 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:51.76 bitrate=4484.6kbits/s dup=0 drop=60 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:52.27 bitrate=4484.5kbits/s dup=0 drop=72 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:52.85 bitrate=4484.5kbits/s dup=0 drop=84 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:53.36 bitrate=4484.5kbits/s dup=0 drop=99 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:53.81 bitrate=4484.5kbits/s dup=0 drop=112 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:54.32 bitrate=4484.5kbits/s dup=0 drop=125 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:54.83 bitrate=4484.5kbits/s dup=0 drop=136 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:55.32 bitrate=4484.5kbits/s dup=0 drop=149 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:55.86 bitrate=4484.4kbits/s dup=0 drop=160 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:56.43 bitrate=4484.4kbits/s dup=0 drop=174 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:56.92 bitrate=4484.4kbits/s dup=0 drop=189 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:57.46 bitrate=4484.4kbits/s dup=0 drop=201 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:57.97 bitrate=4484.4kbits/s dup=0 drop=213 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796047kB time=45:33:58.46 bitrate=4484.4kbits/s dup=0 drop=225 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796056kB time=45:33:58.97 bitrate=4484.4kbits/s dup=0 drop=239 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796065kB time=45:33:59.48 bitrate=4484.3kbits/s dup=0 drop=249 speed=   1x    
frame=4100656 fps= 25 q=16.0 size=89796074kB time=45:34:00.02 bitrate=4484.3kbits/s dup=0 drop=264 speed=   1x    


回复

使用道具 举报

发表于 2016-12-1 15:28:37 | 显示全部楼层
print_report仅仅是输出信息而已,其实主要还是在里面处理的时候dup或者drop了,看你的log,中途解码出错了,而且也报了[mpegts @ 0x36417e0] DTS 10284683486 < 10391368972 out of order
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-12-28 10:10:00 | 显示全部楼层
好的  谢谢大师兄
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg

GMT+8, 2024-12-27 13:05 , Processed in 0.056007 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表