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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 testTranscodeNoStream(): """ Can't process with no stream. """ outputFileName = "testTranscodeNoStream.avi" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.process()
def testSetVideoFrame(): """ Generate a video stream, and set its frame during process. """ # create output outputFileName = "testSetVideoFrame.mov" ouputFile = av.OutputFile(outputFileName) # create custom profile encodingProfile = av.ProfileMap() encodingProfile[av.avProfileIdentificator] = "encodingProfile" encodingProfile[av.avProfileIdentificatorHuman] = "custom profile" encodingProfile[av.avProfileType] = av.avProfileTypeVideo encodingProfile[av.avProfileCodec] = "mpeg2video" encodingProfile[av.avProfilePixelFormat] = "yuv422p" encodingProfile[av.avProfileWidth] = "1920" encodingProfile[av.avProfileHeight] = "1080" # create transcoder and add a video stream transcoder = av.Transcoder(ouputFile) transcoder.addGenerateStream(encodingProfile) videoDecoder = transcoder.getStreamTranscoder(0).getCurrentDecoder() # start process ouputFile.beginWrap() transcoder.preProcessCodecLatency() p = av.ConsoleProgress() # process 51 frames nbFrames = 255 for i in range(0, nbFrames, 5): transcoder.processFrame() p.progress(i, nbFrames) # set video frame frame = av.VideoFrame(av.VideoFrameDesc(1920, 1080, "rgb24")) frame.assignValue(i) videoDecoder.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_videoStream = dst_properties.getVideoProperties()[0] assert_equals("mpeg2video", dst_videoStream.getCodecName()) assert_equals(1920, dst_videoStream.getWidth()) assert_equals(1080, dst_videoStream.getHeight()) assert_equals(16, dst_videoStream.getDar().num) assert_equals(9, dst_videoStream.getDar().den)
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 testEmptyListOfInputs(): """ Add an empty list of inputs. """ # inputs inputs = av.InputStreamDescVector() # output outputFileName = "testEmptyListOfInputs.mov" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(inputs)
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() )
def testSetVideoFrame(): """ Generate a video stream, and set its frame during process. """ # create output outputFileName = "testSetVideoFrame.mov" ouputFile = av.OutputFile( outputFileName ) # create video frame and codec inputVideoCodec = av.VideoCodec( av.eCodecTypeEncoder, "mpeg2video" ); imageDesc = av.VideoFrameDesc( 1920, 1080, "rgb24" ) inputVideoCodec.setImageParameters( imageDesc ) # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) transcoder.add( "", 0, "mpeg2", inputVideoCodec ) videoDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process ouputFile.beginWrap() transcoder.preProcessCodecLatency() p = av.ConsoleProgress() # process 51 frames nbFrames = 255 for i in range(0, nbFrames, 5): transcoder.processFrame() p.progress( i, nbFrames ) # set video frame frame = av.VideoFrame( imageDesc ) frame.assign(i) videoDecoder.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_videoStream = dst_properties.getVideoProperties()[0] assert_equals( "mpeg2video", dst_videoStream.getCodecName() ) assert_equals( "MPEG-2 video", dst_videoStream.getCodecLongName() ) assert_equals( 1920, dst_videoStream.getWidth() ) assert_equals( 1080, dst_videoStream.getHeight() ) assert_equals( 16, dst_videoStream.getDar().num ) assert_equals( 9, dst_videoStream.getDar().den )
def testRewrapDummy(): """ Can't rewrap a dummy stream (no sense). """ outputFileName = "testRewrapDummy.avi" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.add("", 0, "") transcoder.add("", 0, -1, "") progress = av.NoDisplayProgress() transcoder.process(progress)
def testTranscodeDummyExistingProfileWithNoEssenceDesc(): """ Can't add a dummy stream with no essence desc (for encoder). """ outputFileName = "testTranscodeDummyExistingProfileWithNoEssenceDesc.avi" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.add("", 0, "dnxhd120") transcoder.add("", 0, -1, "dnxhd120") progress = av.NoDisplayProgress() transcoder.process(progress)
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)