summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-04-20 09:30:00 +0200
committerAnton Khirnov <anton@khirnov.net>2023-05-02 10:59:24 +0200
commit6e487a50a10597f5bab8a4bde45f7d3a916296b4 (patch)
tree1d920c3885fecce2e09bb996c1b9beb576911deb
parent52b632b65be91264543065296a6a197d2a087c70 (diff)
fftools/ffmpeg: drop OutputStream.error
Only the first component is used in update_video_stats(), so make it a stack variable in that function.
-rw-r--r--fftools/ffmpeg.h8
-rw-r--r--fftools/ffmpeg_enc.c20
2 files changed, 13 insertions, 15 deletions
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index c3cb365a3b..c4b77ab2c8 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -671,9 +671,6 @@ typedef struct OutputStream {
/* packet quality factor */
int quality;
- /* frame encode sum of squared error values */
- int64_t error[4];
-
int sq_idx_encode;
int sq_idx_mux;
@@ -920,11 +917,6 @@ InputStream *ist_iter(InputStream *prev);
* pass NULL to start iteration */
OutputStream *ost_iter(OutputStream *prev);
-static inline double psnr(double d)
-{
- return -10.0 * log10(d);
-}
-
void close_output_stream(OutputStream *ost);
int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt);
void update_benchmark(const char *fmt, ...);
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 096e0ce14a..c368097cd0 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -581,6 +581,11 @@ void enc_stats_write(OutputStream *ost, EncStats *es,
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)
{
Encoder *e = ost->enc;
@@ -590,15 +595,16 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write
enum AVPictureType pict_type;
int64_t frame_number;
double ti1, bitrate, avg_bitrate;
+ double psnr_val = -1;
ost->quality = sd ? AV_RL32(sd) : -1;
pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE;
- for (int i = 0; i<FF_ARRAY_ELEMS(ost->error); i++) {
- if (sd && i < sd[5])
- ost->error[i] = AV_RL64(sd + 8 + 8*i);
- else
- ost->error[i] = -1;
+ if ((enc->flags & AV_CODEC_FLAG_PSNR) && sd && sd[5]) {
+ // FIXME the scaling assumes 8bit
+ double error = AV_RL64(sd + 8) / (enc->width * enc->height * 255.0 * 255.0);
+ if (error >= 0 && error <= 1)
+ psnr_val = psnr(error);
}
if (!write_vstats)
@@ -622,8 +628,8 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write
ost->quality / (float)FF_QP2LAMBDA);
}
- if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
- fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0)));
+ if (psnr_val >= 0)
+ fprintf(vstats_file, "PSNR= %6.2f ", psnr_val);
fprintf(vstats_file,"f_size= %6d ", pkt->size);
/* compute pts value */