Esempio n. 1
0
def testAudioReaderChannelsExtraction():
    """
    Read the same audio stream with several AudioReaders.
    Compare decoded frames from reader of all channels, and of one channel.
    """
    inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
    inputFile = av.InputFile(inputFileName)
    streamIndex = inputFile.getProperties().getAudioProperties(
    )[0].getStreamIndex()
    channelIndex = 0

    # create reader to read all channels of the audio stream
    readerOfAllChannels = av.AudioReader(inputFile, streamIndex)
    nbChannels = readerOfAllChannels.getOutputNbChannels()
    # read first frame
    frame = av.AudioFrame(readerOfAllChannels.readNextFrame())
    sizeOfFrameWithAllChannels = frame.getSize()

    # create reader to read one channel of the audio stream
    readerOfOneChannel = av.AudioReader(inputFile, streamIndex, channelIndex)
    # read first frame
    frame = av.AudioFrame(readerOfOneChannel.readNextFrame())
    sizeOfFrameWithOneChannels = frame.getSize()

    assert_equals(sizeOfFrameWithAllChannels / nbChannels,
                  sizeOfFrameWithOneChannels)
Esempio n. 2
0
def testSetAudioFrame():
    """
    Generate a audio stream, and set its frame during process.
    """

    # create output
    outputFileName = "testSetAudioFrame.wav"
    ouputFile = av.OutputFile( outputFileName )

    # create video frame and codec
    inputAudioCodec = av.AudioCodec( av.eCodecTypeEncoder, "pcm_s24le" );
    audioDesc = av.AudioFrameDesc( 48000, 1, "s32" )
    inputAudioCodec.setAudioParameters( audioDesc );

    # create transcoder and add a video stream
    transcoder = av.Transcoder( ouputFile )
    transcoder.add(  "", 0, "wave24b48kmono", inputAudioCodec )
    audioDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder()

    # start process
    ouputFile.beginWrap()
    transcoder.preProcessCodecLatency()
    p = av.ConsoleProgress()

    # process 51 frames
    nbFrames = 255
    for i in range(0, nbFrames):
        transcoder.processFrame()
        p.progress( i, nbFrames )

        # set video frame
        frame = av.AudioFrame( audioDesc )
        frame.assign(i)
        audioDecoder.setNextFrame( frame )

    # end process
    ouputFile.endWrap()

    # get dst file of transcode
    dst_inputFile = av.InputFile( outputFileName )
    progress = av.NoDisplayProgress()
    dst_inputFile.analyse( progress, av.eAnalyseLevelHeader )
    dst_properties = dst_inputFile.getProperties()
    dst_audioStream = dst_properties.getAudioProperties()[0]

    assert_equals( "pcm_s24le", dst_audioStream.getCodecName() )
    assert_equals( "PCM signed 24-bit little-endian", dst_audioStream.getCodecLongName() )
    assert_equals( "s32", dst_audioStream.getSampleFormatName() )
    assert_equals( "signed 32 bits", dst_audioStream.getSampleFormatLongName() )
    assert_equals( 48000, dst_audioStream.getSampleRate() )
    assert_equals( 1, dst_audioStream.getNbChannels() )
Esempio n. 3
0
def testAudioFrame():
    """
    Check the size and the data buffer of a AudioFrame.
    """
    sampleRate = 48000
    nbChannels = 1
    sampleFormat = "s32"
    desc = av.AudioFrameDesc(sampleRate, nbChannels, sampleFormat)
    frame = av.AudioFrame(desc)

    assert_equals(frame.isDataAllocated(), True)
    assert_equals(frame.isAudioFrame(), True)
    assert_equals(
        frame.getDataSize(),
        frame.getNbSamplesPerChannel() * frame.getBytesPerSample() *
        nbChannels)

    frame.freeData()
    assert_equals(frame.isDataAllocated(), False)
Esempio n. 4
0
def testInvalidAudioFrameManualAllocated():
    """
    Try to create an invalid AudioFrame manually allocated.
    """
    sampleRate = 48000
    nbChannels = 1
    sampleFormat = "titi"
    desc = av.AudioFrameDesc(sampleRate, nbChannels, sampleFormat)
    frame = av.AudioFrame(desc, False)

    assert_equals(frame.isDataAllocated(), False)
    assert_equals(frame.getDataSize(), 0)
    assert_equals(frame.getSampleRate(), sampleRate)
    assert_equals(frame.getNbChannels(), nbChannels)
    assert_equals(frame.getChannelLayoutDesc(), "mono")
    assert_equals(frame.getNbSamplesPerChannel(), 1920)
    assert_equals(frame.getBytesPerSample(), 0)
    assert_equals(av.getSampleFormatName(frame.getSampleFormat()), "")

    frame.allocateData()
Esempio n. 5
0
def testInvalidAudioFrameAutoAllocated():
    """
    Try to create an invalid AudioFrame automatically allocated.
    """
    desc = av.AudioFrameDesc(4800, 1, "toto")
    av.AudioFrame(desc)