|
| 1 | +import os |
| 2 | + |
| 3 | +from nose.tools import * |
| 4 | + |
| 5 | +from pyAvTranscoder import avtranscoder as av |
| 6 | + |
| 7 | + |
| 8 | +def testSetVideoFrame(): |
| 9 | + """ |
| 10 | + Generate a video stream, and set its frame during process. |
| 11 | + """ |
| 12 | + |
| 13 | + # create output |
| 14 | + outputFileName = "testSetVideoFrame.mov" |
| 15 | + ouputFile = av.OutputFile( outputFileName ) |
| 16 | + |
| 17 | + # create video frame and codec |
| 18 | + imageDesc = av.VideoFrameDesc() |
| 19 | + imageDesc.setWidth( 1920 ) |
| 20 | + imageDesc.setHeight( 1080 ) |
| 21 | + imageDesc.setDar( 1920, 1080 ) |
| 22 | + |
| 23 | + inputPixel = av.Pixel() |
| 24 | + inputPixel.setColorComponents( av.eComponentRgb ); |
| 25 | + inputPixel.setPlanar( False ); |
| 26 | + |
| 27 | + imageDesc.setPixel( inputPixel ); |
| 28 | + |
| 29 | + inputVideoCodec = av.VideoCodec( av.eCodecTypeEncoder, "mpeg2video" ); |
| 30 | + inputVideoCodec.setImageParameters( imageDesc ); |
| 31 | + |
| 32 | + # create transcoder and add a video stream |
| 33 | + transcoder = av.Transcoder( ouputFile ) |
| 34 | + transcoder.add( "", 0, "xdcamhd422", inputVideoCodec ) |
| 35 | + videoEssence = transcoder.getStream( 0 ).getCurrentEssence() |
| 36 | + |
| 37 | + # start process |
| 38 | + transcoder.init() |
| 39 | + ouputFile.beginWrap() |
| 40 | + |
| 41 | + # process 255 frames |
| 42 | + for i in range(0,255): |
| 43 | + transcoder.processFrame() |
| 44 | + # set video frame |
| 45 | + frame = av.VideoFrame( imageDesc ) |
| 46 | + frame.getBuffer().assign(frame.getBuffer().size(), i) |
| 47 | + videoEssence.setFrame( frame ) |
| 48 | + |
| 49 | + # end process |
| 50 | + ouputFile.endWrap() |
| 51 | + |
| 52 | + # get dst file of transcode |
| 53 | + dst_inputFile = av.InputFile( outputFileName ) |
| 54 | + progress = av.NoDisplayProgress() |
| 55 | + dst_inputFile.analyse( progress, av.InputFile.eAnalyseLevelFast ) |
| 56 | + dst_properties = dst_inputFile.getProperties() |
| 57 | + dst_videoStream = dst_properties.videoStreams[0] |
| 58 | + |
| 59 | + assert_equals( "mpeg2video", dst_videoStream.codecName ) |
| 60 | + assert_equals( "MPEG-2 video", dst_videoStream.codecLongName ) |
| 61 | + assert_equals( 1920, dst_videoStream.width ) |
| 62 | + assert_equals( 1080, dst_videoStream.height ) |
| 63 | + assert_equals( 16, dst_videoStream.dar.num ) |
| 64 | + assert_equals( 9, dst_videoStream.dar.den ) |
| 65 | + |
| 66 | + |
| 67 | +def testSetAudioFrame(): |
| 68 | + """ |
| 69 | + Generate a audio stream, and set its frame during process. |
| 70 | + """ |
| 71 | + |
| 72 | + # create output |
| 73 | + outputFileName = "testSetAudioFrame.wav" |
| 74 | + ouputFile = av.OutputFile( outputFileName ) |
| 75 | + |
| 76 | + # create video frame and codec |
| 77 | + audioDesc = av.AudioFrameDesc() |
| 78 | + audioDesc.setSampleRate( 48000 ) |
| 79 | + audioDesc.setChannels( 1 ) |
| 80 | + audioDesc.setSampleFormat( "s32" ) |
| 81 | + |
| 82 | + inputAudioCodec = av.AudioCodec( av.eCodecTypeEncoder, "pcm_s24le" ); |
| 83 | + inputAudioCodec.setAudioParameters( audioDesc ); |
| 84 | + |
| 85 | + # create transcoder and add a video stream |
| 86 | + transcoder = av.Transcoder( ouputFile ) |
| 87 | + transcoder.add( "", 0, "wave24b48kmono", inputAudioCodec ) |
| 88 | + audioEssence = transcoder.getStream( 0 ).getCurrentEssence() |
| 89 | + |
| 90 | + # start process |
| 91 | + transcoder.init() |
| 92 | + ouputFile.beginWrap() |
| 93 | + |
| 94 | + # process 255 frames |
| 95 | + for i in range(0,255): |
| 96 | + transcoder.processFrame() |
| 97 | + # set video frame |
| 98 | + frame = av.AudioFrame( audioDesc ) |
| 99 | + frame.getBuffer().assign(frame.getBuffer().size(), i) |
| 100 | + audioEssence.setFrame( frame ) |
| 101 | + |
| 102 | + # end process |
| 103 | + ouputFile.endWrap() |
| 104 | + |
| 105 | + # get dst file of transcode |
| 106 | + dst_inputFile = av.InputFile( outputFileName ) |
| 107 | + progress = av.NoDisplayProgress() |
| 108 | + dst_inputFile.analyse( progress, av.InputFile.eAnalyseLevelFast ) |
| 109 | + dst_properties = dst_inputFile.getProperties() |
| 110 | + dst_audioStream = dst_properties.audioStreams[0] |
| 111 | + |
| 112 | + assert_equals( "pcm_s24le", dst_audioStream.codecName ) |
| 113 | + assert_equals( "PCM signed 24-bit little-endian", dst_audioStream.codecLongName ) |
| 114 | + assert_equals( "signed 32 bits", dst_audioStream.sampleFormat ) |
| 115 | + assert_equals( 48000, dst_audioStream.sampleRate ) |
| 116 | + assert_equals( 1, dst_audioStream.channels ) |
0 commit comments