def ListOneTarget(codecs,
                  rate,
                  videofile,
                  do_score,
                  datatable,
                  score_function=None):
    """Extend a datatable with the info about one video file's scores."""
    for codec_name in codecs:
        # For testing:
        # Allow for direct context injection rather than picking by name.
        if isinstance(codec_name, basestring):
            codec = pick_codec.PickCodec(codec_name)
            my_optimizer = optimizer.Optimizer(codec,
                                               score_function=score_function)
        else:
            my_optimizer = codec_name
            codec_name = my_optimizer.context.codec.name
        bestsofar = my_optimizer.BestEncoding(rate, videofile)
        if do_score and not bestsofar.Result():
            bestsofar.Execute()
            bestsofar.Store()
        assert (bestsofar.Result())
        # Ignore results that score less than zero.
        if my_optimizer.Score(bestsofar) < 0.0:
            return
        (datatable.setdefault(codec_name,
                              {}).setdefault(videofile.basename, []).append(
                                  (bestsofar.result['bitrate'],
                                   bestsofar.result['psnr'])))
 def test_DistinctWorkdirs(self):
     seen_dirs = set()
     for codec_name in pick_codec.AllCodecNames():
         codec = pick_codec.PickCodec(codec_name)
         context = encoder.Context(codec)
         workdir = os.path.abspath(context.cache.WorkDir())
         self.assertNotIn(
             workdir, seen_dirs,
             'Duplicate workdir %s for codec %s' % (workdir, codec_name))
         seen_dirs.add(workdir)
示例#3
0
def ListOneTarget(codecs,
                  rate,
                  videofile,
                  do_score,
                  datatable,
                  score_function=None,
                  full_results=False):
    """Extend a datatable with the info about one video file's scores."""
    for codec_name in codecs:
        # For testing:
        # Allow for direct context injection rather than picking by name.
        if isinstance(codec_name, basestring):
            codec = pick_codec.PickCodec(codec_name)
            my_optimizer = optimizer.Optimizer(codec,
                                               score_function=score_function)
        else:
            my_optimizer = codec_name
            codec_name = my_optimizer.context.codec.name
        bestsofar = my_optimizer.BestEncoding(rate, videofile)
        if do_score and not bestsofar.Result():
            bestsofar.Execute()
            bestsofar.Store()
        assert (bestsofar.Result())
        # Ignore results that score less than zero.
        if my_optimizer.Score(bestsofar) < 0.0:
            return
        if full_results:
            # Datatable is a dictionary of codec name -> result sets.
            # Each result set is an array containing result info.
            # Each result info is a dictionary containing the
            # ID of the configuration used, the
            # target bitrate, the command line, the score and the result.
            (datatable.setdefault(codec_name, {}).setdefault(
                videofile.basename, []).append({
                    'config_id':
                    bestsofar.encoder.Hashname(),
                    'target_bitrate':
                    rate,
                    'encode_command':
                    bestsofar.EncodeCommandLine(),
                    'score':
                    my_optimizer.Score(bestsofar),
                    'result':
                    bestsofar.ResultWithoutFrameData()
                }))
        else:
            # Datatable is a dictionary of codec name -> result sets.
            # Each result set is an array containing result info.
            # Each result info contains the achieved bitrate and the PSNR.
            (datatable.setdefault(codec_name, {}).setdefault(
                videofile.basename, []).append(
                    (bestsofar.result['bitrate'], bestsofar.result['psnr'])))
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--codec')
    parser.add_argument('--score', action='store_true', default=False)
    args = parser.parse_args()

    codec = pick_codec.PickCodec(args.codec)
    for classname in mpeg_settings.files.keys():
        for filename in mpeg_settings.files[classname]:
            for rate in mpeg_settings.rates[classname]:
                videofile = encoder.Videofile('../mpeg_video/%s' % filename)
                encoding = codec.BestEncoding(rate, videofile)
                print rate, filename, encoding.Score(), encoding.result
                AnalyzeVariants(encoding, args.score)
    return 0
示例#5
0
def ListMpegSingleConfigResults(codecs, datatable, score_function=None):
    encoder_list = {}
    optimizer_list = {}
    for codec_name in codecs:
        codec = pick_codec.PickCodec(codec_name)
        my_optimizer = optimizer.Optimizer(codec,
                                           score_function=score_function,
                                           file_set=mpeg_settings.MpegFiles())
        optimizer_list[codec_name] = my_optimizer
        encoder_list[codec_name] = my_optimizer.BestOverallEncoder()
    for rate, filename in sorted(mpeg_settings.MpegFiles().AllFilesAndRates()):
        videofile = encoder.Videofile(filename)
        for codec_name in codecs:
            if encoder_list[codec_name]:
                my_encoding = encoder_list[codec_name].Encoding(
                    rate, videofile)
                my_encoding.Recover()
                AddOneEncoding(codec_name, optimizer_list[codec_name],
                               my_encoding, videofile, datatable)
示例#6
0
def ListOneTarget(codecs,
                  rate,
                  videofile,
                  do_score,
                  datatable,
                  score_function=None):
    """Extend a datatable with the info about one video file's scores."""
    # pylint: disable=too-many-arguments
    for codec_name in codecs:
        # For testing:
        # Allow for direct context injection rather than picking by name.
        if isinstance(codec_name, basestring):
            codec = pick_codec.PickCodec(codec_name)
            my_optimizer = optimizer.Optimizer(codec,
                                               score_function=score_function)
        else:
            my_optimizer = codec_name
            codec_name = my_optimizer.context.codec.name
        best_encoding = my_optimizer.BestEncoding(rate, videofile)
        if do_score and not best_encoding.Result():
            best_encoding.Execute()
            best_encoding.Store()
        AddOneEncoding(codec_name, my_optimizer, best_encoding, videofile,
                       datatable)