Skip to content

Fix: number of samples computing into AudioProperties #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AvTranscoder/properties/AudioProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/properties/AudioProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
36 changes: 33 additions & 3 deletions test/pyTest/testNbSamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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():
"""
Expand Down Expand Up @@ -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() )
4 changes: 2 additions & 2 deletions test/pyTest/testOffset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions test/pyTest/testProperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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