From 170999384db7ecb0fe6c7cee5f91434beeac9956 Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Wed, 19 Feb 2020 16:24:06 +0100 Subject: [PATCH] Fix nb samples computing into AudioProperties And complete and update unit tests --- .../properties/AudioProperties.cpp | 2 +- .../properties/AudioProperties.hpp | 2 +- test/pyTest/testNbSamples.py | 36 +++++++++++++++++-- test/pyTest/testOffset.py | 4 +-- test/pyTest/testProperties.py | 5 +-- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/AvTranscoder/properties/AudioProperties.cpp b/src/AvTranscoder/properties/AudioProperties.cpp index 2ec52828..cf5793ef 100644 --- a/src/AvTranscoder/properties/AudioProperties.cpp +++ b/src/AvTranscoder/properties/AudioProperties.cpp @@ -140,7 +140,7 @@ size_t AudioProperties::getNbSamples() const throw std::runtime_error("unknown format context"); size_t nbSamples = _formatContext->streams[_streamIndex]->nb_frames; if(nbSamples == 0) - nbSamples = getSampleRate() * getNbChannels() * getDuration(); + nbSamples = getSampleRate() * getDuration(); return nbSamples; } diff --git a/src/AvTranscoder/properties/AudioProperties.hpp b/src/AvTranscoder/properties/AudioProperties.hpp index a82f2462..68c8d839 100644 --- a/src/AvTranscoder/properties/AudioProperties.hpp +++ b/src/AvTranscoder/properties/AudioProperties.hpp @@ -22,7 +22,7 @@ class AvExport AudioProperties : public StreamProperties size_t getBitRate() const; ///< in bits/s, 0 if unknown size_t getSampleRate() const; size_t getNbChannels() const; - size_t getNbSamples() const; ///< All the channels are included. + size_t getNbSamples() const; ///< For one channel. size_t getTicksPerFrame() const; diff --git a/test/pyTest/testNbSamples.py b/test/pyTest/testNbSamples.py index 10e24d47..66479feb 100644 --- a/test/pyTest/testNbSamples.py +++ b/test/pyTest/testNbSamples.py @@ -10,12 +10,12 @@ from pyAvTranscoder import avtranscoder as av -def testNbSamplesAudioRewrap(): +def testNbSamplesAudioRewrapFromWav(): """ - Rewrap one audio stream, check nb samples. + Rewrap one audio stream from WAV file, check nb samples. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] - outputFileName = "testNbSamplesAudioRewrap.wav" + outputFileName = "testNbSamplesAudioRewrapFromWav.wav" ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) @@ -36,6 +36,35 @@ def testNbSamplesAudioRewrap(): dst_audioStream = dst_properties.getAudioProperties()[0] assert_equals( src_audioStream.getNbSamples(), dst_audioStream.getNbSamples() ) + assert_equals( src_audioStream.getNbSamples(), src_audioStream.getSampleRate() * src_audioStream.getDuration() ) + +def testNbSamplesAudioRewrapFromMov(): + """ + Rewrap one audio stream from MOV file, check nb samples. + """ + inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] + outputFileName = "testNbSamplesAudioRewrapFromMov.wav" + + ouputFile = av.OutputFile( outputFileName ) + transcoder = av.Transcoder( ouputFile ) + + transcoder.addStream( av.InputStreamDesc(inputFileName, 1) ) + + progress = av.ConsoleProgress() + transcoder.process( progress ) + + # get src file of rewrap + src_inputFile = av.InputFile( inputFileName ) + src_properties = src_inputFile.getProperties() + src_audioStream = src_properties.getAudioProperties()[0] + + # get dst file of rewrap + dst_inputFile = av.InputFile( outputFileName ) + dst_properties = dst_inputFile.getProperties() + dst_audioStream = dst_properties.getAudioProperties()[0] + + assert_equals( src_audioStream.getNbSamples(), dst_audioStream.getNbSamples() ) + assert_equals( src_audioStream.getNbSamples(), src_audioStream.getSampleRate() * src_audioStream.getDuration() ) def testNbSamplesAudioTranscode(): """ @@ -70,3 +99,4 @@ def testNbSamplesAudioTranscode(): dst_audioStream = dst_properties.getAudioProperties()[0] assert_equals( src_audioStream.getNbSamples(), dst_audioStream.getNbSamples() ) + assert_equals( src_audioStream.getNbSamples(), src_audioStream.getSampleRate() * src_audioStream.getDuration() ) diff --git a/test/pyTest/testOffset.py b/test/pyTest/testOffset.py index 278202a0..4e0d4ed9 100644 --- a/test/pyTest/testOffset.py +++ b/test/pyTest/testOffset.py @@ -103,7 +103,7 @@ def testRewrapAudioPositiveOffset(): # check output duration assert_equals( src_audioStream.getDuration() + offset, dst_audioStream.getDuration() ) - assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() * dst_audioStream.getNbChannels() ), dst_audioStream.getNbSamples() ) + assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() ), dst_audioStream.getNbSamples() ) def testRewrapAudioNegativeOffset(): @@ -134,7 +134,7 @@ def testRewrapAudioNegativeOffset(): # check output duration assert_equals( src_audioStream.getDuration() + offset, dst_audioStream.getDuration() ) - assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() * dst_audioStream.getNbChannels() ), dst_audioStream.getNbSamples() ) + assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() ), dst_audioStream.getNbSamples() ) # # The output video stream has not the correct duration. diff --git a/test/pyTest/testProperties.py b/test/pyTest/testProperties.py index 383ee6d5..48773eb2 100644 --- a/test/pyTest/testProperties.py +++ b/test/pyTest/testProperties.py @@ -150,11 +150,11 @@ def testCheckAudioProperties(): expectedAudioBitRate = 4608000 expectedCodecName = 'pcm_s16le' - expectedSamples = 5760000 expectedDuration = 20 expectedChannels = 6 expectedChannelLayout = '5.1' expectedSampleRate = 48000 + expectedSamples = expectedSampleRate * expectedDuration; assert_equals( properties.getBitRate(), expectedTotalBitRate ) assert_equals( audioStream.getBitRate(), expectedAudioBitRate ) @@ -177,4 +177,5 @@ def testCheckFilePropertiesAsJson(): import json # json.loads method throws a ValueError if it is not a valid JSON. - json.loads(inputFile.getProperties().allPropertiesAsJson()) + jsonProps = json.loads(inputFile.getProperties().allPropertiesAsJson()) + print(jsonProps) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy