ffmpeg # muxing overhead

2019-06-13  本文已影响0人  FlyingPenguin

ost->data_size的含义就是当前流写的真实数据的大小

static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
{
...
    ost->last_mux_dts = pkt->dts;

    ost->data_size += pkt->size;
    ost->packets_written++;
...
}
static void print_final_stats(int64_t total_size)
{
    uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
    uint64_t subtitle_size = 0;
    uint64_t data_size = 0;
    float percent = -1.0;
    int i, j;
    int pass1_used = 1;

    for (i = 0; i < nb_output_streams; i++) {
        OutputStream *ost = output_streams[i];
        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; // 音频数据
            case AVMEDIA_TYPE_SUBTITLE: subtitle_size += ost->data_size; break; // 字幕数据
            default:                 other_size += ost->data_size; break; // 其它数据
        }
        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;
    }

    if (data_size && total_size>0 && total_size >= data_size)
        percent = 100.0 * (total_size - data_size) / data_size; // muxing overhead的计算

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

...
}

可见muxing overhead指的是在封装格式中,(文件总大小 - 真实数据大小)/ 真实数据大小的比例,也就是封装数据(比如ts的头信息)和真实数据的比例,这个值当然是越小越好

上一篇下一篇

猜你喜欢

热点阅读