diff --git a/tcd.c b/tcd.c index d851142..b615e6a 100644 --- a/tcd.c +++ b/tcd.c @@ -23,7 +23,7 @@ #define FFT_SIZE_DEFAULT 4096 #define THRESHOLD_DEFAULT 50 -#define MAX_ANALYSIS_SECS 60 +#define MAX_ANALYSIS_SECS 120 #define OVERLAP_FACTOR 2 #define ANSI_RESET "\033[0m" @@ -1082,6 +1082,12 @@ static int process_file(const char *filename, const Options *opts) int max_frames = opts->full ? INT_MAX : sample_rate * opts->max_secs; int total_frames = 0; + if (!opts->full && fmt_ctx->duration > 0 && fmt_ctx->duration != AV_NOPTS_VALUE) { + int64_t seek_ts = fmt_ctx->duration / 2; + if (av_seek_frame(fmt_ctx, -1, seek_ts, AVSEEK_FLAG_BACKWARD) >= 0) + avcodec_flush_buffers(codec_ctx); + } + float *ring = calloc(opts->fft_size * channels, sizeof(float)); int ring_pos = 0; @@ -1183,8 +1189,12 @@ static int process_file(const char *filename, const Options *opts) double expected_min = 0.90; if (bitrate > 0 && bitrate < 192000) expected_min = 0.75; else if (bitrate > 0 && bitrate < 256000) expected_min = 0.85; - if (cutoff_ratio > 0 && cutoff_ratio < expected_min - 0.08) - upscaled = 1; + if (cutoff_ratio > 0 && cutoff_ratio < expected_min - 0.08) { + if (effective_cutoff > 0 && steepness / effective_cutoff > 0.30) + upscaled = 0; + else + upscaled = 1; + } } render_visual_spectrum( @@ -1244,8 +1254,12 @@ static int process_file(const char *filename, const Options *opts) if (bitrate > 0 && bitrate < 192000) expected_min = 0.75; else if (bitrate > 0 && bitrate < 256000) expected_min = 0.85; - if (cutoff_ratio > 0 && cutoff_ratio < expected_min - 0.08) - upscaled = 1; + if (cutoff_ratio > 0 && cutoff_ratio < expected_min - 0.08) { + if (effective_cutoff > 0 && steepness / effective_cutoff > 0.30) + upscaled = 0; + else + upscaled = 1; + } if (upscaled) { printf(ANSI_YELLOW "UPSCALED" ANSI_RESET " (re-encoded from a lower-bitrate source)\n");