### Install optional dependencies for tests Source: https://github.com/anrayliu/pyvidplayer2/blob/main/tests/README.md Install all optional dependencies required by the test suite using the 'all' extra. ```bash pip install pyvidplayer2[all] ``` -------------------------------- ### Install locally after removing problematic packages Source: https://github.com/anrayliu/pyvidplayer2/blob/main/tests/README.md If the installation isn't working, remove problematic packages from pyproject.toml and install locally with pip install . ```bash pip install . ``` -------------------------------- ### Install pyvidplayer2 with pip Source: https://github.com/anrayliu/pyvidplayer2/blob/main/README.md Install the pyvidplayer2 package via pip. Requires FFmpeg and FFprobe binaries accessible via PATH. ```bash pip install pyvidplayer2 ``` -------------------------------- ### Run coverage tests Source: https://github.com/anrayliu/pyvidplayer2/blob/main/tests/README.md Commands to install coverage, run the test suite, and generate an HTML coverage report. ```bash python -m pip install coverage ``` ```bash python -m coverage run -m unittest discover -s tests ``` ```bash python -m coverage html -i ``` -------------------------------- ### play() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets the active attribute to True, starting the webcam feed. ```APIDOC ## play() ### Description Sets `active` to `True`. ### Method play ### Parameters None ### Response None ``` -------------------------------- ### Pygame Integration with pyvidplayer2 Video Source: https://github.com/anrayliu/pyvidplayer2/blob/main/README.md Basic example showing how to integrate pyvidplayer2 with Pygame. Creates a Video object, displays it in a Pygame window, and handles keyboard controls for restart, pause, mute, seek, and volume. The loop draws frames only when needed and updates the display accordingly. Close the video and quit Pygame when done. ```python import pygame from pyvidplayer2 import Video # Create video object vid = Video("video.mp4") win = pygame.display.set_mode(vid.current_size) pygame.display.set_caption(vid.name) while vid.active: key = None for event in pygame.event.get(): if event.type == pygame.QUIT: vid.stop() elif event.type == pygame.KEYDOWN: key = pygame.key.name(event.key) if key == "r": vid.restart() # Rewind video to beginning elif key == "p": vid.toggle_pause() # Pause/play video elif key == "m": vid.toggle_mute() # Mute/unmute video elif key == "right": vid.seek(15) # Skip 15 seconds in video elif key == "left": vid.seek(-15) # Rewind 15 seconds in video elif key == "up": vid.set_volume(1.0) # Max volume elif key == "down": vid.set_volume(0.0) # Min volume # Only draw new frames, and only update the screen if something is drawn if vid.draw(win, (0, 0), force_draw=False): pygame.display.update() pygame.time.wait(16) # Close video when done vid.close() pygame.quit() ``` -------------------------------- ### Get version information with pyvidplayer2.get_version_info() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Prints a dictionary containing the versions of pyvidplayer2, FFmpeg, and Pygame. The version can also be accessed directly via pyvidplayer2.__version__ or pyvidplayer2.VERSION. ```python print(pyvidplayer2.get_version_info()) ``` -------------------------------- ### preview(show_fps: bool = False, max_fps: int = 60) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Opens a window and plays the video. This method hangs until the video finishes. ```APIDOC ## preview(show_fps: bool = False, max_fps: int = 60) ### Description Opens a window and plays the video. This method will hang until the video finishes. `max_fps` enforces how many times a second the video is updated. If `show_fps` is `True`, a counter will be displayed showing the actual number of new frames being rendered every second. If using a graphics library other than Pygame, this method doesn't accept any arguments. ### Method preview ### Parameters #### Request Body - **show_fps** (bool) - Optional - If True, display FPS counter. Default is False. - **max_fps** (int) - Optional - Maximum frames per second. Default is 60. ### Response None ``` -------------------------------- ### preview() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Opens a window and plays the webcam. This method will hang until the window is closed. Videos are played at whatever fps the webcam object is set to. ```APIDOC ## preview() ### Description Opens a window and plays the webcam. This method will hang until the window is closed. Videos are played at whatever fps the webcam object is set to. ### Method preview ### Parameters None ### Response None ``` -------------------------------- ### resume() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Resumes the video. ```APIDOC ## resume() ### Description Resumes the video. ### Method resume ### Parameters None ### Response None ``` -------------------------------- ### play() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets the active attribute to True and begins playback of the video. ```APIDOC ## play() ### Description Sets `active` to `True` and begins playback. ### Method play ### Parameters None ### Response None ``` -------------------------------- ### show_subs() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Displays subtitles. ```APIDOC ## show_subs() ### Description Displays subtitles. ### Method show_subs ### Parameters None ### Response None ``` -------------------------------- ### update() -> bool Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Performs required calculations for the video. Returns True if a new frame is ready to be displayed. ```APIDOC ## update() -> bool ### Description Allows video to perform required calculations. `draw` automatically calls this method, so it doesn't need to be explicitly called. Returns `True` if a new frame is ready to be displayed. ### Method update ### Parameters None ### Response #### Success Response - **bool** - True if a new frame is ready to be displayed. ``` -------------------------------- ### Video Parameters Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Configuration parameters for initializing video playback in pyvidplayer2, including audio output device, video reader backend, and CUDA hardware acceleration settings. ```APIDOC ## Video Parameters ### Description Configuration parameters for initializing video playback in pyvidplayer2, including audio output device, video reader backend, and CUDA hardware acceleration settings. ### Parameters - **audio_output_device** (int) - Optional - Specifies the audio output device for each video. Automatically calculated if not provided. See `audio_devices_demo.py` in the examples directory for more information. If using Pygame instead of Sounddevice, setting output device can be done in the mixer init settings, independent of pyvidplayer2. - **reader** (int) - Optional - Specifies which video reading backend to use. Can be `pyvidplayer2.READER_AUTO` (chooses the best backend automatically), `pyvidplayer2.READER_OPENCV` (requires `opencv-python`), `pyvidplayer2.READER_DECORD` (requires `decord`), `pyvidplayer2.READER_IMAGEIO` (requires `imageio`), and `pyvidplayer2.READER_FFMPEG`. There are fundamental differences between readers. For example, the colour format varies. `READER_OPENCV` and `READER_FFMPEG` use BGR while `READER_IMAGEIO` and `READER_DECORD` use RGB. This information is stored in the `colour_format` attribute. Not every feature will work with every reader. Some are specialized for certain tasks, so you can always try a different one if the current one is not working. Frame seeking with `READER_IMAGEIO` is significantly slower than the rest. - **cuda_device** (int) - Optional - Specifies which Nvidia GPU to use for hardware acceleration. First GPU device is 0, second is 1, and so on. Default is -1, which disables hardware acceleration. Note: this may not result in significant performance gains because all the currently supported graphics libraries must convert video frames with CPU for software rendering. Only in situations like video seeking, where the bottleneck is from decoding instead of rendering, will there be performance gains. ``` -------------------------------- ### VideoPlayer.enqueue(input) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Same exact method as queue, but with a more conventionally correct name. Keeping queue for backwards compatibility. ```APIDOC ## enqueue(input) ### Description Same exact method as `queue`, but with a more conventionally correct name. Keeping `queue` for backwards compatibility. ### Method enqueue(input) ### Parameters - **input** (pyvidplayer2.VideoPygame | str) - Required - Path to a video or a Video object to add to the queue. ### Response None ``` -------------------------------- ### Open Video in a Context Manager with Video() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Use a context manager to automatically call close() when the block exits. The Video object is available as vid inside the with block. ```python with Video("example.mp4") as vid: vid.preview() ``` -------------------------------- ### VideoPlayer.preview(max_fps) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Similar to Video.preview(). ```APIDOC ## preview(max_fps) ### Description Similar to `Video.preview()`. ### Method preview(max_fps) ### Parameters - **max_fps** (int) - Optional - Maximum frames per second. Defaults to 60. ### Response None ``` -------------------------------- ### FFprobe path getter and setter Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Getter and setter for the path to the FFprobe executable. The default path is "ffprobe" (relative path). ```python get_ffprobe_path() -> str set_ffprobe_path(path: str) -> None ``` -------------------------------- ### resize(size) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets dimensions that captured frames will then be resized to. ```APIDOC ## resize(size) ### Description Sets dimensions that captured frames will then be resized to. ### Method resize ### Parameters - **size** ((int, int)) - Required - Dimensions to resize frames to. ### Response None ``` -------------------------------- ### set_ffmpeg_path(path: str) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Setter for path to FFmpeg executable. Default is "ffmpeg" (relative path). ```APIDOC ## set_ffmpeg_path(path: str) ### Description Setter for path to FFmpeg executable. Default is "ffmpeg" (relative path). ### Method Function ### Endpoint `set_ffmpeg_path(path: str)` ### Parameters #### Request Body - **path** (str) - Required - Path to FFmpeg executable. ``` -------------------------------- ### get_version_info() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Returns a dictionary with the version of pyvidplayer2, FFmpeg, and Pygame. Version can also be accessed directly with pyvidplayer2.__version__ or pyvidplayer2.VERSION. ```APIDOC ## get_version_info() ### Description Returns a dictionary with the version of pyvidplayer2, FFmpeg, and Pygame. Version can also be accessed directly with `pyvidplayer2.__version__` or `pyvidplayer2.VERSION`. ### Method Function ### Endpoint `pyvidplayer2.get_version_info()` ### Response #### Success Response - **dictionary** - Contains version of pyvidplayer2, FFmpeg, and Pygame. ### Request Example ```python print(pyvidplayer2.get_version_info()) ``` ``` -------------------------------- ### FFmpeg path getter and setter Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Getter and setter for the path to the FFmpeg executable. The default path is "ffmpeg" (relative path). ```python get_ffmpeg_path() -> str set_ffmpeg_path(path: str) -> None ``` -------------------------------- ### Subtitles(path: str, **kwargs) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Constructor for the Subtitles object. Initializes subtitle handling with the provided path and configuration options. Pass this object into a Video object for use with Pygame. ```APIDOC ## Subtitles(path: str, **kwargs) ### Description Constructor for the Subtitles object. Initializes subtitle handling with the provided path and configuration options. Pass this object into a Video object for use with Pygame. ### Parameters - **path** (str) - Required - Path to subtitle file. Supports many file types, including .srt, .ass, .vtt, and others. Can also be a YouTube url if `youtube` is `True`. Can also be a video that contains embedded subtitle tracks. - **colour** (str | (int, int, int)) - Optional - Colour of text as an RGB value or a string recognized by Pygame. Default: "white". - **highlight** (str | (int, int, int, int)) - Optional - Background colour of text. Accepts RGBA, so it can be made completely transparent. Also accepts Pygame colour strings. Default: (0, 0, 0, 128). - **font** (pygame.font.Font | pygame.font.SysFont) - Optional - Pygame `Font` or `SysFont` object used to render surfaces. This includes the size of the text. By default, a `SysFont` of size 30 will be created. Default: None. - **encoding** (str) - Optional - Encoding used to open subtitle files. Default: "utf-8". - **offset** (float) - Optional - The higher this number is, higher up the subtitles appear. Default: 50. - **delay** (float) - Optional - Delays all subtitles by this many decimal seconds. Default: 0. - **youtube** (bool) - Optional - Set this to `True` and use a video url to grab subtitles. Default: false. - **pref_lang** (str) - Optional - Which language file to grab if using YouTube subtitles. If no subtitle file exists for this language, automatic captions are used, which are also automatically translated into the preferred language. It's important to use the correct language code set by Google, otherwise the subtitles will not be found. Default: "en". - **track_index** (int) - Optional - If path is given as a video with subtitle tracks, use this to specify which subtitle to load. 0 selects the first, 1 selects the second, and so on. Default: None. ``` -------------------------------- ### buffer_current() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Populates `frame_surf` and `frame_data` when they are `None`. As of v0.9.32, this is automatically called when seeking, so explicit calls are rarely needed. ```APIDOC ## buffer_current() ### Description Whenever `frame_surf` or `frame_data` are `None`, use this method to populate them. As of v0.9.32, this is automatically called when seeking, so explicit calls are rarely needed. ### Method buffer_current() ### Parameters None ### Response Returns a boolean indicating success. ``` -------------------------------- ### Webcam() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Constructor for the Webcam object, used for displaying a webcam feed. Only supported for Pygame. ```APIDOC ## Webcam() ### Description Object used for displaying a webcam feed. Only supported for Pygame. ### Parameters - **post_process** (callable(numpy.ndarray) -> numpy.ndarray) - Optional - Same as `Video` parameter. - **interp** (str | int) - Optional - Same as `Video` parameter. - **fps** (int) - Optional - Maximum number of frames captured from the webcam per second. - **cam_id** (int) - Optional - Specifies which webcam to use if there are more than one. 0 means the first, 1 means the second, and so on. - **capture_size** ((int, int)) - Optional - Specifies the webcam resolution. If nothing is set, a default is used. ``` -------------------------------- ### get_metadata() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Outputs a dictionary with attributes about the file metadata, including frame_count, frame_rate, etc. ```APIDOC ## get_metadata() ### Description Outputs a dictionary with attributes about the file metadata, including `frame_count`, `frame_rate`, etc. ### Method get_metadata() ### Parameters None ### Response Returns a dictionary with metadata attributes such as `frame_count`, `frame_rate`, etc. ``` -------------------------------- ### update() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Allows webcam to perform required operations. draw() already calls this method, so it's usually not used. Returns True if a new frame is ready to be displayed. ```APIDOC ## update() ### Description Allows webcam to perform required operations. `draw()` already calls this method, so it's usually not used. Returns `True` if a new frame is ready to be displayed. ### Method update ### Parameters None ### Response - **bool** - `True` if a new frame is ready to be displayed. ``` -------------------------------- ### get_ffprobe_path() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Getter for path to FFprobe executable. Default is "ffprobe" (relative path). ```APIDOC ## get_ffprobe_path() ### Description Getter for path to FFprobe executable. Default is "ffprobe" (relative path). ### Method Function ### Endpoint `get_ffprobe_path()` ### Response #### Success Response - **str** - Path to FFprobe executable. ``` -------------------------------- ### VideoPlayer.queue(input) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Adds a video to the queue. Accepts a path to a video or a Video object. Passing a path will not load the video until it becomes the active video. ```APIDOC ## queue(input) ### Description Accepts a path to a video or a Video object and adds it to the queue. Passing a path will not load the video until it becomes the active video. ### Method queue(input) ### Parameters - **input** (pyvidplayer2.VideoPygame | str) - Required - Path to a video or a Video object to add to the queue. ### Response None ``` -------------------------------- ### close() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Releases resources. Always recommended to call when done. ```APIDOC ## close() ### Description Releases resources. Always recommended to call when done. ### Method close ### Parameters None ### Response None ``` -------------------------------- ### set_ffprobe_path(path: str) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Setter for path to FFprobe executable. Default is "ffprobe" (relative path). ```APIDOC ## set_ffprobe_path(path: str) ### Description Setter for path to FFprobe executable. Default is "ffprobe" (relative path). ### Method Function ### Endpoint `set_ffprobe_path(path: str)` ### Parameters #### Request Body - **path** (str) - Required - Path to FFprobe executable. ``` -------------------------------- ### resize(size: (int, int)) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets a new frame size for the video and resizes the current frame data and surface. ```APIDOC ## resize(size: (int, int)) ### Description Sets the new frame size for video. Also resizes current `frame_data` and `frame_surf`. ### Method resize ### Parameters #### Request Body - **size** ((int, int)) - Required - The new frame size (width, height). ### Response None ``` -------------------------------- ### get_ffmpeg_path() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Getter for path to FFmpeg executable. Default is "ffmpeg" (relative path). ```APIDOC ## get_ffmpeg_path() ### Description Getter for path to FFmpeg executable. Default is "ffmpeg" (relative path). ### Method Function ### Endpoint `get_ffmpeg_path()` ### Response #### Success Response - **str** - Path to FFmpeg executable. ``` -------------------------------- ### set_post_func(func) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Changes the post-processing function. Works the same as the post_func parameter. ```APIDOC ## set_post_func(func) ### Description Changes the post-processing function. Works the same as the `post_func` parameter. ### Method set_post_func ### Parameters - **func** (callable(numpy.ndarray) -> numpy.ndarray) - Required - Post-processing function to apply. ### Response None ``` -------------------------------- ### FFmpeg log level getter and setter Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Getter and setter for the FFmpeg log level. Accepted levels include quiet, panic, fatal, error, warning, info, verbose, debug, and trace. The default log level is quiet. ```python get_ffmpeg_loglevel() -> str set_ffmpeg_loglevel(level: str) -> None ``` -------------------------------- ### set_subs(subs: Subtitles | [Subtitles]) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets the subtitles to use for the video. ```APIDOC ## set_subs(subs: Subtitles | [Subtitles]) ### Description Set the subtitles to use. Works the same as providing subtitles through the `subs` parameter. ### Method set_subs ### Parameters #### Request Body - **subs** (Subtitles | [Subtitles]) - Required - The subtitles to use. ### Response None ``` -------------------------------- ### restart() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Rewinds the video to the beginning without changing the active attribute. ```APIDOC ## restart() ### Description Rewinds video to the beginning. Does not change `active` attribute. ### Method restart ### Parameters None ### Response None ``` -------------------------------- ### probe() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Uses FFprobe to find accurate information about the video, such as frame count and frame rate, which may be incorrect when read through file headers by OpenCV. Call this method to update video metadata attributes. ```APIDOC ## probe() ### Description Uses FFprobe to find information about the video. When using OpenCV to read videos, information such as frame count and frame rate are read through the file headers, which is sometimes incorrect. For more accuracy, call this method to start a probe and update video metadata attributes. ### Method probe() ### Parameters None ### Response None ``` -------------------------------- ### Video(path, **kwargs) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Main object used to play videos. Supports playback from disk, RAM, or YouTube streaming. This class uses Pygame for graphics and Sounddevice for audio by default. ```APIDOC ## Video(path, **kwargs) ### Description Main object used to play videos. Supports playback from disk, RAM, or YouTube streaming. This class uses Pygame for graphics and Sounddevice for audio by default. ### Constructor `Video(path: str | bytes, **kwargs)` ### Parameters - **path** (str | bytes) - Required - Path to video file. Supports any codec or container that your FFmpeg binary can parse. Can also provide the video as a bytes object. If streaming from YouTube, provide the URL here. - **chunk_size** (float) - Optional, default 10 - Playable audio is extracted in chunks. This parameter dictates the size of each chunk, in seconds. Increasing this value will slow the initial loading of video, but may be necessary to prevent stuttering. When streaming from YouTube, this will be automatically set to a higher value. Cannot be lower than 0.1 seconds. - **max_threads** (int) - Optional, default 1 - Obsolete and deprecated. Will be locked to 1. Maximum number of chunks that can be simultaneously extracted. When streaming from YouTube, this will be locked to 1. - **max_chunks** (int) - Optional, default 1 - Maximum number of chunks allowed to be extracted and queued for playback. Cannot be lower than 1. - **subs** (pyvidplayer2.Subtitles) - Optional, default None - Pass a `Subtitles` object or a list of them to display during playback. - **post_process** (function(numpy.ndarray) -> numpy.ndarray) - Optional, default PostProcessing.none - Post processing function to be applied whenever a frame is rendered. Functions should accept a NumPy image and return the processed image. There are also a few pre-made post-processing functions. - **interp** (str | int) - Optional, default "linear" - Interpolation technique used when resizing frames. Accepts `nearest`, `linear`, `cubic`, `lanczos4` and `area`. Nearest is the fastest technique but produces the worst results. Lanczos4 produces the best results but is so much more intensive that it's usually not worth it. Area is a technique that produces the best results when downscaling. This parameter can also accept OpenCV constants like `cv2.INTER_LINEAR`. Resizing will use OpenCV when available but can fall back on FFmpeg (much slower) if needed. - **use_pygame_audio** (bool) - Optional, default False - Chooses Pygame as the audio library. Sounddevice is the default and is usually the best option, but Pygame can handle higher-FPS videos. Videos can only be played in parallel when using Sounddevice. - **reverse** (bool) - Optional, default False - Plays the video in reverse. Warning: Doing so will load every frame into RAM, so videos longer than a few minutes can temporarily brick your computer. - **no_audio** (bool) - Optional, default False - Specifies whether the given video has no audio tracks. If not set explicitly, this value will be auto-detected. Setting this to `True` can also be used to forcefully disable all existing audio tracks. - **speed** (float | int) - Optional, default 1.0 - Float from 0.25 to 10.0 that multiplies the playback speed. Note that every single video frame will still have to be processed. To avoid dropping frames, the fps of your program must be at least the fps of your video multiplied by the speed. For example, for a 24 fps video to be played at x2.0 speed, the video will have to be updated at least, but ideally more than 48 times a second to avoid skipping frames. - **youtube** (bool) - Optional, default False - Specifies whether to stream a YouTube video. Path must be a valid YouTube video URL. YouTube shorts and livestreams are not supported. Requires a few external dependencies, see this [example](https://github.com/anrayliu/pyvidplayer2/blob/main/examples/youtube_streaming_demo.py) for more information. - **max_res** (int) - Optional, default 720 - Only used when streaming YouTube videos. Sets the highest possible resolution when choosing video quality. 4320p is the highest YouTube supports. Actual video quality is not guaranteed to match `max_res`. - **as_bytes** (bool) - Optional, default False - Specifies whether `path` is a video in byte form. The Python package `decord` is required for this feature. - **audio_track** (int) - Optional, default 0 - Selects which audio track to use. 0 will play the first, 1 will play the second, and so on. - **vfr** (bool) - Optional, default False - Used to play variable frame rate videos. If `False`, a constant frame rate will be assumed. If `True`, presentation timestamps will be extracted for each frame. These will be stored in the `timestamps` attribute. This still works for constant frame rate videos, but extracting the timestamps will increase initialization time. - **pref_lang** (str) - Optional, default "en" - Only used when streaming YouTube videos. Used to select a language track if video has multiple. This must be a Google language code. - **audio_index** (int) - Optional, default None - Used to specify which audio output device to use if using Sounddevice. Can be specific to the system. ``` -------------------------------- ### get_pos() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Returns how long the webcam has been active. Is not reset if webcam is stopped. ```APIDOC ## get_pos() ### Description Returns how long the webcam has been active. Is not reset if webcam is stopped. ### Method get_pos ### Parameters None ### Response - **float** - Time in seconds the webcam has been active. ``` -------------------------------- ### VideoPlayer.get_queue() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Returns the list of queued video objects. ```APIDOC ## get_queue() ### Description Returns list of queued video objects. ### Method get_queue() ### Parameters None ### Response - **list[pyvidplayer2.VideoPygame]** - List of queued video objects. ``` -------------------------------- ### draw(surf, pos, force_draw) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Draws the current video frame onto the given surface, at the given position. If force_draw is True, a surface will be drawn every time this is called. Otherwise, only new frames will be drawn. This reduces CPU usage but will cause flickering if anything is drawn under or above the video. This method also returns whether a frame was drawn. ```APIDOC ## draw(surf, pos, force_draw) ### Description Draws the current video frame onto the given surface, at the given position. If `force_draw` is `True`, a surface will be drawn every time this is called. Otherwise, only new frames will be drawn. This reduces CPU usage but will cause flickering if anything is drawn under or above the video. This method also returns whether a frame was drawn. ### Method draw ### Parameters - **surf** (pygame.Surface) - Required - Surface to draw the frame onto. - **pos** ((int, int)) - Required - Position to draw the frame at. - **force_draw** (bool) - Optional - If `True`, draw every time; otherwise only new frames. Default is `True`. ### Response - **bool** - Whether a frame was drawn. ``` -------------------------------- ### change_resolution(height) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Given a height, the video will scale its width while maintaining aspect ratio. Returns new width. ```APIDOC ## change_resolution(height) ### Description Given a height, the video will scale its width while maintaining aspect ratio. Returns new width. ### Method change_resolution ### Parameters - **height** (int) - Required - Target height for the video. ### Response - **int** - New width after scaling. ``` -------------------------------- ### get_ffmpeg_loglevel() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Getter for FFmpeg log level. Accepted levels include quiet, panic, fatal, error, warning, info, verbose, debug, and trace. Default loglevel is quiet. ```APIDOC ## get_ffmpeg_loglevel() ### Description Getter for FFmpeg log level. Accepted levels include `quiet`, `panic`, `fatal`, `error`, `warning`, `info`, `verbose`, `debug`, and `trace`. Default loglevel is `quiet`. ### Method Function ### Endpoint `get_ffmpeg_loglevel()` ### Response #### Success Response - **str** - FFmpeg log level. ``` -------------------------------- ### get_volume() -> float Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Returns the current volume attribute. Exists for backwards compatibility. ```APIDOC ## get_volume() -> float ### Description Returns `volume` attribute. Only exists for backwards compatibility. ### Method get_volume ### Parameters None ### Response #### Success Response - **float** - The current volume value. ``` -------------------------------- ### VideoPlayer.skip() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Moves onto the next video in the queue. ```APIDOC ## skip() ### Description Moves onto the next video in the queue. ### Method skip() ### Parameters None ### Response None ``` -------------------------------- ### set_volume(volume: float) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Adjusts the volume of the video from 0.0 (min) to 1.0 (max). ```APIDOC ## set_volume(volume: float) ### Description Adjusts the volume of the video, from 0.0 (min) to 1.0 (max). ### Method set_volume ### Parameters #### Request Body - **volume** (float) - Required - The volume level (0.0 to 1.0). ### Response None ``` -------------------------------- ### set_interp(interp) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Changes the interpolation technique that OpenCV uses. Works the same as the interp parameter. ```APIDOC ## set_interp(interp) ### Description Changes the interpolation technique that OpenCV uses. Works the same as the `interp` parameter. ### Method set_interp ### Parameters - **interp** (str | int) - Required - Interpolation technique to use. ### Response None ``` -------------------------------- ### VideoPlayer.get_next() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Returns the next item in the queue. ```APIDOC ## get_next() ### Description Return next item in queue. ### Method get_next() ### Parameters None ### Response - **list[str | pyvidplayer2.VideoPygame]** - Next item in queue. ``` -------------------------------- ### close() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Releases resources used by the video object. Always recommended to call when done. ```APIDOC ## close() ### Description Releases resources. Always recommended to call when done. Attempting to use video object after closing it may lead to unexpected behaviour. ### Method close ### Parameters None ### Response None ``` -------------------------------- ### set_font(font: pygame.font.Font | pygame.font.SysFont) -> None Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets the font used for rendering subtitle text. This is equivalent to the `font` parameter in the constructor. ```APIDOC ## set_font(font: pygame.font.Font | pygame.font.SysFont) -> None ### Description Sets the font used for rendering subtitle text. This is equivalent to the `font` parameter in the constructor. ### Parameters - **font** (pygame.font.Font | pygame.font.SysFont) - Required - Pygame `Font` or `SysFont` object used to render surfaces. ``` -------------------------------- ### get_pos() -> float Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Returns the current video timestamp/position in decimal seconds. ```APIDOC ## get_pos() -> float ### Description Returns the current video timestamp/position in decimal seconds. ### Method get_pos ### Parameters None ### Response #### Success Response - **float** - The current video position in seconds. ``` -------------------------------- ### stop() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets the active attribute to False, stopping the webcam feed. ```APIDOC ## stop() ### Description Sets `active` to `False`. ### Method stop ### Parameters None ### Response None ``` -------------------------------- ### VideoPlayer.update(events, show_ui, fps) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Allows the VideoPlayer to make calculations. It must be passed the returns of pygame.event.get(). The GUI automatically shows up when your mouse hovers over the video player, so setting show_ui can be used to override that. The fps parameter can enforce a frame rate to your app. This method also returns whether the UI was shown. ```APIDOC ## update(events, show_ui, fps) ### Description Allows the VideoPlayer to make calculations. It must be passed the returns of `pygame.event.get()`. The GUI automatically shows up when your mouse hovers over the video player, so setting `show_ui` can be used to override that. The `fps` parameter can enforce a frame rate to your app. This method also returns whether the UI was shown. ### Method update(events, show_ui, fps) ### Parameters - **events** (list[pygame.event.Event]) - Required - The returns of `pygame.event.get()`. - **show_ui** (bool) - Optional - Override automatic GUI display. - **fps** (int) - Optional - Enforce a frame rate. Defaults to 0. ### Response - **bool** - Whether the UI was shown. ``` -------------------------------- ### set_ffmpeg_loglevel(level: str) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Setter for FFmpeg log level. Accepted levels include quiet, panic, fatal, error, warning, info, verbose, debug, and trace. Default loglevel is quiet. ```APIDOC ## set_ffmpeg_loglevel(level: str) ### Description Setter for FFmpeg log level. Accepted levels include `quiet`, `panic`, `fatal`, `error`, `warning`, `info`, `verbose`, `debug`, and `trace`. Default loglevel is `quiet`. ### Method Function ### Endpoint `set_ffmpeg_loglevel(level: str)` ### Parameters #### Request Body - **level** (str) - Required - FFmpeg log level. ``` -------------------------------- ### resize_capture(size) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Changes the resolution at which frames are captured from the webcam. Returns True if a resolution was found that matched the given size exactly, otherwise False and the closest matching resolution will be used. ```APIDOC ## resize_capture(size) ### Description Changes the resolution at which frames are captured from the webcam. Returns `True` if a resolution was found that matched the given size exactly. Otherwise, `False` will be returned and the closest matching resolution will be used. ### Method resize_capture ### Parameters - **size** ((int, int)) - Required - Desired capture resolution. ### Response - **bool** - `True` if exact match found, `False` otherwise. ``` -------------------------------- ### pause() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Pauses the video. ```APIDOC ## pause() ### Description Pauses the video. ### Method pause ### Parameters None ### Response None ``` -------------------------------- ### change_resolution(height: int) -> int Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Scales the video dimensions to the given height while maintaining aspect ratio, returning the new width. ```APIDOC ## change_resolution(height: int) -> int ### Description Given a height, the video will scale its dimensions while maintaining aspect ratio. Returns the new width. ### Method change_resolution ### Parameters #### Request Body - **height** (int) - Required - The target height for the video. ### Response #### Success Response - **int** - The new width of the video. ``` -------------------------------- ### draw(surf: pygame.Surface, pos: (int, int), force_draw: bool = True) -> bool Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Draws the current video frame onto a given surface at a specified position. Returns whether a frame was drawn. ```APIDOC ## draw(surf: pygame.Surface, pos: (int, int), force_draw: bool = True) -> bool ### Description Draws the current video frame onto the given surface, at the given position. If `force_draw` is `True`, a surface will be drawn every time this is called. Otherwise, only new frames will be drawn. This reduces CPU usage but will cause flickering if anything is drawn under or above the video. This method returns whether a frame was drawn. ### Method draw ### Parameters #### Request Body - **surf** (pygame.Surface) - Required - The surface to draw the video frame onto. - **pos** ((int, int)) - Required - The position (x, y) to draw the frame. - **force_draw** (bool) - Optional - If True, always draw. Default is True. ### Response #### Success Response - **bool** - Whether a frame was drawn. ``` -------------------------------- ### VideoPlayer.close() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Releases resources. Always recommended to call when done. Using the video player after can lead to unexpected behaviour. ```APIDOC ## close() ### Description Releases resources. Always recommended to call when done. Using the video player after can lead to unexpected behaviour. ### Method close() ### Parameters None ### Response None ``` -------------------------------- ### set_audio_track(index: int) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets the current audio track to the specified index. ```APIDOC ## set_audio_track(index: int) ### Description Sets the current audio track. ### Method set_audio_track ### Parameters #### Request Body - **index** (int) - Required - The index of the audio track to set. ### Response None ``` -------------------------------- ### set_post_func(func: callable(numpy.ndarray) -> numpy.ndarray) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets a post-processing function that operates on the video frame data. ```APIDOC ## set_post_func(func: callable(numpy.ndarray) -> numpy.ndarray) ### Description Changes the post-processing function. Works the same as the `post_func` parameter. ### Method set_post_func ### Parameters #### Request Body - **func** (callable(numpy.ndarray) -> numpy.ndarray) - Required - The post-processing function. ### Response None ``` -------------------------------- ### VideoPlayer.toggle_zoom() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Switches between zoomed in and zoomed out states. ```APIDOC ## toggle_zoom() ### Description Switches between zoomed in and zoomed out. ### Method toggle_zoom() ### Parameters None ### Response None ``` -------------------------------- ### VideoPlayer.get_video() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Returns the currently playing video object. ```APIDOC ## get_video() ### Description Returns currently playing video object. ### Method get_video() ### Parameters None ### Response - **pyvidplayer2.VideoPygame** - Currently playing video object. ``` -------------------------------- ### set_interp(interp: str | int) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Changes the interpolation technique used for video rendering. ```APIDOC ## set_interp(interp: str | int) ### Description Changes the interpolation technique. Works the same as the `interp` parameter. ### Method set_interp ### Parameters #### Request Body - **interp** (str | int) - Required - The interpolation technique to use. ### Response None ``` -------------------------------- ### Iterate over video frames as a generator Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Video objects can be iterated as a generator, yielding each subsequent frame. Frames are returned in reverse if the video is reversed, and post-processing and resizing still apply. Subtitles are not rendered; after iteration, play() resumes from the last frame. ```python for frame in Video("example.mp4"): print(frame) ``` -------------------------------- ### get_font() -> pygame.font.Font | pygame.font.SysFont Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Returns the Pygame font object currently being used for rendering subtitle text. ```APIDOC ## get_font() -> pygame.font.Font | pygame.font.SysFont ### Description Returns the Pygame font object currently being used for rendering subtitle text. ### Returns - **pygame.font.Font | pygame.font.SysFont** - The Pygame font object being used. ``` -------------------------------- ### stop() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Restarts the video and sets the active attribute to False, stopping playback. ```APIDOC ## stop() ### Description Restarts video and sets `active` to `False`. ### Method stop ### Parameters None ### Response None ``` -------------------------------- ### Access Individual Frames via Indexing Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Index a Video object to retrieve individual frames without affecting playback position. Slicing is not supported; use positive or negative indices. ```python first_frame = video[0] last_frame = video[-1] ``` -------------------------------- ### mute() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Mutes the video without affecting the volume setting. ```APIDOC ## mute() ### Description Mutes video. Doesn't affect volume. ### Method mute ### Parameters None ### Response None ``` -------------------------------- ### unmute() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Unmutes the video without affecting the volume setting. ```APIDOC ## unmute() ### Description Unmutes video. Doesn't affect volume. ### Method unmute ### Parameters None ### Response None ``` -------------------------------- ### VideoPlayer.move(pos, relative) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Moves the VideoPlayer. If relative is True, the given coordinates will be added onto the current coordinates. Otherwise, the current coordinates will be set to the given coordinates. ```APIDOC ## move(pos, relative) ### Description Moves the VideoPlayer. If `relative` is `True`, the given coordinates will be added onto the current coordinates. Otherwise, the current coordinates will be set to the given coordinates. ### Method move(pos, relative) ### Parameters - **pos** ((int, int)) - Required - New coordinates for the VideoPlayer. - **relative** (bool) - Optional - If True, coordinates are added to current position. Defaults to False. ### Response None ``` -------------------------------- ### VideoPlayer.zoom_out() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Reverts the zoom applied by zoom_to_fill(). ```APIDOC ## zoom_out() ### Description Reverts `zoom_to_fill()`. ### Method zoom_out() ### Parameters None ### Response None ``` -------------------------------- ### VideoPlayer.zoom_to_fill() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Zooms in the video so that frame_rect is entirely filled in while maintaining aspect ratio. ```APIDOC ## zoom_to_fill() ### Description Zooms in the video so that `frame_rect` is entirely filled in while maintaining aspect ratio. ### Method zoom_to_fill() ### Parameters None ### Response None ``` -------------------------------- ### seek(time: float | int, relative: bool = True, intuitive: bool = False) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Changes the current position in the video. Supports relative or absolute seeking with a precision limit of 3 decimals. ```APIDOC ## seek(time: float | int, relative: bool = True, intuitive: bool = False) ### Description Changes the current position in the video. If `relative` is `True`, the given time will be added or subtracted to the current time. Otherwise, the current position will be set to the given time exactly. Time must be given in seconds, with a precision limit of 3 decimals. If the given value is larger than the video duration, the video will seek to the last frame. Remember that the `frame` attribute represents the next frame to be rendered. Most people expect seeking to already display the frame they want, but this will require incrementing `frame` by one extra. To force `frame` to be exactly correct (which is one frame before requested position), set intuitive to `False`. Not applicable for relative seeking. Intuitive seeking does not work for Raylib and wxPython. ### Method seek ### Parameters #### Request Body - **time** (float | int) - Required - The time to seek to, in seconds. - **relative** (bool) - Optional - If True, the time is added/subtracted to the current position. Default is True. - **intuitive** (bool) - Optional - If True, seeks to the exact frame. Default is False. ### Response None ``` -------------------------------- ### VideoPlayer.clear_queue() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Clears all queued items. ```APIDOC ## clear_queue() ### Description Clears queued items. ### Method clear_queue() ### Parameters None ### Response None ``` -------------------------------- ### hide_subs() Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Hides subtitles. ```APIDOC ## hide_subs() ### Description Hides subtitles. ### Method hide_subs ### Parameters None ### Response None ``` -------------------------------- ### set_speed(speed: float) Source: https://github.com/anrayliu/pyvidplayer2/blob/main/documentation.md Sets a new speed value for playback, ranging from 0.25 to 10.0. ```APIDOC ## set_speed(speed: float) ### Description Sets a new speed value (0.25-10.0) just like the parameter. ### Method set_speed ### Parameters #### Request Body - **speed** (float) - Required - The new speed value (0.25-10.0). ### Response None ```