fftools/ffmpeg: drop OutputStream.error

Only the first component is used in update_video_stats(), so make it a
stack variable in that function.
pull/389/head
Anton Khirnov 2 years ago
parent 52b632b65b
commit 6e487a50a1
  1. 8
      fftools/ffmpeg.h
  2. 20
      fftools/ffmpeg_enc.c

@ -671,9 +671,6 @@ typedef struct OutputStream {
/* packet quality factor */ /* packet quality factor */
int quality; int quality;
/* frame encode sum of squared error values */
int64_t error[4];
int sq_idx_encode; int sq_idx_encode;
int sq_idx_mux; int sq_idx_mux;
@ -920,11 +917,6 @@ InputStream *ist_iter(InputStream *prev);
* pass NULL to start iteration */ * pass NULL to start iteration */
OutputStream *ost_iter(OutputStream *prev); OutputStream *ost_iter(OutputStream *prev);
static inline double psnr(double d)
{
return -10.0 * log10(d);
}
void close_output_stream(OutputStream *ost); void close_output_stream(OutputStream *ost);
int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt); int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt);
void update_benchmark(const char *fmt, ...); void update_benchmark(const char *fmt, ...);

@ -581,6 +581,11 @@ void enc_stats_write(OutputStream *ost, EncStats *es,
avio_flush(io); avio_flush(io);
} }
static inline double psnr(double d)
{
return -10.0 * log10(d);
}
static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats)
{ {
Encoder *e = ost->enc; Encoder *e = ost->enc;
@ -590,15 +595,16 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write
enum AVPictureType pict_type; enum AVPictureType pict_type;
int64_t frame_number; int64_t frame_number;
double ti1, bitrate, avg_bitrate; double ti1, bitrate, avg_bitrate;
double psnr_val = -1;
ost->quality = sd ? AV_RL32(sd) : -1; ost->quality = sd ? AV_RL32(sd) : -1;
pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE;
for (int i = 0; i<FF_ARRAY_ELEMS(ost->error); i++) { if ((enc->flags & AV_CODEC_FLAG_PSNR) && sd && sd[5]) {
if (sd && i < sd[5]) // FIXME the scaling assumes 8bit
ost->error[i] = AV_RL64(sd + 8 + 8*i); double error = AV_RL64(sd + 8) / (enc->width * enc->height * 255.0 * 255.0);
else if (error >= 0 && error <= 1)
ost->error[i] = -1; psnr_val = psnr(error);
} }
if (!write_vstats) if (!write_vstats)
@ -622,8 +628,8 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write
ost->quality / (float)FF_QP2LAMBDA); ost->quality / (float)FF_QP2LAMBDA);
} }
if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) if (psnr_val >= 0)
fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); fprintf(vstats_file, "PSNR= %6.2f ", psnr_val);
fprintf(vstats_file,"f_size= %6d ", pkt->size); fprintf(vstats_file,"f_size= %6d ", pkt->size);
/* compute pts value */ /* compute pts value */

Loading…
Cancel
Save