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 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 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 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.add( inputFileName, 0, "", offset_1 ) transcoder.add( 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 testNbFramesVideoRewrap(): """ Rewrap one video stream, check nb frames. """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testNbFramesVideoRewrap.mov" ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) transcoder.add( inputFileName, 0, "" ) progress = av.ConsoleProgress() transcoder.process( progress ) # get src file of rewrap src_inputFile = av.InputFile( inputFileName ) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] # get dst file of rewrap 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 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 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 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 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 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 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 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 testTranscodeMovExtractChannelsToOneOutput(): """ Transcode the audio stream of a MOV file which contains a video stream. Extract first, third and last channels of the audio stream (5.1), and create one output streams. The encoding profile will be found from from input. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] outputFileName = "testTranscodeMovExtractChannelsToOneOutput.mov" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) inputFile = av.InputFile(inputFileName) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() audiochannelIndexArray = (0, 3, 5) transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex, audiochannelIndexArray)) 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) dst_audioProperties = dst_inputFile.getProperties().getAudioProperties() assert_equals(1, len(dst_audioProperties)) assert_equals(3, dst_audioProperties[0].getNbChannels())
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 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.add(inputFileName_first, 0) transcoder.add(inputFileName_second, 0) transcoder.add(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 testTranscodeMovExtractChannels(): """ Transcode the audio stream of a MOV file which contains a video stream. Extract channel one and third of the audio stream (5.1). 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.add(inputFileName, audioStreamIndex, 0) transcoder.add(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 testEProcessMethodLongest(): """ Process with method eProcessMethodLongest, check output duration. """ inputFileName_longest = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] inputFileName_shortest = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] outputFileName = "testEProcessMethodLongest.mov" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.setProcessMethod(av.eProcessMethodLongest) transcoder.addStream(av.InputStreamDesc(inputFileName_longest, 0)) transcoder.addStream(av.InputStreamDesc(inputFileName_shortest, 0)) progress = av.ConsoleProgress() transcoder.process(progress) # get src file src_inputFile_longest = av.InputFile(inputFileName_longest) src_properties_longest = src_inputFile_longest.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_longest.getDuration(), delta=0.05)
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 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'] inputFile = av.InputFile(inputFileName) reader = av.AudioReader(inputFile) # 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 testCheckVideoProperties(): """ Check properties of a video stream. """ # get src file inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MP4_FILE'] inputFile = av.InputFile(inputFileName) properties = inputFile.getProperties() videoStream = properties.getVideoProperties()[0] expectedTotalBitRate = 3249739 expectedVideoBitRate = 3247981 expectedCodecName = 'h264' expectedWidth = 1920 expectedHeight = 1080 expectedNbFrames = 241 expectedDuration = 10.04 expectedFps = 24 assert_equals(properties.getBitRate(), expectedTotalBitRate) assert_equals(videoStream.getBitRate(), expectedVideoBitRate) assert_equals(videoStream.getCodecName(), expectedCodecName) assert_equals(videoStream.getWidth(), expectedWidth) assert_equals(videoStream.getHeight(), expectedHeight) assert_equals(videoStream.getNbFrames(), expectedNbFrames) assert_equals(round(videoStream.getDuration(), 2), expectedDuration) assert_equals(videoStream.getFps(), expectedFps)
def testCheckAudioProperties(): """ Check properties of an audio stream. """ # get src file inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] inputFile = av.InputFile(inputFileName) properties = inputFile.getProperties() audioStream = properties.getAudioProperties()[0] expectedTotalBitRate = 4608040 expectedAudioBitRate = 4608000 expectedCodecName = 'pcm_s16le' expectedSamples = 5760000 expectedDuration = 20 expectedChannels = 6 expectedChannelLayout = '5.1' expectedSampleRate = 48000 assert_equals(properties.getBitRate(), expectedTotalBitRate) assert_equals(audioStream.getBitRate(), expectedAudioBitRate) assert_equals(audioStream.getCodecName(), expectedCodecName) assert_equals(audioStream.getNbSamples(), expectedSamples) assert_equals(round(audioStream.getDuration(), 2), expectedDuration) assert_equals(audioStream.getNbChannels(), expectedChannels) assert_equals(audioStream.getChannelLayout(), expectedChannelLayout) assert_equals(audioStream.getSampleRate(), expectedSampleRate)
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 testCheckRawVideoProperties(): """ Check properties of a raw video stream. A raw stream does not contain header (so the duration, number of frames... needs to be computed). """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_RAW_FILE'] inputFile = av.InputFile(inputFileName) properties = inputFile.getProperties() # Check format assert_true(properties.isRawFormat()) assert_equals(properties.getNbStreams(), 1) assert_equals(properties.getNbVideoStreams(), 1) assert_equals(properties.getDuration(), 0) # file duration is unknown assert_equals(properties.getBitRate(), 0) # file bitrate is unknown assert_equals(properties.getFileSize(), 256293L) # Check video stream when analyse the header videoStream = properties.getVideoProperties()[0] assert_equals(videoStream.getFps(), 25) assert_equals(videoStream.getNbFrames(), 0) # stream nbFrames is unknown assert_equals(videoStream.getDuration(), 0) # stream duration is unknown assert_equals(videoStream.getBitRate(), 0) # stream bitrate is unknown # Check video stream when analyse the first GOP inputFile.analyse(av.NoDisplayProgress(), av.eAnalyseLevelFirstGop) videoStream = properties.getVideoProperties()[0] assert_equals(videoStream.getNbFrames(), 200) assert_equals(videoStream.getDuration(), 8) assert_equals(videoStream.getBitRate(), 177200L)
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 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 testProcessWithStatistics(): """ Process one video stream with a custom profile of encoding to activate statistics. """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testProcessWithStatistics.mov" 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.avProfileTypeVideo customProfile[av.avProfileCodec] = "mpeg2video" customProfile[av.avProfileProcessStat] = "processStat" src_inputFile = av.InputFile(inputFileName) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() transcoder.add(inputFileName, videoStreamIndex, customProfile) progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned videoStat = processStat.getVideoStat(0) assert_equals(videoStat.getDuration(), src_videoStream.getDuration()) assert_equals( videoStat.getNbFrames(), int(src_videoStream.getDuration() * src_videoStream.getFps())) assert_not_equals(videoStat.getQuality(), 0) assert_not_equals(videoStat.getPSNR(), 0)
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 testVideoTranscodeWithFilter(): """ A video transcode with a yadif filter. """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testVideoTranscodeWithFilter.avi" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) inputFile = av.InputFile(inputFileName) src_videoStream = inputFile.getProperties().getVideoProperties()[0] # transcode the video stream videoStreamIndex = src_videoStream.getStreamIndex() customProfile = av.ProfileMap() customProfile[av.avProfileIdentificator] = "customProfile" customProfile[av.avProfileIdentificatorHuman] = "custom profile" customProfile[av.avProfileType] = av.avProfileTypeVideo customProfile[av.avProfileCodec] = "mpeg2video" customProfile[av.avProfilePixelFormat] = "yuv420p" transcoder.add(inputFileName, videoStreamIndex, customProfile) # add yadif filter streamTranscoder = transcoder.getStreamTranscoder(0) filterGraph = streamTranscoder.getFilterGraph() filterGraph.addFilter("yadif") progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned videoStat = processStat.getVideoStat(0) assert_equals(src_videoStream.getDuration(), videoStat.getDuration()) assert_equals( int(src_videoStream.getDuration() * src_videoStream.getFps()), 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("mpeg2video", dst_videoStream.getCodecName()) assert_equals("yuv420p", dst_videoStream.getPixelProperties().getPixelName())
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())