|
| 1 | +import os |
| 2 | + |
| 3 | +# Check if environment is setup to run the tests |
| 4 | +if os.environ.get('AVTRANSCODER_TEST_IMAGE_PNG_FILE') is None or \ |
| 5 | + os.environ.get('AVTRANSCODER_TEST_IMAGE_JPG_FILE') is None: |
| 6 | + from nose.plugins.skip import SkipTest |
| 7 | + raise SkipTest("Need to define environment variables " |
| 8 | + "AVTRANSCODER_TEST_IMAGE_PNG_FILE and " |
| 9 | + "AVTRANSCODER_TEST_IMAGE_JPG_FILE") |
| 10 | + |
| 11 | +from nose.tools import * |
| 12 | + |
| 13 | +from pyAvTranscoder import avtranscoder as av |
| 14 | + |
| 15 | + |
| 16 | +def testTranscodePngToMjpeg(): |
| 17 | + """ |
| 18 | + Transcode one image (to mjpeg). |
| 19 | + """ |
| 20 | + inputFileName = os.environ['AVTRANSCODER_TEST_IMAGE_PNG_FILE'] |
| 21 | + outputFileName = "testTranscodePngToMjpeg.jpg" |
| 22 | + |
| 23 | + ouputFile = av.OutputFile( outputFileName ) |
| 24 | + transcoder = av.Transcoder( ouputFile ) |
| 25 | + |
| 26 | + inputFile = av.InputFile( inputFileName ) |
| 27 | + src_videoStream = inputFile.getProperties().getVideoProperties()[0] |
| 28 | + videoStreamIndex = src_videoStream.getStreamIndex() |
| 29 | + transcoder.add( inputFileName, videoStreamIndex, "mjpeg" ) |
| 30 | + |
| 31 | + progress = av.ConsoleProgress() |
| 32 | + processStat = transcoder.process( progress ) |
| 33 | + |
| 34 | + # check process stat returned |
| 35 | + videoStat = processStat.getVideoStat(0) |
| 36 | + assert_equals(1, videoStat.getNbFrames()) |
| 37 | + |
| 38 | + # get dst file of transcode |
| 39 | + dst_inputFile = av.InputFile( outputFileName ) |
| 40 | + dst_properties = dst_inputFile.getProperties() |
| 41 | + dst_videoStream = dst_properties.getVideoProperties()[0] |
| 42 | + |
| 43 | + assert_equals( "mjpeg", dst_videoStream.getCodecName() ) |
| 44 | + assert_equals( "yuvj420p", dst_videoStream.getPixelProperties().getPixelName() ) |
| 45 | + |
| 46 | + |
| 47 | +def testTranscodeJpgToMjpeg(): |
| 48 | + """ |
| 49 | + Transcode one image (to mjpeg). |
| 50 | + """ |
| 51 | + inputFileName = os.environ['AVTRANSCODER_TEST_IMAGE_JPG_FILE'] |
| 52 | + outputFileName = "testTranscodeJpgToMjpeg.jpg" |
| 53 | + |
| 54 | + ouputFile = av.OutputFile( outputFileName ) |
| 55 | + transcoder = av.Transcoder( ouputFile ) |
| 56 | + |
| 57 | + inputFile = av.InputFile( inputFileName ) |
| 58 | + src_videoStream = inputFile.getProperties().getVideoProperties()[0] |
| 59 | + videoStreamIndex = src_videoStream.getStreamIndex() |
| 60 | + transcoder.add( inputFileName, videoStreamIndex, "mjpeg" ) |
| 61 | + |
| 62 | + progress = av.ConsoleProgress() |
| 63 | + processStat = transcoder.process( progress ) |
| 64 | + |
| 65 | + # check process stat returned |
| 66 | + videoStat = processStat.getVideoStat(0) |
| 67 | + assert_equals(1, videoStat.getNbFrames()) |
| 68 | + |
| 69 | + # get dst file of transcode |
| 70 | + dst_inputFile = av.InputFile( outputFileName ) |
| 71 | + dst_properties = dst_inputFile.getProperties() |
| 72 | + dst_videoStream = dst_properties.getVideoProperties()[0] |
| 73 | + |
| 74 | + assert_equals( "mjpeg", dst_videoStream.getCodecName() ) |
| 75 | + assert_equals( "yuvj420p", dst_videoStream.getPixelProperties().getPixelName() ) |
0 commit comments