1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100

content / test / data / gpu / webcodecs / encoding-modes.html [blame]

<!DOCTYPE html>
<!--
Check that VideoEncoder can encode in different latency and bitrate modes
-->
<html>

<head>
  <title>Encode test</title>
  <script src="webcodecs_common.js"></script>
  <script type="text/javascript">
    'use strict';
    async function main(arg) {
      const width = 640;
      const height = 480;
      const frames_in_one_pass = 15;

      let errors = 0;
      let chunks = [];
      let decoder_configs = [];

      const encoder_config = {
        codec: arg.codec,
        hardwareAcceleration: arg.acceleration,
        width: width,
        height: height,
        latencyMode: arg.latency_mode,
        bitrateMode: arg.bitrate_mode,
        bitrate: 1000000,
        framerate: 24,
        contentHint: arg.content_hint
      };

      TEST.log('Starting test with arguments: ' + JSON.stringify(arg));
      let supported = false;
      try {
        supported = (await VideoEncoder.isConfigSupported(encoder_config)).supported;
      } catch (e) {}
      if (!supported) {
        TEST.skip('Unsupported codec: ' + arg.codec);
        return;
      }

      let source = await createFrameSource(arg.source_type, width, height);
      if (!source) {
        TEST.skip('Unsupported source: ' + arg.source_type);
        return;
      }

      const init = {
        output(chunk, metadata) {
          if (metadata.decoderConfig)
            decoder_configs.push(metadata.decoderConfig);

          chunks.push(chunk);
        },
        error(e) {
          errors++;
          TEST.log(e);
        }
      };

      let encoder = new VideoEncoder(init);
      encoder.configure(encoder_config);

      for (let i = 0; i < frames_in_one_pass; i++) {
        let frame = await source.getNextFrame();
        encoder.encode(frame, { keyFrame: false });
        frame.close();
        await waitForNextFrame();
      }

      await encoder.flush();
      encoder.close();
      source.close();

      TEST.assert(
        decoder_configs.length >= 1,
        'There should be at least 1 configs');

      TEST.assert(
        chunks.length == frames_in_one_pass,
        'Output count mismatch: ' + chunks.length);

      TEST.assert(errors == 0, 'Encoding errors occurred during the test');
      TEST.log('Test completed');
    }
    addManualTestButton([{
      'source_type': 'offscreen',
      'codec': 'avc1.42001E',
      'acceleration':'prefer-software',
      'bitrate_mode': 'constant',
      'latency_mode': 'realtime'
    }]);
  </script>
</head>

<body>
</body>

</html>