From: Paul Brossier Date: Mon, 25 Apr 2016 14:38:14 +0000 (+0200) Subject: src/io/source_avcodec.h: add _get_duration X-Git-Tag: 0.4.4~300^2~214 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=2d071ad1c546923854587280a312f23872905ee2;p=aubio.git src/io/source_avcodec.h: add _get_duration --- diff --git a/src/io/source_avcodec.c b/src/io/source_avcodec.c index 1d058f97..90a299c0 100644 --- a/src/io/source_avcodec.c +++ b/src/io/source_avcodec.c @@ -400,6 +400,14 @@ uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t * s, uint_t pos) { return ret; } +uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s) { + if (s && &(s->avFormatCtx) != NULL) { + int64_t duration = s->avFormatCtx->duration; + return s->samplerate * ((uint_t)duration / 1e6 ); + } + return 0; +} + uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) { if (s->avr != NULL) { avresample_close( s->avr ); diff --git a/src/io/source_avcodec.h b/src/io/source_avcodec.h index 71c98f67..9ca96db9 100644 --- a/src/io/source_avcodec.h +++ b/src/io/source_avcodec.h @@ -118,6 +118,8 @@ uint_t aubio_source_avcodec_get_channels (const aubio_source_avcodec_t * s); */ uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t *s, uint_t pos); +uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s); + /** close source diff --git a/tests/src/io/test-source_avcodec.c b/tests/src/io/test-source_avcodec.c index b07c9414..dc23d76c 100644 --- a/tests/src/io/test-source_avcodec.c +++ b/tests/src/io/test-source_avcodec.c @@ -38,6 +38,8 @@ int main (int argc, char **argv) if (!s) { err = 1; goto beach; } fvec_t *vec = new_fvec(hop_size); + uint_t n_frames_expected = aubio_source_avcodec_get_duration(s); + samplerate = aubio_source_avcodec_get_samplerate(s); do { @@ -46,8 +48,9 @@ int main (int argc, char **argv) n_frames += read; } while ( read == hop_size ); - PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", n_frames, samplerate, - n_frames / hop_size, source_path); + PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n", + n_frames, n_frames_expected, samplerate, n_frames / hop_size, + source_path); del_fvec (vec); del_aubio_source_avcodec (s);