コード例 #1
0
    def test_OptimizeOverMultipleEncoders(self):
        """Run the optimizer for a few cycles with a real codec.

    This may turn out to be an over-heavy test for every-checkin testing."""
        my_fileset = test_tools.TestFileSet()
        my_codec = vp8.Vp8Codec()
        my_optimizer = optimizer.Optimizer(
            my_codec, my_fileset, cache_class=encoder.EncodingDiskCache)
        # Establish a baseline.
        for bitrate, videofile_name in my_fileset.AllFilesAndRates():
            videofile = encoder.Videofile(videofile_name)
            my_encoding = my_optimizer.BestEncoding(bitrate, videofile)
            my_encoding.Execute().Store()
        # Try to improve it.
        encoding_count = 0
        while encoding_count < 10:
            (bitrate,
             videofile_name) = random.choice(my_fileset.AllFilesAndRates())
            videofile = encoder.Videofile(videofile_name)
            next_encoding = my_optimizer.BestUntriedEncoding(
                bitrate, videofile)
            if not next_encoding:
                break
            encoding_count += 1
            next_encoding.Execute().Store()
コード例 #2
0
 def test_ScoreResult(self):
     codec = vp8.Vp8Codec()
     result = {'bitrate': 100, 'psnr': 10.0}
     self.assertEqual(10.0, codec.ScoreResult(100, result))
     self.assertEqual(10.0, codec.ScoreResult(1000, result))
     # Score is reduced by 0.1 per kbps overrun.
     self.assertAlmostEqual(10.0 - 0.1, codec.ScoreResult(99, result))
     # Score floors at 0.1 for very large overruns.
     self.assertAlmostEqual(0.1, codec.ScoreResult(1, result))
     self.assertFalse(codec.ScoreResult(100, None))
コード例 #3
0
 def test_VerifyMatroskaFile(self):
     codec = vp8.Vp8Codec()
     my_optimizer = optimizer.Optimizer(codec)
     videofile = test_tools.MakeYuvFileWithOneBlankFrame(
         'one_black_frame_1024_768_30.yuv')
     encoding = my_optimizer.BestEncoding(1000, videofile)
     encoding.Execute()
     # Matroska files will be identical if generated within the same
     # clock second. So wait a bit.
     time.sleep(1)
     self.assertTrue(encoding.VerifyEncode())
コード例 #4
0
 def test_FfmpegFrameInfo(self):
     codec = vp8.Vp8Codec()
     my_optimizer = optimizer.Optimizer(codec)
     videofile = test_tools.MakeYuvFileWithOneBlankFrame(
         'one_black_frame_1024_768_30.yuv')
     encoding = my_optimizer.BestEncoding(1000, videofile)
     encoding.Execute()
     # This line comes from file_codec.Execute()
     encodedfile = '%s/%s.%s' % (encoding.Workdir(), videofile.basename,
                                 codec.extension)
     frameinfo = file_codec.FfmpegFrameInfo(encodedfile)
     self.assertEquals(len(frameinfo), 1)
     self.assertGreater(
         os.path.getsize(encodedfile) * 8, frameinfo[0]['size'])
コード例 #5
0
 def test_OneBlackFrame(self):
   codec = vp8.Vp8Codec()
   my_optimizer = optimizer.Optimizer(codec)
   videofile = test_tools.MakeYuvFileWithOneBlankFrame(
     'one_black_frame_1024_768_30.yuv')
   encoding = my_optimizer.BestEncoding(1000, videofile)
   encoding.Execute()
   # Most codecs should be good at this.
   self.assertLess(50.0, my_optimizer.Score(encoding))
   self.assertEqual(1, len(encoding.result['frame']))
   # Check that expected results are present and "reasonable".
   print encoding.result
   self.assertTrue(0.01 < encoding.result['encode_cputime'] < 0.7)
   self.assertTrue(400 < encoding.result['bitrate'] < 500)
   self.assertTrue(10000 < encoding.result['frame'][0]['size'] < 12000)
コード例 #6
0
 def test_ConfigurationFixups(self):
     codec = vp8.Vp8Codec()
     # Any value but --rt should be ignored.
     value_set = encoder.OptionValueSet(codec.option_set, '--good')
     value_set_out = codec.ConfigurationFixups(value_set)
     self.assertFalse(value_set_out.HasValue('cpu-used'))
     # Missing values should be filled in.
     value_set = encoder.OptionValueSet(codec.option_set, '--rt')
     value_set_out = codec.ConfigurationFixups(value_set)
     self.assertEqual('-1', value_set_out.GetValue('cpu-used'))
     # Positive values should be converted to -1.
     value_set = encoder.OptionValueSet(codec.option_set,
                                        '--rt --cpu-used=5')
     value_set_out = codec.ConfigurationFixups(value_set)
     self.assertEqual('-1', value_set_out.GetValue('cpu-used'))
     # Negative values should be untouched.
     value_set = encoder.OptionValueSet(codec.option_set,
                                        '--rt --cpu-used=-5')
     value_set_out = codec.ConfigurationFixups(value_set)
     self.assertEqual('-5', value_set_out.GetValue('cpu-used'))
コード例 #7
0
 def test_EncoderVersion(self):
   codec = vp8.Vp8Codec()
   self.assertRegexpMatches(codec.EncoderVersion(),
                            r'WebM Project VP8 Encoder')
コード例 #8
0
 def test_SpeedGroup(self):
   codec = vp8.Vp8Codec()
   self.assertEqual('5000', codec.SpeedGroup(5000))
コード例 #9
0
 def test_Init(self):
   codec = vp8.Vp8Codec()
   self.assertEqual(codec.name, 'vp8')