diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-09-06 14:44:34 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-09-06 14:44:34 +0100 |
| commit | cf13d9ad7374db79546af46b37823967e5684a9a (patch) | |
| tree | eefd6928c669b1f79d717a4901ff47488d2bd3a0 /ffcmp.c | |
| parent | d0848d2371c4ab13bd56f665d081b7683fdfca14 (diff) | |
Support some more audio sample formats. Only warn about non-comparison of video once.
Diffstat (limited to 'ffcmp.c')
| -rw-r--r-- | ffcmp.c | 45 |
1 files changed, 41 insertions, 4 deletions
@@ -6,6 +6,7 @@ #endif #include <getopt.h> #include <stdbool.h> +#include <math.h> #define MAX_COMPLETE_FRAMES 64 @@ -72,6 +73,8 @@ open_file(char* filename) bool read_frame(File* file) { + static bool warned_about_video = false; + int r = av_read_frame(file->format_context, &file->packet); if (r == AVERROR_EOF) { return true; @@ -84,7 +87,10 @@ read_frame(File* file) switch (file->format_context->streams[file->packet.stream_index]->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: - fprintf(stderr, "Warning: ignoring video frame.\n"); + if (!warned_about_video) { + fprintf(stderr, "Warning: ignoring video frames.\n"); + warned_about_video = true; + } break; case AVMEDIA_TYPE_AUDIO: { @@ -129,7 +135,7 @@ void help(char const * name) { fprintf(stderr, "Syntax: %s [options] file1 file2\n", name); fprintf(stderr, "Options are:\n"); - fprintf(stderr, "\t--audio-sample-tolerance, -t specify allowable absolute difference in audio sample value\n"); + fprintf(stderr, "\t--audio-sample-tolerance, -t specify allowable difference in audio sample value, in bits (e.g. 1 means least significant bit can differ)\n"); } int main(int argc, char** argv) @@ -232,11 +238,12 @@ int main(int argc, char** argv) switch (stream->codec->sample_fmt) { case AV_SAMPLE_FMT_S16: { + int const tol = pow(2, audio_sample_tolerance - 1); int16_t* p = (int16_t *) (file[0].complete_frames[0].frame->data[0]); int16_t* q = (int16_t *) (file[1].complete_frames[0].frame->data[0]); for (int i = 0; i < channels; ++i) { for (int j = 0; j < frames; ++j) { - if (abs(*p - *q) > audio_sample_tolerance) { + if (abs(*p - *q) > tol) { different = true; fprintf(stderr, "\tsamples %d vs %d at channel %d frame %d\n", *p, *q, i, j); } @@ -246,8 +253,38 @@ int main(int argc, char** argv) } break; } + case AV_SAMPLE_FMT_S32P: + { + int const tol = pow(2, audio_sample_tolerance - 1); + int32_t** p = (int32_t **) (file[0].complete_frames[0].frame->data); + int32_t** q = (int32_t **) (file[1].complete_frames[0].frame->data); + for (int i = 0; i < channels; ++i) { + for (int j = 0; j < frames; ++j) { + if (abs(p[i][j] - q[i][j]) > tol) { + different = true; + fprintf(stderr, "\tsamples %d vs %d at channel %d frame %d\n", p[i][j], q[i][j], i, j); + } + } + } + break; + } + case AV_SAMPLE_FMT_FLTP: + { + float const tol = pow(2, audio_sample_tolerance - 1) / ((float) pow(2, 32)); + float** p = (float **) (file[0].complete_frames[0].frame->data); + float** q = (float **) (file[1].complete_frames[0].frame->data); + for (int i = 0; i < channels; ++i) { + for (int j = 0; j < frames; ++j) { + if (fabs(p[i][j] - q[i][j]) > tol) { + different = true; + fprintf(stderr, "\tsamples %f vs %f at channel %d frame %d\n", p[i][j], q[i][j], i, j); + } + } + } + break; + } default: - fprintf(stderr, "Audio frames differ and could not be compared in detail.\n"); + fprintf(stderr, "Audio frames differ and could not be compared in detail (sample format %d unsupported).\n", stream->codec->sample_fmt); break; } |
