<commit_before>'use strict';

const execa = require('execa');
const log = require('intel');
const get = require('lodash.get');
const videoDefaults = require('../../defaults');

module.exports = function ffmpegRemoveOrangeAndAddText(
  videoPath,
  newStart,
  outputFile,
  metrics,
  options
) {
  let extras = '';
  // on Linux you don't need to set the fontfile
  const fontFile =
    process.platform === 'darwin' ? '/System/Library/Fonts/SFNSText.ttf:' : '';

  // we only add if we collect VisualMetrics
  if (options.visualMetrics) {
    const speedIndex = `drawtext=${fontFile}enable='between(t,${Number(
      metrics.SpeedIndex
    ) /
      1000},30)':x=(w-tw)/2: y=H-124:fontcolor=white:fontsize=26:box=1:boxcolor=0x000000AA:text='SpeedIndex ${
      metrics.SpeedIndex
    }'`;

    const firstVisualChange = `drawtext=${fontFile}enable='between(t,${Number(
      metrics.FirstVisualChange
    ) /
      1000},30)':x=(w-tw)/2: y=H-180:fontcolor=white:fontsize=26:box=1:boxcolor=0x000000AA:text='FirstVisualChange ${
      metrics.FirstVisualChange
    }'`;

    const visualComplete85 = `drawtext=${fontFile}enable='between(t,${Number(
      metrics.VisualComplete85
    ) /
      1000},30)':x=(w-tw)/2: y=H-152:fontcolor=white:fontsize=26:box=1:boxcolor=0x000000AA:text='VisualComplete85 ${
      metrics.VisualComplete85
    }'`;

    const lastVisualChange = `drawtext=${fontFile}enable='between(t,${Number(
      metrics.LastVisualChange
    ) /
      1000},30)':x=(w-tw)/2: y=H-96:fontcolor=white:fontsize=26:box=1:boxcolor=0x000000AA:text='LastVisualChange ${
      metrics.LastVisualChange
    }'`;

    extras = `,${speedIndex}, ${lastVisualChange}, ${visualComplete85}, ${firstVisualChange}`;
  }

  const scriptArgs = ['-ss', newStart];
  if (options.visualMetrics) {
    // End the video on last visual change + 1 s
    const end = newStart + metrics.LastVisualChange / 1000 + 1;
    scriptArgs.push('-t', end);
  }

  scriptArgs.push('-i', videoPath, '-c:v', 'libx264', '-an');

  // keeping old legacy videoRaw
  let showTimer = options.videoRaw ? false : videoDefaults.addTimer;
  if (
    !options.videoRaw &&
    get(options, 'videoParams.addTimer', undefined) != undefined
  ) {
    showTimer = options.videoParams.addTimer;
  }

  if (showTimer) {
    scriptArgs.push(
      '-vf',
      `drawtext=${fontFile}timecode='00\\:00\\:00\\:00':rate=${
        options.videoParams.framerate
      }: x=(w-280)/2: y=H-60:fontcolor=white:fontsize=48:box=1:boxcolor=0x000000AA${extras}`
    );
  }

  scriptArgs.push('-y', outputFile);

  log.verbose('Running ffmpeg ' + scriptArgs.join(' '));

  return execa('ffmpeg', scriptArgs).then(result => result);
};<commit_msg>remove font support on Mac since we skipped Mac support for video (#480)<commit_after>'use strict';

const execa = require('execa');
const log = require('intel');
const get = require('lodash.get');
const videoDefaults = require('../../defaults');

module.exports = function ffmpegRemoveOrangeAndAddText(
  videoPath,
  newStart,
  outputFile,
  metrics,
  options
) {
  let extras = '';
  // we only add if we collect VisualMetrics
  if (options.visualMetrics) {
    const speedIndex = `drawtext=enable='between(t,${Number(
      metrics.SpeedIndex
    ) /
      1000},30)':x=(w-tw)/2: y=H-124:fontcolor=white:fontsize=26:box=1:boxcolor=0x000000AA:text='SpeedIndex ${
      metrics.SpeedIndex
    }'`;

    const firstVisualChange = `drawtext=enable='between(t,${Number(
      metrics.FirstVisualChange
    ) /
      1000},30)':x=(w-tw)/2: y=H-180:fontcolor=white:fontsize=26:box=1:boxcolor=0x000000AA:text='FirstVisualChange ${
      metrics.FirstVisualChange
    }'`;

    const visualComplete85 = `drawtext=enable='between(t,${Number(
      metrics.VisualComplete85
    ) /
      1000},30)':x=(w-tw)/2: y=H-152:fontcolor=white:fontsize=26:box=1:boxcolor=0x000000AA:text='VisualComplete85 ${
      metrics.VisualComplete85
    }'`;

    const lastVisualChange = `drawtext=enable='between(t,${Number(
      metrics.LastVisualChange
    ) /
      1000},30)':x=(w-tw)/2: y=H-96:fontcolor=white:fontsize=26:box=1:boxcolor=0x000000AA:text='LastVisualChange ${
      metrics.LastVisualChange
    }'`;

    extras = `,${speedIndex}, ${lastVisualChange}, ${visualComplete85}, ${firstVisualChange}`;
  }

  const scriptArgs = ['-ss', newStart];
  if (options.visualMetrics) {
    // End the video on last visual change + 1 s
    const end = newStart + metrics.LastVisualChange / 1000 + 1;
    scriptArgs.push('-t', end);
  }

  scriptArgs.push('-i', videoPath, '-c:v', 'libx264', '-an');

  // keeping old legacy videoRaw
  let showTimer = options.videoRaw ? false : videoDefaults.addTimer;
  if (
    !options.videoRaw &&
    get(options, 'videoParams.addTimer', undefined) != undefined
  ) {
    showTimer = options.videoParams.addTimer;
  }

  if (showTimer) {
    scriptArgs.push(
      '-vf',
      `drawtext=timecode='00\\:00\\:00\\:00':rate=${
        options.videoParams.framerate
      }: x=(w-280)/2: y=H-60:fontcolor=white:fontsize=48:box=1:boxcolor=0x000000AA${extras}`
    );
  }

  scriptArgs.push('-y', outputFile);

  log.verbose('Running ffmpeg ' + scriptArgs.join(' '));

  return execa('ffmpeg', scriptArgs).then(result => result);
};
{'fraction_non_alphanumeric': 0.16784418560244416, 'fraction_numerical': 0.04716440710330342, 'mean_word_length': 3.960227272727273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3834786', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1757, 'n_words': 282}