def testTranscodeMovExtractChannels(): """ Transcode the audio stream of a MOV file which contains a video stream. Extract first and fourth channels of the audio stream (5.1), and create two output streams. The encoding profile will be found from from input. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] outputFileName = "testTranscodeMovExtractChannels.mov" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) inputFile = av.InputFile(inputFileName) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() transcoder.addStream(av.InputStreamDesc(inputFileName, audioStreamIndex, 0)) transcoder.addStream(av.InputStreamDesc(inputFileName, audioStreamIndex, 3)) progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned audioStat = processStat.getAudioStat(0) assert_equals(src_audioStream.getDuration(), audioStat.getDuration()) # check dst audio streams dst_inputFile = av.InputFile(outputFileName) for dst_audioStream in dst_inputFile.getProperties().getAudioProperties(): assert_equals(1, dst_audioStream.getNbChannels())
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( av.InputStreamDesc(inputFileName, streamIndex)) nbChannels = readerOfAllChannels.getOutputNbChannels() # read first frame frame = readerOfAllChannels.readNextFrame() sizeOfFrameWithAllChannels = frame.getDataSize() # create reader to read one channel of the audio stream readerOfOneChannel = av.AudioReader( av.InputStreamDesc(inputFileName, streamIndex, channelIndex)) # read first frame frame = readerOfOneChannel.readNextFrame() sizeOfFrameWithOneChannels = frame.getDataSize() assert_equals(sizeOfFrameWithAllChannels / nbChannels, sizeOfFrameWithOneChannels)
def testEProcessMethodBasedOnStream(): """ Process with method testEProcessMethodBasedOnStream, check output duration. """ inputFileName_first = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] inputFileName_second = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] inputFileName_third = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] outputFileName = "testEProcessMethodBasedOnStream.mov" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.setProcessMethod(av.eProcessMethodBasedOnStream, 1) transcoder.addStream(av.InputStreamDesc(inputFileName_first, 0)) transcoder.addStream(av.InputStreamDesc(inputFileName_second, 0)) transcoder.addStream(av.InputStreamDesc(inputFileName_third, 0)) progress = av.ConsoleProgress() transcoder.process(progress) # get src file src_inputFile_second = av.InputFile(inputFileName_second) src_properties_second = src_inputFile_second.getProperties() # get dst file dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() for dst_stream_properties in dst_properties.getStreamProperties(): assert_almost_equals(dst_stream_properties.getDuration(), src_properties_second.getDuration(), delta=0.05)
def testAllSeveralInputsWithDifferentType(): """ Add one video and one audio to create one output stream. """ # inputs inputs = av.InputStreamDescVector() inputs.append(av.InputStreamDesc(os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'], 0)) inputs.append(av.InputStreamDesc(os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'], 0)) # output outputFileName = "testAllSeveralInputsWithDifferentType.mov" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(inputs)
def testAddImpossibleMetadata(): """ Can't add an impossible metadata to the outputFile. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testAddMetadataPlop.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) # rewrap a stream transcoder.addStream(av.InputStreamDesc(inputFileName)) # add one metadata metadata_to_check = ("undefinedMetadataKey", "undefinedMetadataValue") ouputFile.addMetadata(metadata_to_check[0], metadata_to_check[1]) progress = av.NoDisplayProgress() transcoder.process(progress) inputFile = av.InputFile(outputFileName) inputFile.analyse(progress, av.eAnalyseLevelHeader) properties = inputFile.getProperties() assert_not_in(metadata_to_check, properties.getMetadatas())
def testAddPossibleMetadata(): """ Add metadata 'date' to the outputFile. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testAddMetadataDate.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) # rewrap a stream transcoder.addStream(av.InputStreamDesc(inputFileName)) # add a set of metadata metadata_to_check = av.PropertyVector() metadata_to_check.append(("date", "value")) ouputFile.addMetadata(metadata_to_check) progress = av.NoDisplayProgress() transcoder.process(progress) inputFile = av.InputFile(outputFileName) inputFile.analyse(progress, av.eAnalyseLevelHeader) properties = inputFile.getProperties() for metadata in metadata_to_check: assert_in(metadata, properties.getMetadatas())
def testRewrapAudioPositiveOffset(): """ Rewrap one audio stream with offset at the beginning of the process. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testRewrapAudioPositiveOffset.wav" offset = 10 ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(av.InputStreamDesc(inputFileName, 0), "", offset) progress = av.ConsoleProgress() transcoder.process(progress) # get src file src_inputFile = av.InputFile(inputFileName) src_properties = src_inputFile.getProperties() src_audioStream = src_properties.getAudioProperties()[0] # get dst file dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_audioStream = dst_properties.getAudioProperties()[0] # 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())
def testTranscodeAudioNegativeOffset(): """ Transcode one audio stream (profile wave24b48kmono) with a negative offset at the beginning of the process. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testTranscodeAudioNegativeOffset.wav" offset = -5.5 ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(av.InputStreamDesc(inputFileName, 0), "wave24b48kmono", offset) progress = av.ConsoleProgress() transcoder.process(progress) # get src file src_inputFile = av.InputFile(inputFileName) src_properties = src_inputFile.getProperties() src_audioStream = src_properties.getAudioProperties()[0] # get dst file dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_audioStream = dst_properties.getAudioProperties()[0] # check output duration assert_equals(src_audioStream.getDuration() + offset, dst_audioStream.getDuration())
def testRewrapVideoNegativeOffset(): """ Rewrap one video stream with a negative offset at the beginning of the process. """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testRewrapVideoNegativeOffset.mov" offset = -5.5 ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(av.InputStreamDesc(inputFileName, 0), "", offset) progress = av.ConsoleProgress() transcoder.process(progress) # get src file src_inputFile = av.InputFile(inputFileName) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] # get dst file dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] # check output duration assert_equals(src_videoStream.getDuration() + offset, dst_videoStream.getDuration()) assert_equals( src_videoStream.getNbFrames() + (offset * dst_videoStream.getFps()), dst_videoStream.getNbFrames())
def testTranscodeVideoPositiveOffset(): """ Transcode one video stream (profile mpeg2) with offset at the beginning of the process. """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testTranscodeVideoPositiveOffset.mov" offset = 10 ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(av.InputStreamDesc(inputFileName, 0), "mpeg2", offset) progress = av.ConsoleProgress() transcoder.process(progress) # get src file src_inputFile = av.InputFile(inputFileName) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] # get dst file dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] # check output duration assert_equals(src_videoStream.getDuration() + offset, dst_videoStream.getDuration())
def testNbSamplesAudioTranscode(): """ Transcode one audio stream (to wave24b48kmono), check nb samples. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testNbSamplesAudioTranscode.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) # create custom profile customProfile = av.ProfileMap() customProfile[av.avProfileIdentificator] = "customProfile" customProfile[av.avProfileIdentificatorHuman] = "custom profile" customProfile[av.avProfileType] = av.avProfileTypeAudio customProfile[av.avProfileCodec] = "pcm_s16le" transcoder.addStream(av.InputStreamDesc(inputFileName), customProfile) progress = av.ConsoleProgress() transcoder.process(progress) # get src file of transcode src_inputFile = av.InputFile(inputFileName) src_properties = src_inputFile.getProperties() src_audioStream = src_properties.getAudioProperties()[0] # get dst file of transcode dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_audioStream = dst_properties.getAudioProperties()[0] assert_equals(src_audioStream.getNbSamples(), dst_audioStream.getNbSamples())
def testNbSamplesAudioRewrap(): """ Rewrap one audio stream, check nb samples. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testNbSamplesAudioRewrap.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(av.InputStreamDesc(inputFileName)) 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())
def testTranscodeJpgToMjpeg(): """ Transcode one image (to mjpeg). """ inputFileName = os.environ['AVTRANSCODER_TEST_IMAGE_JPG_FILE'] outputFileName = "testTranscodeJpgToMjpeg.jpg" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) inputFile = av.InputFile(inputFileName) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() transcoder.addStream(av.InputStreamDesc(inputFileName, videoStreamIndex), "mjpeg") progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned videoStat = processStat.getVideoStat(0) assert_equals(1, videoStat.getNbFrames()) # get dst file of transcode dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] assert_equals("mjpeg", dst_videoStream.getCodecName()) assert_equals("yuvj420p", dst_videoStream.getPixelProperties().getPixelName())
def testRewrapAVIVideoStream(): """ Rewrap one video stream from avi. """ # get src file of wrap inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] src_inputFile = av.InputFile( inputFileName ) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] formatList = src_properties.getFormatName().split(",") outputFileName = "testRewrapAVIVideoStream." + formatList[0] ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) transcoder.addStream( av.InputStreamDesc(inputFileName) ) processStat = transcoder.process() # check process stat returned checkVideoStat(src_videoStream, processStat.getVideoStat(0)) # get dst file of wrap dst_inputFile = av.InputFile( outputFileName ) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] # check format checkFormat(src_properties, dst_properties) # check video properties checkStream(src_videoStream, dst_videoStream)
def testRewrapRawVideoStream(): """ Rewrap one raw video stream (no format). """ # get src file of wrap inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_RAW_FILE'] src_inputFile = av.InputFile(inputFileName) src_inputFile.analyse(av.NoDisplayProgress(), av.eAnalyseLevelFirstGop) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] formatList = src_properties.getFormatName().split(",") outputFileName = "testRewrapRawVideoStream." + formatList[0] ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream( av.InputStreamDesc(inputFileName) ) processStat = transcoder.process() # check process stat returned checkVideoStat(src_videoStream, processStat.getVideoStat(0)) # get dst file of wrap dst_inputFile = av.InputFile(outputFileName) dst_inputFile.analyse(av.NoDisplayProgress(), av.eAnalyseLevelFirstGop) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] # check format checkFormat(src_properties, dst_properties) # check video properties checkStream(src_videoStream, dst_videoStream)
def testRewrapAudioStream(): """ Rewrap one audio stream. """ # get src file of wrap inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] src_inputFile = av.InputFile( inputFileName ) src_properties = src_inputFile.getProperties() src_audioStream = src_properties.getAudioProperties()[0] formatList = src_properties.getFormatName().split(",") outputFileName = "testRewrapAudioStream." + formatList[0] ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) transcoder.addStream( av.InputStreamDesc(inputFileName) ) processStat = transcoder.process() # check process stat returned audioStat = processStat.getAudioStat(0) assert_equals(src_audioStream.getDuration(), audioStat.getDuration()) # get dst file of wrap dst_inputFile = av.InputFile( outputFileName ) dst_properties = dst_inputFile.getProperties() dst_audioStream = dst_properties.getAudioProperties()[0] # check format checkFormat(src_properties, dst_properties) # check audio properties checkStream(src_audioStream, dst_audioStream)
def testAudioReaderWithGenerator(): """ Read an audio stream with the AudioReader. When there is no more data to decode, switch to a generator and process some frames. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] reader = av.AudioReader(av.InputStreamDesc(inputFileName)) # read all frames and check their size while True: frame = reader.readNextFrame() if not frame: break assert_greater(frame.getDataSize(), 0) # check if there is no next frame assert_equals(reader.readNextFrame(), None) # generate 10 frames of silence reader.continueWithGenerator() for i in xrange(0, 9): frame = reader.readNextFrame() # assuming we generate data of 1920 samples of 2 bytes nbSamplesPerChannel = 1920 bytesPerSample = 2 assert_equals( frame.getDataSize(), reader.getOutputNbChannels() * nbSamplesPerChannel * bytesPerSample)
def testVideoReaderWithGenerator(): """ Read a video stream with the VideoReader. When there is no more data to decode, switch to a generator and process some frames. """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] reader = av.VideoReader(av.InputStreamDesc(inputFileName)) # read all frames and check their size for i in xrange(0, reader.getSourceVideoProperties().getNbFrames()): frame = reader.readNextFrame() bytesPerPixel = reader.getOutputBitDepth() / 8 assert_equals( frame.getDataSize(), reader.getOutputWidth() * reader.getOutputHeight() * bytesPerPixel) # check if there is no next frame assert_equals(reader.readNextFrame(), None) # generate 10 frames of black reader.continueWithGenerator() for i in xrange(0, 9): frame = reader.readNextFrame() bytesPerPixel = reader.getOutputBitDepth() / 8 assert_equals( frame.getDataSize(), reader.getOutputWidth() * reader.getOutputHeight() * bytesPerPixel)
def testNbFramesVideoTranscode(): """ Transcode one video stream (to h264), check nb frames. """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testNbFramesVideoTranscode.mov" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(av.InputStreamDesc(inputFileName), "mpeg2") progress = av.ConsoleProgress() transcoder.process(progress) # get src file of transcode src_inputFile = av.InputFile(inputFileName) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] # get dst file of transcode dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] assert_equals(src_videoStream.getNbFrames(), dst_videoStream.getNbFrames())
def testTranscodeWave24b48kstereo(): """ Transcode one audio stream (profile wave24b48kstereo). """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testTranscodeWave24b48kstereo.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) inputFile = av.InputFile(inputFileName) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() transcoder.addStream(av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kstereo") progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned audioStat = processStat.getAudioStat(0) assert_equals(src_audioStream.getDuration(), audioStat.getDuration()) # get dst file of transcode dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_audioStream = dst_properties.getAudioProperties()[0] assert_equals("pcm_s24le", dst_audioStream.getCodecName()) assert_equals("s32", dst_audioStream.getSampleFormatName()) assert_equals("signed 32 bits", dst_audioStream.getSampleFormatLongName()) assert_equals(48000, dst_audioStream.getSampleRate()) assert_equals(2, dst_audioStream.getNbChannels())
def testMuxAudioChannelsFromDifferentFormatInputs_20(): """ Mux audio channels from different formats files, and generate one audio stereo stream """ # inputs inputFileName1 = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] inputFileName2 = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] assert_not_equals(inputFileName1, inputFileName2) inputs = av.InputStreamDescVector() inputs.append(av.InputStreamDesc(inputFileName1, 1, 1)) inputs.append(av.InputStreamDesc(inputFileName2, 0, 2)) # output outputFileName = "testMuxAudioChannelsFromDifferentFormatInputs_20.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(inputs, "wave24b48kstereo") progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned audioStat = processStat.getAudioStat(0) inputFile1 = av.InputFile(inputFileName1) inputFile2 = av.InputFile(inputFileName2) src_audioStream1 = inputFile1.getProperties().getAudioProperties()[0] src_audioStream2 = inputFile2.getProperties().getAudioProperties()[0] min_src_duration = min(src_audioStream1.getDuration(), src_audioStream2.getDuration()) assert_equals(min_src_duration, audioStat.getDuration()) # check dst file properties dst_inputFile = av.InputFile(outputFileName) dst_fileProperties = dst_inputFile.getProperties() assert_equals(min_src_duration, dst_fileProperties.getDuration()) # check dst audio streams dst_audioProperties = dst_fileProperties.getAudioProperties() assert_equals(1, len(dst_audioProperties)) assert_equals(2, dst_audioProperties[0].getNbChannels())
def testAddSeveralInputsToCreateOneOutput(): """ Add several audio inputs and create one output stream. """ # inputs inputs = av.InputStreamDescVector() inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] inputFile = av.InputFile(inputFileName) src_audioStream = inputFile.getProperties().getAudioProperties()[0] src_audioStreamIndex = src_audioStream.getStreamIndex() inputs.append( av.InputStreamDesc(inputFileName, src_audioStreamIndex, (0, 1))) inputs.append( av.InputStreamDesc(inputFileName, src_audioStreamIndex, (2, 3))) inputs.append( av.InputStreamDesc(inputFileName, src_audioStreamIndex, (4, 5))) # output outputFileName = "testAddSeveralInputsToCreateOneOutput.mov" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(inputs) # process processStat = transcoder.process() # check process stat returned audioStat = processStat.getAudioStat(0) assert_equals(src_audioStream.getDuration(), audioStat.getDuration()) # get dst file of transcode dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_audioStream = dst_properties.getAudioProperties()[0] assert_equals(src_audioStream.getCodecName(), dst_audioStream.getCodecName()) assert_equals(src_audioStream.getSampleFormatName(), dst_audioStream.getSampleFormatName()) assert_equals(src_audioStream.getSampleFormatLongName(), dst_audioStream.getSampleFormatLongName()) assert_equals(src_audioStream.getSampleRate(), dst_audioStream.getSampleRate()) assert_equals(src_audioStream.getNbChannels(), dst_audioStream.getNbChannels())
def testMultipleOffsetFromSameStream(): """ Process same stream several times with different offset at the beginning of the process. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] outputFileName = "testMultipleOffsetFromSameStream.mov" offset_1 = 2 offset_2 = -2 ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(av.InputStreamDesc(inputFileName, 0), "", offset_1) transcoder.addStream(av.InputStreamDesc(inputFileName, 0), "", offset_2) progress = av.ConsoleProgress() transcoder.process(progress) # get src file src_inputFile = av.InputFile(inputFileName) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] # get dst file dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_videoStream_1 = dst_properties.getVideoProperties()[0] dst_videoStream_2 = dst_properties.getVideoProperties()[1] # check output duration assert_equals(src_videoStream.getDuration() + offset_1, dst_videoStream_1.getDuration()) assert_equals(src_videoStream.getDuration() + offset_1, dst_videoStream_2.getDuration()) assert_equals( src_videoStream.getNbFrames() + (offset_1 * dst_videoStream_1.getFps()), dst_videoStream_1.getNbFrames()) assert_equals( src_videoStream.getNbFrames() + (offset_1 * dst_videoStream_2.getFps()), dst_videoStream_2.getNbFrames())
def testMuxAudioChannelsWithSilenceOnly_20(): """ Mux audio channels with generated silence, and generate one audio stereo stream """ # input inputs = av.InputStreamDescVector() inputs.append(av.InputStreamDesc("", 0, 0)) # empty filename to generate silence inputs.append(av.InputStreamDesc("", 0, 0)) # empty filename to generate silence # output outputFileName = "testMuxAudioChannelsWithSilenceOnly_20.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(inputs, "wave24b48kstereo") progress = av.ConsoleProgress() processStat = transcoder.process(progress)
def testMuxAudioChannelsWithSilenceProfileFromInput_20(): """ Mux audio channels with generated silence, and generate one audio stereo stream """ # input inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] inputs = av.InputStreamDescVector() inputs.append(av.InputStreamDesc(inputFileName, 0, 0)) inputs.append(av.InputStreamDesc("", 0, 0)) # empty filename to generate silence # output outputFileName = "testMuxAudioChannelsWithSilenceNoProfile_20.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(inputs) progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned audioStat = processStat.getAudioStat(0) inputFile = av.InputFile(inputFileName) src_audioStream = inputFile.getProperties().getAudioProperties()[0] assert_equals(src_audioStream.getDuration(), audioStat.getDuration()) # check dst file properties dst_inputFile = av.InputFile(outputFileName) dst_fileProperties = dst_inputFile.getProperties() assert_equals(src_audioStream.getDuration(), dst_fileProperties.getDuration()) # check dst audio streams dst_audioProperties = dst_fileProperties.getAudioProperties() assert_equals(1, len(dst_audioProperties)) assert_equals(2, dst_audioProperties[0].getNbChannels())
def testAddOneChannelWhichDoesNotExist(): """ Extract one audio channel from an input stream. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testAddOneChannelWhichDoesNotExist.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) inputFile = av.InputFile(inputFileName) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() transcoder.addStream(av.InputStreamDesc(inputFileName, audioStreamIndex, 15)) transcoder.process()
def testAddAStreamFromAFileWhichDoesNotExist(): """ Add all streams from a given file. """ # input inputFileName = "fileWhichDoesNotExist.mov" # output outputFileName = "testAddAStreamFromAFileWhichDoesNotExist.mov" ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) # process transcoder.process()
def parseConfigFile(inputConfigFile, transcoder): file = open(inputConfigFile, 'r') for line in file: line = line.strip('\n') filename, operation = line.split('=') streamIndexes, profileName = operation.split(':') if "." in streamIndexes: streamIndex, subStreamIndex = map(int, streamIndexes.split('.')) else: streamIndex = int(streamIndexes) subStreamIndex = -1 inputDesc = av.InputStreamDesc(filename, streamIndex, subStreamIndex) transcoder.addStream(inputDesc, profileName)
def testMuxAudioChannelsWithSilenceProfileFromInput_51(): """ Mux audio channels with generated silence, and generate one audio 5.1 stream """ # inputs inputFileName1 = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] inputFileName2 = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] assert_not_equals(inputFileName1, inputFileName2) inputs = av.InputStreamDescVector() inputs.append(av.InputStreamDesc("", 0, 0)) # empty filename to generate silence inputs.append(av.InputStreamDesc(inputFileName1, 1, 0)) inputs.append(av.InputStreamDesc(inputFileName2, 0, 2)) inputs.append(av.InputStreamDesc("", 0, 0)) # empty filename to generate silence inputs.append(av.InputStreamDesc(inputFileName2, 0, 1)) inputs.append(av.InputStreamDesc("", 0, 0)) # empty filename to generate silence # output outputFileName = "testMuxAudioChannelsWithSilenceProfileFromInput_51.wav" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(inputs) progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned audioStat = processStat.getAudioStat(0) inputFile1 = av.InputFile(inputFileName1) inputFile2 = av.InputFile(inputFileName2) src_audioStream1 = inputFile1.getProperties().getAudioProperties()[0] src_audioStream2 = inputFile2.getProperties().getAudioProperties()[0] min_src_duration = min(src_audioStream1.getDuration(), src_audioStream2.getDuration()) assert_equals(min_src_duration, audioStat.getDuration()) # check dst file properties dst_inputFile = av.InputFile(outputFileName) dst_fileProperties = dst_inputFile.getProperties() assert_equals(min_src_duration, dst_fileProperties.getDuration()) # check dst audio streams dst_audioProperties = dst_inputFile.getProperties().getAudioProperties() assert_equals(1, len(dst_audioProperties)) assert_equals(6, dst_audioProperties[0].getNbChannels())
def testAudioReader(): """ Read a audio stream with the AudioReader. The InputFile is created inside the reader. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] reader = av.AudioReader(av.InputStreamDesc(inputFileName)) # read all frames and check their size while True: frame = reader.readNextFrame() if not frame: break assert_greater(frame.getDataSize(), 0) # check if there is no next frame frame = reader.readNextFrame() assert_equals(reader.readNextFrame(), None)