Skip to content

Commit

Permalink
Bugfix: Operative system screen scaling different from 100% was causi…
Browse files Browse the repository at this point in the history
…ng capture problems
  • Loading branch information
Pablo committed Jan 12, 2020
1 parent a47f50f commit c9f0304
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
31 changes: 20 additions & 11 deletions plug-ins/virtuCameraMaya/virtuCameraMaya.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def save(self, stream, kind=None):

class VirtuCameraMaya(object):
# Constants
_SERVER_VERSION = (1,2,0)
_SERVER_VERSION = (1,2,1)
_SERVER_PLATFORM = 'Maya' # Please, don't exceed 10 characters (for readability purposes)
_CONFIG_FILE = 'configuration.xml' # Configuration file name
_ALPHA_BITRATE_RATIO = 0.2 # Factor of total bitrate used for Alpha
Expand Down Expand Up @@ -390,7 +390,7 @@ def _get_ffmpeg_cmd(self, fps, bitrate, port, opaque, vflip):
'-y',
'-f:v', 'rawvideo',
'-c:v', 'rawvideo',
'-s', '%dx%d'%(self._STREAM_WIDTH, self._STREAM_HEIGHT), # frame dimensions
'-s', '%dx%d'%(self._real_stream_width, self._real_stream_height), # frame dimensions
'-pix_fmt', 'bgra',
'-r', '%.3f'%fps, # frames per second
'-an', # Tells FFMPEG not to expect any audio
Expand Down Expand Up @@ -451,14 +451,22 @@ def _start_autosend(self, fps):
thread.start_new_thread(self._autosend_loop, (autosend_interval,))

def _init_capture_vars(self):
self._real_stream_width = cmds.control(self._ui_view, query=True, width=True)
self._real_stream_height = cmds.control(self._ui_view, query=True, height=True)
if self._is_streaming_screenshot:
self._sct = mss.mss()
qw = v1apiUI.MQtUtil.findControl(self._ui_view)
self._ui_view_qw = wrapInstance(long(qw), QtWidgets.QWidget)
else:
self._view = apiUI.M3dView.getM3dViewFromModelPanel(self._ui_view)
self._img = api.MImage()
self._img_len = self._STREAM_WIDTH * self._STREAM_HEIGHT * 4 # x4 - rgba pixels
self._img_len = self._real_stream_width * self._real_stream_height * 4 # x4 - rgba pixels

def _deinit_streaming_ui(self):
self._maya_exec(self._stop_streaming_ui)
# Workaround to wait for Maya to start managing views again before setting active view
time.sleep(0.2)
self._maya_exec(self._activate_orig_active_view)

def _start_streaming(self):
# Read streaming parameters from TCP:
Expand All @@ -484,9 +492,12 @@ def _start_streaming(self):
self._maya_print("Starting Viewport Streaming. %.2f fps, %.2f Mbits/s, Opaque: %d, Autosend: %d"%(fps, bitrate, opaque, self.is_autosend))

self._is_streaming_screenshot = (self._config.capture_mode == self._config.CAPMODE_SCREENSHOT)
self._maya_exec(self._start_streaming_ui)
self._maya_exec(self._init_capture_vars)

vflip = not self._is_streaming_screenshot
self._ffmpeg_cmd = self._get_ffmpeg_cmd(fps, bitrate, port, opaque, vflip)
#self._maya_print(self._ffmpeg_cmd)

try:
if hasattr(subprocess, 'STARTUPINFO'):
startupinfo = subprocess.STARTUPINFO()
Expand All @@ -497,10 +508,11 @@ def _start_streaming(self):
except:
self._tcp_send(self._CMD_ERR_FFMPEG)
self.is_streaming = False
self._deinit_streaming_ui()
self._maya_print("Error starting Ffmpeg")
return
self._fout = self._proc.stdin
self._maya_exec(self._start_streaming_ui)
self._maya_exec(self._init_capture_vars)

if self.is_autosend:
self._start_autosend(fps)

Expand All @@ -512,10 +524,7 @@ def _stop_streaming(self):
self._fout.close()
self._proc.wait()
self.is_autosend = False
self._maya_exec(self._stop_streaming_ui)
# Workaround to wait for Maya to start managing views again before setting active view
time.sleep(0.2)
self._maya_exec(self._activate_orig_active_view)
self._deinit_streaming_ui()

def _capture_viewport_buffer(self):
if self._is_closing:
Expand All @@ -529,7 +538,7 @@ def _capture_viewport_screenshot(self):
if self._is_closing:
return
pos = self._ui_view_qw.mapToGlobal(self._ui_view_qw.pos())
monitor = {"top": pos.y(), "left": pos.x()-1, "width": self._STREAM_WIDTH, "height": self._STREAM_HEIGHT}
monitor = {"top": pos.y(), "left": pos.x()-1, "width": self._real_stream_width, "height": self._real_stream_height}
img_bytes = self._sct.grab(monitor).raw
return img_bytes

Expand Down
4 changes: 2 additions & 2 deletions plug-ins/virtuCameraMaya/virtuCameraMayaConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _start_ui(self):
if cmds.windowPref(windowName, exists=True):
cmds.windowPref(windowName, remove=True)
self._ui_window = cmds.window(windowName, width=self._WINDOW_SIZE[0], height=self._WINDOW_SIZE[1], menuBarVisible=False, titleBar=True, visible=True, sizeable=True, closeCommand=self._close_ui, title='VirtuCamera Configuration')
form_lay = cmds.formLayout(width=500, height=400)
form_lay = cmds.formLayout(width=550, height=400)
col_lay = cmds.columnLayout(adjustableColumn=True, columnAttach=('both', 0), width=465)

cmds.text(label='General Settings', align='left')
Expand All @@ -388,7 +388,7 @@ def _start_ui(self):
self._cap_mode_ui = cmds.optionMenuGrp(label='Capture Mode', changeCommand=self._cap_mode_changed_ui)
cmds.menuItem(label=self.CAPMODE_BUFFER)
cmds.menuItem(label=self.CAPMODE_SCREENSHOT)
cmds.text(label=" 'Viewport Buffer' is faster. Use 'Screenshot' if you are\n having problems visualizing the viewport on the App.", align='left')
cmds.text(label=" 'Viewport Buffer' is faster. 'Screenshot' is experimental, only use it\n if you are having problems visualizing the viewport on the App.", align='left')
cmds.separator(height=25, style='none')
cmds.separator()
cmds.separator(height=15, style='none')
Expand Down

0 comments on commit c9f0304

Please sign in to comment.