| 465 | } |
| 466 | |
| 467 | void enc_stats_write(OutputStream *ost, EncStats *es, |
| 468 | const AVFrame *frame, const AVPacket *pkt, |
| 469 | uint64_t frame_num) |
| 470 | { |
| 471 | Encoder *e = ost->enc; |
| 472 | EncoderPriv *ep = ep_from_enc(e); |
| 473 | AVIOContext *io = es->io; |
| 474 | AVRational tb = frame ? frame->time_base : pkt->time_base; |
| 475 | int64_t pts = frame ? frame->pts : pkt->pts; |
| 476 | |
| 477 | AVRational tbi = (AVRational){ 0, 1}; |
| 478 | int64_t ptsi = INT64_MAX; |
| 479 | |
| 480 | const FrameData *fd = NULL; |
| 481 | |
| 482 | if (frame ? frame->opaque_ref : pkt->opaque_ref) { |
| 483 | fd = (const FrameData*)(frame ? frame->opaque_ref->data : pkt->opaque_ref->data); |
| 484 | tbi = fd->dec.tb; |
| 485 | ptsi = fd->dec.pts; |
| 486 | } |
| 487 | |
| 488 | pthread_mutex_lock(&es->lock); |
| 489 | |
| 490 | for (size_t i = 0; i < es->nb_components; i++) { |
| 491 | const EncStatsComponent *c = &es->components[i]; |
| 492 | |
| 493 | switch (c->type) { |
| 494 | case ENC_STATS_LITERAL: avio_write (io, c->str, c->str_len); continue; |
| 495 | case ENC_STATS_FILE_IDX: avio_printf(io, "%d", ost->file->index); continue; |
| 496 | case ENC_STATS_STREAM_IDX: avio_printf(io, "%d", ost->index); continue; |
| 497 | case ENC_STATS_TIMEBASE: avio_printf(io, "%d/%d", tb.num, tb.den); continue; |
| 498 | case ENC_STATS_TIMEBASE_IN: avio_printf(io, "%d/%d", tbi.num, tbi.den); continue; |
| 499 | case ENC_STATS_PTS: avio_printf(io, "%"PRId64, pts); continue; |
| 500 | case ENC_STATS_PTS_IN: avio_printf(io, "%"PRId64, ptsi); continue; |
| 501 | case ENC_STATS_PTS_TIME: avio_printf(io, "%g", pts * av_q2d(tb)); continue; |
| 502 | case ENC_STATS_PTS_TIME_IN: avio_printf(io, "%g", ptsi == INT64_MAX ? |
| 503 | INFINITY : ptsi * av_q2d(tbi)); continue; |
| 504 | case ENC_STATS_FRAME_NUM: avio_printf(io, "%"PRIu64, frame_num); continue; |
| 505 | case ENC_STATS_FRAME_NUM_IN: avio_printf(io, "%"PRIu64, fd ? fd->dec.frame_num : -1); continue; |
| 506 | } |
| 507 | |
| 508 | if (frame) { |
| 509 | switch (c->type) { |
| 510 | case ENC_STATS_SAMPLE_NUM: avio_printf(io, "%"PRIu64, e->samples_encoded); continue; |
| 511 | case ENC_STATS_NB_SAMPLES: avio_printf(io, "%d", frame->nb_samples); continue; |
| 512 | default: av_assert0(0); |
| 513 | } |
| 514 | } else { |
| 515 | switch (c->type) { |
| 516 | case ENC_STATS_DTS: avio_printf(io, "%"PRId64, pkt->dts); continue; |
| 517 | case ENC_STATS_DTS_TIME: avio_printf(io, "%g", pkt->dts * av_q2d(tb)); continue; |
| 518 | case ENC_STATS_PKT_SIZE: avio_printf(io, "%d", pkt->size); continue; |
| 519 | case ENC_STATS_KEYFRAME: avio_write(io, (pkt->flags & AV_PKT_FLAG_KEY) ? |
| 520 | "K" : "N", 1); continue; |
| 521 | case ENC_STATS_BITRATE: { |
| 522 | double duration = FFMAX(pkt->duration, 1) * av_q2d(tb); |
| 523 | avio_printf(io, "%g", 8.0 * pkt->size / duration); |
| 524 | continue; |
no test coverage detected