-
Notifications
You must be signed in to change notification settings - Fork 1
virtucamera.VCServer Methods
- start_serving( port )
- stop_serving()
- execute_pending_events()
- get_qr_string()
- get_qr_image_qt( box_size )
- get_qr_image_raw( box_size )
- write_qr_image_png( file_path, box_size )
- set_capture_mode( capture_mode, capture_format=None )
- set_capture_resolution( width, height )
- set_vertical_flip( use_vflip )
- update_script_labels()
Starts the server, listening for incoming connections from
VirtuCamera app in the provided TCP port.
A QR code can be generated for easy app connection after this
function returns successfully.
Parameters
----------
port : int
TCP port to open for connections.
Returns
-------
bool
True if server started successfully, False otherwise.
Related: VCServer.is_serving ||| VCServer.server_port
Stops the server. This method returns immediately but the server
is shut-down in the background due to the asyncronous nature of some
of its processes.
VCBase.server_did_stop() is called when the server
is completely stopped. Calling VCServer.start_serving() before the
server is stopped will return unsuccessfully.
Related: VCBase.server_did_stop() ||| VCServer.start_serving() ||| VCServer.is_serving ||| VCServer.is_stopping
If using event_mode VCServer.EVENTMODE_PULL, this method must
be called regularly from the main thread while
VCServer.is_event_loop_running is True, or from the moment after
the server is started with VCServer.start_serving() to the moment
after the server is completely stopped, when
VCBase.server_did_stop() is called.
This can be done with a timer-like object that some DCCs provide,
that will call a function in the main thread at regular intervals.
You have to set the interval really low, less than 0.016
seconds (60FPS) or even zero if it's allowed, as setting
a value too high will lead to low framerates and high latency.
Related: VCServer.is_event_loop_running ||| VCServer.start_serving() ||| VCBase.server_did_stop()
Returns a string that, when converted to a QR Code,
works with VirtuCamera app to connect to the server.
The server needs to be started with VCServer.start_serving()
before calling this method.
Returns
-------
str
string to be converted to QR Code.
Related: VCServer.start_serving() ||| VCServer.is_serving
Returns QR Code image for client connection as a QPixmap Qt object.
this image works with VirtuCamera app to connect to the server.
The server needs to be started with VCServer.start_serving()
before calling this method.
WARNING: You need PySide or PySide2 available in your Python path,
it's not provided with PyVirtuCamera.
Parameters
----------
box_size : int
Controls how many pixels each "box" of the QR code is
Returns
-------
QPixmap object
QR Code image as a QPixmap Qt object.
Related: VCServer.start_serving() ||| VCServer.is_serving
Returns QR Code image as a Python byte array of greyscale
pixels on each row. This image works with VirtuCamera app
to connect to the server. The server needs to be started with
VCServer.start_serving() before calling this method.
Parameters
----------
box_size : int
Controls how many pixels each "box" of the QR code is
Returns
-------
array
QR Code image as a greyscale Python array.
Related: VCServer.start_serving() ||| VCServer.is_serving
Saves a QR image as a PNG file. This image works with
VirtuCamera app to connect to the server. The server needs
to be started with VCServer.start_serving() before calling
this method.
Parameters
----------
file_path : str
Absolute path where the PNG file will be saved.
box_size : int
Controls how many pixels each "box" of the QR code is
Related: VCServer.start_serving() ||| VCServer.is_serving
This method must always be called from your implementation of
VCBase.capture_will_start(), as it prepares the server for
capturing the viewport with one of these three modes:
* VCServer.CAPMODE_SCREENSHOT - The simplest way of capturing
the viewport, it grabs screenshots of a specific
screen region with no need to handle any pixel buffer.
You must implement VCBase.get_capture_coords(), as it will
be called regularly to retrieve the coordinates
of the screen region to be captured.
This mode is the simplest but doesn't provide the Alpha
channel of the viewport, that may be used in the future
by the app to compose over the device camera. It also might
be the slowest mode depending on the DCC software.
For higher framerates VCServer.CAPMODE_BUFFER or
VCServer.CAPMODE_BUFFER_POINTER are recommended.
* VCServer.CAPMODE_BUFFER - You will have to provide a contiguous
buffer as a Python bytes-like object implementing the
'Buffer Protocol', containing raw pixels of the viewport image.
You must implement VCBase.get_capture_buffer(), as it will
be called regularly to retrieve the buffer.
* VCServer.CAPMODE_BUFFER_POINTER - It's similar to
VCServer.CAPMODE_BUFFER but you have to provide an int value
representing a memory address to the first element of the
buffer.
You must implement VCBase.get_capture_pointer(), as it will
be called regularly to retrieve the buffer pointer.
This may be usefull when the DCC software doesn't
provide an object implementing the Buffer Protocol, but it
provides a pointer, or for cases where you can extract
the pointer with ctypes, although this can be a bit hacky.
If you choose one of the buffer options, parameter 'capture_format'
must also be set depending on the channels and order of the buffer.
At the moment float buffers are not supported, only 8-bit per
channel is supported (0-255 unsigned int values).
If you choose VCServer.CAPMODE_SCREENSHOT, you don't need to
set capture_format.
Parameters
----------
capture_mode : int
Mode to be used for capturing the viewport. One of:
* VCServer.CAPMODE_SCREENSHOT
* VCServer.CAPMODE_BUFFER
* VCServer.CAPMODE_BUFFER_POINTER
capture_format : int, optional
Pixel format when a buffer is used. One of:
* VCServer.CAPFORMAT_UBYTE_RGB
* VCServer.CAPFORMAT_UBYTE_BGR
* VCServer.CAPFORMAT_UBYTE_RGBA
* VCServer.CAPFORMAT_UBYTE_BGRA
Related: VCServer.capture_mode ||| VCServer.capture_format ||| VCBase.capture_will_start() ||| VCBase.get_capture_coords() ||| VCBase.get_capture_buffer() ||| VCBase.get_capture_pointer()
This method must always be called from your implementation of
VCBase.capture_will_start(), as it prepares the server for
capturing the viewport at the provided resolution.
Whenever the capture resolution changes in the middle of
a capture session, this method must also be called from any
of your implementations of:
* VCBase.get_capture_coords()
* VCBase.get_capture_buffer()
* VCBase.get_capture_pointer()
Parameters
----------
width : int
Horizontal size of the captured image in pixels.
height : int
Vertical size of the captured image in pixels.
Related: VCServer.capture_width ||| VCServer.capture_height ||| VCBase.capture_will_start() ||| VCBase.get_capture_coords() ||| VCBase.get_capture_buffer() ||| VCBase.get_capture_pointer()
Only if you are using VCServer.CAPMODE_BUFFER or
VCServer.CAPMODE_BUFFER_POINTER as the capture_mode, this
method can be called from your implementation of
VCBase.capture_will_start() to enable or disable vertical
flip of the pixel buffer. By default it's disabled.
Parameters
----------
use_vflip : bool
Enables vertical flip of the viewport video feed
if True, disabled otherwise.
Related: VCServer.use_vflip |||VCBase.capture_will_start()
Sends custom script labels to VirtuCamera app.
Call this method when you update custom scripts
while the app is connected.