Skip to content

Commit e5cbb2a

Browse files
committed
lavd: print similiar performance hint as lavc
1 parent b17dad1 commit e5cbb2a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/video_compress/libavcodec.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,7 @@ static void *pixfmt_conv_task(void *arg) {
13921392
return NULL;
13931393
}
13941394

1395+
/// print hint to improve performance if not making it
13951396
static void check_duration(struct state_video_compress_libav *s, time_ns_t dur_ns)
13961397
{
13971398
constexpr int mov_window = 100;

src/video_decompress/libavcodec.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ struct state_libavcodec_decompress {
101101
struct hw_accel_state hwaccel;
102102

103103
_Bool h264_sps_found; ///< to avoid initial error flood, start decoding after SPS was received
104+
double mov_avg_comp_duration;
105+
long mov_avg_frames;
104106
};
105107

106108
static enum AVPixelFormat get_format_callback(struct AVCodecContext *s, const enum AVPixelFormat *fmt);
@@ -794,6 +796,33 @@ static _Bool check_first_h264_sps(struct state_libavcodec_decompress *s, unsigne
794796
return 0;
795797
}
796798

799+
/// print hint to improve performance if not making it
800+
static void check_duration(struct state_libavcodec_decompress *s, double duration)
801+
{
802+
const int mov_window = 100;
803+
if (s->mov_avg_frames >= 10 * mov_window) {
804+
return;
805+
}
806+
s->mov_avg_comp_duration = (s->mov_avg_comp_duration * (mov_window - 1) + duration) / mov_window;
807+
s->mov_avg_frames += 1;
808+
if (s->mov_avg_frames < 2 * mov_window || s->mov_avg_comp_duration < 1 / s->desc.fps) {
809+
return;
810+
}
811+
log_msg(LOG_LEVEL_WARNING, MOD_NAME "Average decompression time of last %d frames is %f ms but time per frame is only %f ms!\n",
812+
mov_window, s->mov_avg_comp_duration * 1000, 1000 / s->desc.fps);
813+
const char *hint = NULL;
814+
if ((s->codec_ctx->thread_type & FF_THREAD_SLICE) == 0 && (s->codec_ctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) != 0) {
815+
hint = "\"--param lavd-thread-count=<n>FS\" option with small <n> or 0 (nr of logical cores)";
816+
} else if (s->codec_ctx->thread_count == 1 && (s->codec_ctx->codec->capabilities & AV_CODEC_CAP_OTHER_THREADS) != 0) {
817+
hint = "\"--param lavd-thread-count=<n>\" option with small <n> or 0 (nr of logical cores)";
818+
}
819+
if (hint) {
820+
log_msg(LOG_LEVEL_WARNING, MOD_NAME "Consider adding %s to increase throughput at the expense of latency.\n",
821+
hint);
822+
}
823+
s->mov_avg_frames = LONG_MAX;
824+
}
825+
797826
static decompress_status libavcodec_decompress(void *state, unsigned char *dst, unsigned char *src,
798827
unsigned int src_len, int frame_seq, struct video_frame_callbacks *callbacks, codec_t *internal_codec)
799828
{
@@ -918,6 +947,7 @@ static decompress_status libavcodec_decompress(void *state, unsigned char *dst,
918947
struct timeval t4;
919948
gettimeofday(&t4, NULL);
920949
log_msg(LOG_LEVEL_DEBUG, MOD_NAME "Decompressing %c frame took %f sec, pixfmt change %f s.\n", av_get_picture_type_char(s->frame->pict_type), tv_diff(t1, t0), tv_diff(t4, t3));
950+
check_duration(s, tv_diff(t4, t0));
921951
}
922952

923953
if (len <= 0) {

0 commit comments

Comments
 (0)