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 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 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 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 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 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 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 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 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 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 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 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 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 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 testTranscodeDnxhd185(): """ Transcode one video stream (profile dnxhd185). """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testTranscodeDnxhd185.mxf" 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), "dnxhd185") progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned videoStat = processStat.getVideoStat(0) # do not test duration because the profile "dnxhd185" forces the fps to 25 assert_equals( int(src_videoStream.getDuration() * src_videoStream.getFps()), videoStat.getNbFrames()) # get dst file of transcode dst_inputFile = av.InputFile(outputFileName) dst_inputFile.analyse(progress, av.eAnalyseLevelFirstGop) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] assert_equals("dnxhd", dst_videoStream.getCodecName()) expectedBitRate = 185000000 deltaBitRate = expectedBitRate * 0.05 assert_almost_equals(expectedBitRate, dst_videoStream.getBitRate(), delta=deltaBitRate) assert_equals("yuv422p", dst_videoStream.getPixelProperties().getPixelName()) assert_equals(1920, dst_videoStream.getWidth()) assert_equals(1080, dst_videoStream.getHeight()) assert_equals(1, dst_videoStream.getGopSize())
def testMultipleOffsetFromSameInputFile(): """ Process multiple streams with different offset at the beginning of the process. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] outputFileName = "testMultipleOffsetFromSameInputFile.mov" offset_1 = 10 offset_2 = 3 ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) transcoder.addStream(av.InputStreamDesc(inputFileName, 0), "", offset_1) transcoder.addStream(av.InputStreamDesc(inputFileName, 1), "", 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] src_audioStream = src_properties.getAudioProperties()[0] # get dst file dst_inputFile = av.InputFile(outputFileName) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] dst_audioStream = dst_properties.getAudioProperties()[0] # check output duration assert_equals(src_videoStream.getDuration() + offset_1, dst_videoStream.getDuration()) assert_equals( src_videoStream.getNbFrames() + (offset_1 * dst_videoStream.getFps()), dst_videoStream.getNbFrames()) assert_equals(src_audioStream.getDuration() + offset_1, dst_audioStream.getDuration()) assert_equals( src_audioStream.getNbSamples() + (offset_1 * dst_audioStream.getSampleRate() * dst_audioStream.getNbChannels()), dst_audioStream.getNbSamples())
def testTranscodeYUV420(): """ Process one video stream (custom profile of encoding, with pixel format YUV420). """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testTranscodeYUV420.avi" 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.avProfilePixelFormat] = "yuv420p" inputFile = av.InputFile(inputFileName) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() transcoder.addStream(av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile) 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 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 testTranscodeDnxhd185x(): """ Transcode one video stream (profile dnxhd185x). """ inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE'] outputFileName = "testTranscodeDnxhd185x.mxf" ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) inputFile = av.InputFile(inputFileName) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() transcoder.add(inputFileName, videoStreamIndex, "dnxhd185x") progress = av.ConsoleProgress() processStat = transcoder.process(progress) # check process stat returned videoStat = processStat.getVideoStat(0) # do not test duration because the profile "dnxhd185x" forces the fps to 25 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("dnxhd", dst_videoStream.getCodecName()) assert_equals("VC3/DNxHD", dst_videoStream.getCodecLongName()) expectedBitRate = 185000000 deltaBitRate = expectedBitRate * 0.05 assert_almost_equals(expectedBitRate, dst_videoStream.getBitRate(), delta=deltaBitRate) assert_equals("yuv422p10le", dst_videoStream.getPixelProperties().getPixelName())
def testAudioTranscodeWithFilter(): """ An audio transcode with a volume filter. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testAudioTranscodeWithFilter.wav" ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] # transcode the video stream audioStreamIndex = src_audioStream.getStreamIndex() transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kmono" ) # add volume filter (here +150% of current volume) streamTranscoder = transcoder.getStreamTranscoder(0) filterGraph = streamTranscoder.getFilterGraph() filterGraph.addFilter("volume", "1.5") 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( 1, dst_audioStream.getNbChannels() )
def testTranscodeMovVariableNbSamplesPerFrame(): """ Transcode the audio stream of a MOV file which contains a video stream. The number of samples per frame can vary to fit the gop size. AudioTransform must manage these cases. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] outputFileName = "testTranscodeMovVariableNbSamplesPerFrame.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_s24le" inputFile = av.InputFile(inputFileName) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() transcoder.add(inputFileName, audioStreamIndex, customProfile) 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("PCM signed 24-bit little-endian", dst_audioStream.getCodecLongName())