<commit_before># coding: utf-8
# pylint: disable=too-many-instance-attributes
# pylint: disable=no-self-use
# pylint: disable=arguments-differ

import logging
import subprocess
import os

from abstract_recorder import *
from ffmpeg_process import *
from scr_config import *

class FfmpegRecorder(AbstractRecorder):

    def __init__(self):
        self._scr_config = ScrConfig()
        self._process = FfmpegProcess()
        self._should_be_running = False

        # always disable aero
        self._scr_config.disable_aero = True

        # set some sensible (or not) defaults
        self.scale = .5
        self.output_file = 'output.mp4'
        self.audio_device = 'virtual-audio-capturer'
        self.video_device = 'screen-capture-recorder'
        self.capture_x = 0
        self.capture_y = 0
        self.capture_width = 800
        self.capture_height = 600
        self.capture_fps = 20

        self.debug_show_video = False
        self.records_dir = self._setup_output_folder()
        logging.debug('records_dir=%s', self.records_dir)

    def _setup_output_folder(self):
        # create the folder if does not exist yet
        name = 'records'
        records_dir = os.path.join(os.getcwd(), name)

        if not os.path.isdir(records_dir):
            os.mkdir(records_dir)

        # share the folder w/ everyone, readonly
        # this is so that the recorded videos can be later accessed over
        # windows shared folders
        try:
            # test if the folder is already shared
            shares = subprocess.check_output('net share')
            if records_dir in shares:
                logging.info('records dir already shared')
                return records_dir

            # construct net share command-line
            cmdline = 'net share {0}={1} /GRANT:Everyone,READ /UNLIMITED /REMARK:"Records output"' \
                .format(name, records_dir)

            # sudo
            cmdline = 'nircmdc elevate {0}'.format(cmdline)

            logging.info('sharing records folder, cmdline=\'%s\'', cmdline)
            subprocess.call(cmdline, stderr=subprocess.STDOUT)
            return records_dir

        except Exception as e:      # pylint: disable=broad-except
            logging.error('failed to share records folder, %s', e)
            return None


    def _ffmpeg_cmdline(self):
        cmdline_template = 'ffmpeg ' + \
                '-loglevel info ' + \
                '-f dshow -i audio="{0}":video="{1}" ' + \
                '-vf scale=iw*{2}:-1 ' + \
                '-vcodec libx264 -pix_fmt yuv420p -preset ultrafast ' + \
                '-acodec libmp3lame ' + \
                '-y {3}'

        show_video_template = 'ffmpeg ' + \
                '-loglevel info ' + \
                '-f dshow -i audio="{0}":video="{1}" ' + \
                '-filter_complex [0:v]scale=iw*{2}:-1,split=2[out1][out2] ' + \
                '-map [out1] -map 0:a ' + \
                '-vcodec libx264 -pix_fmt yuv420p -preset ultrafast ' + \
                '-acodec libmp3lame ' + \
                '-y {3} ' + \
                '-map [out2] -f sdl "DO NOT CLOSE THIS WINDOW ({3})"'

        template = show_video_template if self.debug_show_video \
                                    else cmdline_template

        output = os.path.join(self.records_dir, self.output_file)
        return template.format(self.audio_device,
                self.video_device,
                self.scale,
                output)

    @property
    def capture_x(self):
        return self._scr_config.x

    @capture_x.setter
    def capture_x(self, value):
        self._scr_config.x = value

    @property
    def capture_y(self):
        return self._scr_config.y

    @capture_y.setter
    def capture_y(self, value):
        self._scr_config.y = value

    @property
    def capture_width(self):
        return self._scr_config.width

    @capture_width.setter
    def capture_width(self, value):
        self._scr_config.width = value

    @property
    def capture_height(self):
        return self._scr_config.height

    @capture_height.setter
    def capture_height(self, value):<commit_msg>Extract ffmpeg log level<commit_after># coding: utf-8
# pylint: disable=too-many-instance-attributes
# pylint: disable=no-self-use
# pylint: disable=arguments-differ

import logging
import subprocess
import os

from abstract_recorder import *
from ffmpeg_process import *
from scr_config import *

class FfmpegRecorder(AbstractRecorder):

    def __init__(self):
        self._scr_config = ScrConfig()
        self._process = FfmpegProcess()
        self._should_be_running = False

        # always disable aero
        self._scr_config.disable_aero = True

        # set some sensible (or not) defaults
        self.scale = .5
        self.output_file = 'output.mp4'
        self.audio_device = 'virtual-audio-capturer'
        self.video_device = 'screen-capture-recorder'
        self.capture_x = 0
        self.capture_y = 0
        self.capture_width = 800
        self.capture_height = 600
        self.capture_fps = 20

        self.debug_show_video = False
        self.records_dir = self._setup_output_folder()
        logging.debug('records_dir=%s', self.records_dir)

    def _setup_output_folder(self):
        # create the folder if does not exist yet
        name = 'records'
        records_dir = os.path.join(os.getcwd(), name)

        if not os.path.isdir(records_dir):
            os.mkdir(records_dir)

        # share the folder w/ everyone, readonly
        # this is so that the recorded videos can be later accessed over
        # windows shared folders
        try:
            # test if the folder is already shared
            shares = subprocess.check_output('net share')
            if records_dir in shares:
                logging.info('records dir already shared')
                return records_dir

            # construct net share command-line
            cmdline = 'net share {0}={1} /GRANT:Everyone,READ /UNLIMITED /REMARK:"Records output"' \
                .format(name, records_dir)

            # sudo
            cmdline = 'nircmdc elevate {0}'.format(cmdline)

            logging.info('sharing records folder, cmdline=\'%s\'', cmdline)
            subprocess.call(cmdline, stderr=subprocess.STDOUT)
            return records_dir

        except Exception as e:      # pylint: disable=broad-except
            logging.error('failed to share records folder, %s', e)
            return None


    def _ffmpeg_cmdline(self):
        ffmpeg_loglevel = 'info'
        cmdline_template = 'ffmpeg ' + \
                '-loglevel {loglevel} ' + \
                '-f dshow -i audio="{0}":video="{1}" ' + \
                '-vf scale=iw*{2}:-1 ' + \
                '-vcodec libx264 -pix_fmt yuv420p -preset ultrafast ' + \
                '-acodec libmp3lame ' + \
                '-y {3}'

        show_video_template = 'ffmpeg ' + \
                '-loglevel {loglevel} ' + \
                '-f dshow -i audio="{0}":video="{1}" ' + \
                '-filter_complex [0:v]scale=iw*{2}:-1,split=2[out1][out2] ' + \
                '-map [out1] -map 0:a ' + \
                '-vcodec libx264 -pix_fmt yuv420p -preset ultrafast ' + \
                '-acodec libmp3lame ' + \
                '-y {3} ' + \
                '-map [out2] -f sdl "DO NOT CLOSE THIS WINDOW ({3})"'

        template = show_video_template if self.debug_show_video \
                                    else cmdline_template

        output = os.path.join(self.records_dir, self.output_file)
        return template.format(self.audio_device,
                self.video_device,
                self.scale,
                output, loglevel=ffmpeg_loglevel)

    @property
    def capture_x(self):
        return self._scr_config.x

    @capture_x.setter
    def capture_x(self, value):
        self._scr_config.x = value

    @property
    def capture_y(self):
        return self._scr_config.y

    @capture_y.setter
    def capture_y(self, value):
        self._scr_config.y = value

    @property
    def capture_width(self):
        return self._scr_config.width

    @capture_width.setter
    def capture_width(self, value):
        self._scr_config.width = value

    @property
    def capture_height(self):
        return self._scr_config.height

    @capture_height.setter
    def capture_height(self, value):
{'fraction_non_alphanumeric': 0.10176568837986161, 'fraction_numerical': 0.01145311381531854, 'mean_word_length': 1.9270251396648044, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1632706', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2452, 'n_words': 575}