# coding: utf-8

import logging
from ffmpeg_process import *
from scr_config import *

class FfmpegRecorder(object):

    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

    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

        return template.format(self.audio_device,
                self.video_device,
                self.scale,
                self.output_file)

    @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):
        self._scr_config.height = value

    @property
    def capture_fps(self):
        return self._scr_config.fps

    @capture_fps.setter
    def capture_fps(self, value):
        self._scr_config.fps = value

    def run(self):
        self._process.cmdline = self._ffmpeg_cmdline()
        self._process.run()
        self._should_be_running = True

    def stop(self):
        self._process.stop()
        self._should_be_running = False

    @property
    def has_crashed(self):
        return not self.running and self._should_be_running

    @property
    def running(self):
        return self._process.running

    def pause(self):
        self._process.pause()

    def unpause(self):
        self._process.unpause()

    @property
    def paused(self):
        return self._process.paused








@@ -25,16 +25,44 @@
 logging%0A
+import subprocess%0Aimport os%0A
 from ffm
@@ -762,24 +762,982 @@
 deo = False%0A
+        self.records_dir = self._setup_output_folder()%0A%0A    def _setup_output_folder(self):%0A        try:%0A            records_dir = os.path.join(os.getcwd(), 'records')%0A            logging.debug('records_dir=%25s', records_dir)%0A%0A            if not os.path.isdir(records_dir):%0A                os.mkdir(records_dir)%0A        except os.error as e:%0A            logging.error('failed to create records folder')%0A            return None%0A%0A        try:%0A            cmdline = 'net share records=%7B0%7D /GRANT:Everyone,READ /UNLIMITED ' %5C%0A                .format(records_dir)%0A%0A            logging.info('sharing records folder, cmdline=%5C'%25s%5C'', cmdline)%0A            subprocess.check_output(cmdline, stderr=subprocess.STDOUT)%0A            return records_dir%0A%0A        except subprocess.CalledProcessError as e:%0A            logging.error('failed to share records folder, net share ' + %5C%0A                    ' rc=%25d, output=%5C'%25s%5C'', e.returncode, e.output)%0A            return None%0A%0A
 %0A    def _ff
@@ -2686,16 +2686,82 @@
 mplate%0A%0A
+        output = os.path.join(self.records_dir, self.output_file)%0A
         
@@ -2881,32 +2881,22 @@
         
-self.
 output
-_file
 )%0A%0A    @

Add output folder setup