### General Conversion Example Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods An example demonstrating a basic conversion process using PyFFmpeg. ```APIDOC ## POST /api/convert ### Description Performs a media conversion from one format to another. This is a high-level command that orchestrates the input, processing, and output steps. ### Method POST ### Endpoint /api/convert ### Parameters #### Request Body - **input_path** (string) - Required - Path to the input media file. - **output_path** (string) - Required - Path for the converted output file. ### Request Example ```json { "input_path": "path/to/music_folder/f.mp3", "output_path": "f.wav" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful conversion. #### Response Example ```json { "status": "Conversion completed successfully" } ``` ``` -------------------------------- ### Install pyffmpeg Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Install the pyffmpeg library using pip. This is the first step before using any of its functionalities. ```bash pip install pyffmpeg ``` -------------------------------- ### Example Progress Output Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Get-Progress-Info This is an example of the output generated by the progress handler function when processing a file. ```shell 10% complete 11% complete ... 100% complete ``` -------------------------------- ### FFprobe Duration Output Example Source: https://github.com/deuteronomy-works/pyffmpeg/blob/master/README.md Illustrates the expected output format for the duration when using FFprobe. The actual digits may vary based on the media file. ```shell > 00:04:32:32 ``` -------------------------------- ### Extract Basic Media Metadata with FFprobe Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Use `FFprobe` to extract essential media metadata like duration, FPS, and bitrate without requiring a separate FFprobe binary installation. Initialize `FFprobe` with the media file path. ```python from pyffmpeg import FFprobe # Probe a media file fp = FFprobe('/path/to/video.mp4') # Get basic properties print(f"Duration: {fp.duration}") print(f"FPS: {fp.fps}") print(f"Bitrate: {fp.bitrate}") # Probe audio file fp_audio = FFprobe('/path/to/music.mp3') print(f"Audio duration: {fp_audio.duration}") ``` -------------------------------- ### Extract Output Stream Metadata (Video Codec) Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Metadata Retrieve metadata for the primary output stream (index 0), which typically contains the main video or audio. This example shows how to get the video codec. ```python ff = FFprobe('movie.mp4') codec = ff.metadata[0][0]['codec'] // might return h264 ``` -------------------------------- ### FFmpeg.get_ffmpeg_bin() - Get FFmpeg Binary Path Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Retrieve the path to the bundled FFmpeg executable, allowing for its use in external processes. ```APIDOC ## FFmpeg.get_ffmpeg_bin() - Get FFmpeg Binary Path ### Description Retrieve the path to the bundled FFmpeg executable for external use. ### Method `get_ffmpeg_bin()` method of `FFmpeg` class ### Endpoint N/A (Local library function) ### Parameters None ### Request Example ```python from pyffmpeg import FFmpeg ff = FFmpeg() ffmpeg_path = ff.get_ffmpeg_bin() print(f"FFmpeg binary: {ffmpeg_path}") ``` ### Response #### Success Response (200) Returns the absolute path to the FFmpeg binary. #### Response Example ``` FFmpeg binary: /home/user/.pyffmpeg/bin/ffmpeg ``` ``` -------------------------------- ### Get Media Duration with FFprobe Source: https://github.com/deuteronomy-works/pyffmpeg/blob/master/README.md Utilizes FFprobe to extract media information, such as duration. Initialize FFprobe with the input file path. ```python from pyffmpeg import FFprobe input_file = 'path/to/music.mp3' fp = FFprobe(input_file) print(fp.duration) ``` -------------------------------- ### Extract Output Stream Metadata (Audio Codec) Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Metadata Retrieve metadata for the secondary output stream (index 1), which often contains audio information for video files. This example shows how to get the audio codec. ```python ff = FFprobe('movie.mp4) codec = ff.metadata[0][1]['codec'] // might return aac ``` -------------------------------- ### Get Album Art Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Explains how to retrieve album art from a media file, either saving it to disk or getting it as bytes. ```APIDOC ## Get Album Art ### Description Retrieves the album art from a media file. It can either save the art to a specified filename or return the raw bytes. ### Method get_album_art ### Endpoint N/A (Method of FFprobe class) ### Parameters #### Path Parameters - **filename** (string or None) - Optional - If provided, the album art will be saved to this filename. If None, the raw bytes of the album art are returned. ### Request Example (Saving to file) ```python input_file = 'path/to/music.mp3' fp = FFprobe(input_file) fp.get_album_art('cover_art.png') ``` ### Request Example (Getting as bytes) ```python input_file = 'path/to/music.mp3' cover_art_bin = FFprobe(input_file).get_album_art() print(cover_art_bin) ``` ```shell > \x01e\x0f4\x01e\xo4e\x03e\x01e\x0f4\x01e\xo4e\x03e\x01e\x0f4\x01e\xo4e\x03e\x01e\x0f4\x01e\xo4e\x03e\x01e\x0f4\x01e\xo4e\x03e\x01e\x0f4\x01e\xo4e\x03e ... (Illustrative bytes output) ``` ### Response #### Success Response (Saving to file) If a filename is provided, the album art is saved to the specified file, and the method returns None. #### Success Response (Getting as bytes) If filename is None, the method returns the raw bytes of the album art. ``` -------------------------------- ### Get Album Art as File Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Extract album art and save it to a specified file. If a filename is provided, the art is saved to disk. ```python input_file = 'path/to/music.mp3' fp = FFprobe(input_file) fp.get_album_art('cover_art.png') ``` -------------------------------- ### Extract Video/Audio Segments with FFmpeg.clip() Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Create subclips by specifying start and end times using FFmpeg.clip(). Times can be integers, floats, or timestamp strings (HH:MM:SS). ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Extract segment from 5 seconds to 100 seconds ff.input('/path/to/movie.mp4').clip(5, 100).output('/path/to/clip.mp4').run() # Using timestamp format (HH:MM:SS) ff.input('/path/to/movie.mp4').clip('00:01:30', '00:05:00').output('/path/to/scene.mp4').run() # Extract first 10 seconds using duration() ff.input('/path/to/audio.mp3').duration(10).output('/path/to/preview.mp3').run() ``` -------------------------------- ### Get FFmpeg Executable Path Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Home Retrieve the full path to the FFmpeg executable bundled with pyffmpeg using the get_ffmpeg_bin function. Useful for integration with other libraries. ```python ff = FFmpeg() ffmpeg_exe = ff.get_ffmpeg_bin() ``` -------------------------------- ### Get FFmpeg Binary Path Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Retrieve the absolute path to the bundled FFmpeg executable using `get_ffmpeg_bin()`. This is useful for integrating FFmpeg into external workflows. ```python from pyffmpeg import FFmpeg ff = FFmpeg() ffmpeg_path = ff.get_ffmpeg_bin() print(f"FFmpeg binary: {ffmpeg_path}") ``` -------------------------------- ### Clip Video Segment Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods Create a subclip by specifying the start and end times. Times can be integers, floats, or timestamp strings. ```python ff.input(input_file).clip(5, 100).output(out).run() ``` -------------------------------- ### FFprobe - Extract Media Metadata Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Probe media files to extract essential metadata such as duration, bitrate, and FPS without requiring a separate FFprobe binary installation. ```APIDOC ## FFprobe - Extract Media Metadata ### Description Probe media files to extract duration, bitrate, FPS, and other metadata without using the separate FFprobe binary. ### Method `FFprobe` class constructor and attributes ### Endpoint N/A (Local library class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pyffmpeg import FFprobe # Probe a media file fp = FFprobe('/path/to/video.mp4') # Get basic properties print(f"Duration: {fp.duration}") print(f"FPS: {fp.fps}") print(f"Bitrate: {fp.bitrate}") # Probe audio file fp_audio = FFprobe('/path/to/music.mp3') print(f"Audio duration: {fp_audio.duration}") ``` ### Response #### Success Response (200) Returns metadata accessible via object attributes. #### Response Example ``` Duration: 00:04:32:32 FPS: 29.97 Bitrate: 2500 kb/s Audio duration: 00:03:45:12 ``` ``` -------------------------------- ### Clipping Media Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods Shows how to extract a specific segment from a media file using start and end times. ```APIDOC ## POST /api/clip ### Description Creates a subclip from a media file by specifying the start and end times for the desired segment. ### Method POST ### Endpoint /api/clip ### Parameters #### Query Parameters - **start** (int or float or string) - Required - The starting time of the clip. Can be in seconds (int/float) or timestamp format (e.g., 'HH:MM:SS'). - **end** (int or float or string) - Required - The ending time of the clip. Can be in seconds (int/float) or timestamp format (e.g., 'HH:MM:SS'). ### Request Example ```json { "start": 5, "end": 100 } ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful clipping operation. #### Response Example ```json { "status": "Clip created successfully" } ``` ``` -------------------------------- ### Get Album Art as Bytes Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Retrieve album art as raw bytes. If None is passed, the method returns the binary data of the album art. ```python input_file = 'path/to/music.mp3' cover_art_bin = FFprobe(input_file).get_album_art() print(cover_art_bin) ``` -------------------------------- ### Simple File Conversion with FFmpeg.convert() Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Use FFmpeg.convert() for straightforward media file conversions based on the output file extension. Ensure FFmpeg is initialized. ```python from pyffmpeg import FFmpeg # Initialize FFmpeg ff = FFmpeg() # Convert MP4 video to MP3 audio input_file = '/path/to/video.mp4' output_file = '/path/to/audio.mp3' try: result = ff.convert(input_file, output_file) print(f"Conversion complete: {result}") # Output: Conversion complete: /path/to/audio.mp3 except Exception as e: print(f"Conversion failed: {e}") ``` -------------------------------- ### Import FFprobe Class Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Import the FFprobe class from the pyffmpeg library to begin. ```python from pyffmpeg import FFprobe ``` -------------------------------- ### FFprobe Initialization and Usage Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Demonstrates how to initialize the FFprobe class with an input file and access its properties like duration. ```APIDOC ## FFprobe Initialization and Usage ### Description Initializes the FFprobe class with an input file and provides access to various media file properties. ### Method __init__ ### Endpoint N/A (Class Initialization) ### Parameters #### Path Parameters - **input_file** (string) - Required - The path to the media file to be probed. ### Request Example ```python from pyffmpeg import FFprobe input_file = 'path/to/music.mp3' fp = FFprobe(input_file) ``` ### Response #### Success Response (Initialization) Upon successful initialization, the `fp` object will contain properties like `duration`, `fps`, `bitrate`, and `metadata`. #### Response Example (Accessing Duration) ```python print(fp.duration) ``` ```shell > 00:04:32:32 ``` ``` -------------------------------- ### Run Local Test Script Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/How-to-Contribute Execute this script to create the ffmpeg executable on your machine. Ensure you are on the correct OS-specific branch before running. ```python local_t_est.py ``` -------------------------------- ### Input Handling Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods Demonstrates how to specify input files, including handling multiple inputs with stream mapping. ```APIDOC ## POST /api/input ### Description Allows specifying one or more input files for media processing. When using multiple inputs, a map is required to define how streams are selected from each input. ### Method POST ### Endpoint /api/input ### Parameters #### Query Parameters - **inputs** (string) - Required - Path to the input file(s). - **map** (list of strings) - Optional - Specifies stream mapping for multiple inputs (e.g., ['0:v', '1:0']). - **rate** (int) - Optional - Sets the input frame rate. ### Request Example ```json { "inputs": "input_file", "inp2": "another_input.mp4", "map": ["0:v", "1:0"] } ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful processing of input. #### Response Example ```json { "status": "Input processed successfully" } ``` ``` -------------------------------- ### Initialize FFprobe Class Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Instantiate the FFprobe class with the input file path. Probing is performed upon initialization. ```python input_file = 'path/to/music.mp3' fp = FFprobe(input_file) ``` -------------------------------- ### Chained Operations with FFmpeg.input().output().run() Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Build complex FFmpeg commands using method chaining for multiple inputs, stream mapping, and advanced options. The .run() method executes the command. ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Simple conversion using chain syntax ff.input('/path/to/input.mp4').output('/path/to/output.mp3').run() # Multiple inputs with stream mapping # Select video from first file (0:v) and audio from second file (1:0) ff.input( '/path/to/video.mp4', '/path/to/audio.mp3', map=['0:v', '1:0'] ).output('/path/to/combined.mp4').run() # With frame rate specification ff.input('/path/to/video.mp4', rate=30).output('/path/to/output.mp4').run() ``` -------------------------------- ### Initialize FFprobe and Access Metadata Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Metadata Instantiate FFprobe with an input file and access its general metadata. The metadata variable contains information for output streams (index 0) and input streams (index -1). ```python ff = FFprobe(input_file) meta = ff.metadata ``` -------------------------------- ### Configure FFmpeg Output and Behavior Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Customize FFmpeg operations by setting the output directory, controlling file overwriting, and managing automatic folder creation. Initialize `FFmpeg` with desired configuration parameters. ```python from pyffmpeg import FFmpeg # Set output directory (relative paths will be resolved here) ff = FFmpeg(directory='/path/to/output/folder') # Disable logging ff_quiet = FFmpeg(enable_log=False) # Control overwrite behavior ff.overwrite = True # Overwrite existing files (default) ff.overwrite = False # Skip if file exists # Control automatic folder creation ff.create_folders = True # Create output directories automatically (default) ff.create_folders = False # Raise error if directory doesn't exist # Perform conversion ff.convert('/path/to/input.mp4', 'output.mp3') ``` -------------------------------- ### Pass Raw FFmpeg Commands with FFmpeg.options() Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Pass custom FFmpeg command-line options for advanced use cases using FFmpeg.options(). Options can be provided as a single string or a list of strings. ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Pass raw options as string ff.options('-i /path/to/input.mp4 -c:v libx264 -preset fast /path/to/output.mp4') # Pass options as list ff.options(['-i', '/path/to/input.mp4', '-c:v', 'libx264', '/path/to/output.mp4']) ``` -------------------------------- ### Specify Output Directory Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Home Initialize FFmpeg with a specific directory path to store all converted files. This sets a global output location. ```python ff = FFmpeg('path/to/app_folder') ff.convert('path/to/music_folder/f.mp3', 'f.wav') ``` -------------------------------- ### Import pyffmpeg Library Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Home Import the FFmpeg class from the pyffmpeg library to begin using its functionalities. ```python from pyffmpeg import FFmpeg ``` -------------------------------- ### Convert Audio/Video File Source: https://github.com/deuteronomy-works/pyffmpeg/blob/master/README.md Use this method for simple file conversions. Ensure the input and output paths are correctly specified. ```python from pyffmpeg import FFmpeg inp = 'path/to/music_folder/f.mp4' out = 'path/to/music_folder/f.mp3' ff = FFmpeg() output_file = ff.convert(inp, out) print(output_file) ``` -------------------------------- ### FFmpeg Configuration Options Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Configure FFmpeg behavior, including setting the output directory, controlling file overwriting, and managing automatic folder creation. ```APIDOC ## FFmpeg Configuration Options ### Description Configure FFmpeg behavior including output directory, overwrite settings, and folder creation. ### Method `FFmpeg` class constructor and attributes ### Endpoint N/A (Local library configuration) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pyffmpeg import FFmpeg # Set output directory (relative paths will be resolved here) ff = FFmpeg(directory='/path/to/output/folder') # Disable logging ff_quiet = FFmpeg(enable_log=False) # Control overwrite behavior ff.overwrite = True # Overwrite existing files (default) ff.overwrite = False # Skip if file exists # Control automatic folder creation ff.create_folders = True # Create output directories automatically (default) ff.create_folders = False # Raise error if directory doesn't exist # Perform conversion ff.convert('/path/to/input.mp4', 'output.mp3') # Saves to /path/to/output/folder/output.mp3 ``` ### Response #### Success Response (200) Media conversion is performed according to the specified configuration. #### Response Example Output file is created in the configured directory with the specified overwrite and folder creation settings. ``` -------------------------------- ### Set Input Files with Stream Mapping Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods Use this method to specify input files for processing. Include a map argument when using multiple input files to select specific streams. ```python ff.input(input_file, inp2, map=['0:v', '1:0']).output(out).run() ``` -------------------------------- ### Specify Codec Settings with FFmpeg.codec() Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Set codecs for video, audio, or both streams during conversion using FFmpeg.codec(). Use 'copy' to avoid re-encoding. ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Copy video stream without re-encoding ff.input('/path/to/input.mp4').codec('copy', specifier='v').output('/path/to/output.mp4').run() # Set audio codec to AAC ff.input('/path/to/input.mp4').codec('aac', specifier='a').output('/path/to/output.mp4').run() # Copy all streams (fastest, no re-encoding) ff.input('/path/to/input.mp4').codec('copy').output('/path/to/output.mp4').run() ``` -------------------------------- ### Set Output Bitrate with FFmpeg.bitrate() Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Control the bitrate for video or audio streams using FFmpeg.bitrate(). Specify the bitrate in bits per second. ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Set video bitrate to 2Mbps ff.input('/path/to/input.mp4').bitrate(2000000, specifier='v').output('/path/to/output.mp4').run() # Set audio bitrate to 192kbps ff.input('/path/to/input.mp4').bitrate(192000, specifier='a').output('/path/to/output.mp4').run() # Set overall bitrate ff.input('/path/to/input.mp4').bitrate(1500000).output('/path/to/output.mp4').run() ``` -------------------------------- ### Execute Custom FFmpeg Options Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Home Utilize the options function to pass custom FFmpeg commands. Exclude the 'ffmpeg' command itself and the overwrite flag. ```python ff = FFmpeg() ff.options("-i /path/to/video.mp4 -vf scale -1:720 /path/to/video_hd.mp4") ``` -------------------------------- ### Apply Filters with FFmpeg.filter() Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Apply FFmpeg filters for video or audio processing using FFmpeg.filter(). Filters are specified as strings. ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Apply video filter (e.g., scale) ff.input('/path/to/input.mp4').filter('scale=1280:720', specifier='v').output('/path/to/output.mp4').run() # Apply audio filter ff.input('/path/to/input.mp4').filter('volume=2.0', specifier='a').output('/path/to/output.mp4').run() ``` -------------------------------- ### Run FFprobe Test Script Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/How-to-Contribute Use this script for testing FFprobe functionality within the pyffmpeg project. It is part of the local testing suite. ```python local_probe_t_est.py ``` -------------------------------- ### Progress Reporting Properties Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFmpeg Configure how progress is reported and handled. ```APIDOC ## Properties ### `report_progress` * **Type**: `bool` * **Default**: `True` This should be set before progress will be captured. ``` ```APIDOC ### `onProgressChanged` * **Type**: `def(progres: int)` * **Default**: `progressChangeMock` This should be set to a name of a function/method. It will be called whenever progress changes. The progress will be passed to the function/method as an int. ``` -------------------------------- ### Track FFmpeg Conversion Progress Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Monitor audio conversion progress using a callback function. Ensure `report_progress` is set to `True` and `onProgressChanged` is assigned a handler. ```python from pyffmpeg import FFmpeg def handle_progress(progress): print(f'{progress}% complete') ff = FFmpeg() ff.report_progress = True ff.onProgressChanged = handle_progress # Conversion will report progress ff.convert('/path/to/long_audio.wav', '/path/to/output.mp3') ``` -------------------------------- ### Setting Duration Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods Allows setting the duration for the output media file. ```APIDOC ## POST /api/duration ### Description Sets the duration for the output media file. ### Method POST ### Endpoint /api/duration ### Parameters #### Query Parameters - **duration** (int) - Required - The desired duration in seconds. ### Request Example ```json { "duration": 10 } ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful duration setting. #### Response Example ```json { "status": "Duration set successfully" } ``` ``` -------------------------------- ### FFmpeg Progress Tracking Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Monitor the progress of media conversions using a callback function. This feature currently supports audio files. ```APIDOC ## FFmpeg Progress Tracking ### Description Monitor conversion progress with a callback function. Currently works with audio files. ### Method `convert` method of `FFmpeg` class ### Endpoint N/A (Local library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pyffmpeg import FFmpeg def handle_progress(progress): print(f'{progress}% complete') ff = FFmpeg() ff.report_progress = True ff.onProgressChanged = handle_progress # Conversion will report progress ff.convert('/path/to/long_audio.wav', '/path/to/output.mp3') ``` ### Response #### Success Response (200) Prints progress updates to the console. #### Response Example ``` 10% complete 20% complete ... 100% complete ``` ``` -------------------------------- ### Handle Audio File Progress with PyFFmpeg Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Get-Progress-Info Set `report_progress` to True and assign a callback function to `onProgressChanged` to receive progress updates. This feature currently only works for audio files. ```python def handle_progress(progress): print(f'{progress}% complete') ff = FFmpeg() ff.report_progress = True ff.onProgressChanged = handle_progress ``` -------------------------------- ### FFprobe Values Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Lists and describes the available values that can be accessed after initializing the FFprobe class. ```APIDOC ## FFprobe Values ### Description These are the properties available on an FFprobe object after it has been initialized with an input file. ### Values - **duration** (string) - The duration of the audio/video file. - **fps** (number) - The frames per second of the video file. - **bitrate** (string) - The bitrate of the video/file file. - **metadata** (object) - All the metadata info. Use this to access all the metadata of all the various streams. More on metadata [here](https://github.com/deuteronomy-works/pyffmpeg/wiki/Metadata) ``` -------------------------------- ### Run Pytest for Testing Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/How-to-Contribute Execute this command to run all tests using pytest. This is the final step in ensuring your code changes meet the project's quality standards. ```bash pytest -v ``` -------------------------------- ### FFprobe.metadata - Access Full Metadata Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Access comprehensive metadata from media files, including input/output stream details, artist, album, and codec information. ```APIDOC ## FFprobe.metadata - Access Full Metadata ### Description Access comprehensive metadata including input/output stream information, artist, album, and codec details. ### Method `metadata` attribute of `FFprobe` object ### Endpoint N/A (Local library attribute) ### Parameters None ### Request Example ```python from pyffmpeg import FFprobe # Get all metadata fp = FFprobe('/path/to/song.mp3') meta = fp.metadata # Input metadata (index -1) - contains artist, album, etc. input_meta = meta[-1] artist_name = input_meta.get('artist', 'Unknown') album_title = input_meta.get('album', 'Unknown') print(f"Artist: {artist_name}, Album: {album_title}") # Output stream metadata (index 0) # Stream 0: main stream (video for video files, audio for audio files) # Stream 1: secondary stream (audio for video files, album art for audio files) fp_video = FFprobe('/path/to/movie.mp4') video_codec = fp_video.metadata[0][0].get('codec', 'unknown') # e.g., 'h264' audio_codec = fp_video.metadata[0][1].get('codec', 'unknown') # e.g., 'aac' print(f"Video codec: {video_codec}, Audio codec: {audio_codec}") ``` ### Response #### Success Response (200) Returns a nested structure containing detailed metadata. #### Response Example ``` Artist: Example Artist, Album: Example Album Video codec: h264, Audio codec: aac ``` ``` -------------------------------- ### Multiple Input File Conversion Source: https://github.com/deuteronomy-works/pyffmpeg/blob/master/README.md Handles multiple input files for conversion, allowing for complex stream mapping. The 'map' argument specifies which streams to use from the inputs. ```python ff.input( 'path/to/music_folder/f.mp4', 'path/to/music_folder/g.mp3', map=['0:1', '0:0'] ).output('path/to/music_folder/f.mp4').run() ``` -------------------------------- ### Chained FFmpeg Conversion Source: https://github.com/deuteronomy-works/pyffmpeg/blob/master/README.md This method allows for more complex file handling using a chained API. It's useful for building conversion pipelines. ```python from pyffmpeg import FFmpeg ff = FFmpeg() ff.input('path/to/music_folder/f.mp4').output('path/to/music_folder/f.mp3').run() ``` -------------------------------- ### Access Metadata Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Access all metadata information for the media file. This includes details about various streams within the file. ```python print(fp.metadata) ``` -------------------------------- ### Access Comprehensive FFprobe Metadata Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Access detailed metadata, including input and output stream information, artist, album, and codec details, via the `metadata` attribute. Metadata is structured as a list of dictionaries, where index -1 typically holds input metadata. ```python from pyffmpeg import FFprobe # Get all metadata fp = FFprobe('/path/to/song.mp3') meta = fp.metadata # Input metadata (index -1) - contains artist, album, etc. input_meta = meta[-1] artist_name = input_meta.get('artist', 'Unknown') album_title = input_meta.get('album', 'Unknown') print(f"Artist: {artist_name}, Album: {album_title}") # Output stream metadata (index 0) # Stream 0: main stream (video for video files, audio for audio files) # Stream 1: secondary stream (audio for video files, album art for audio files) fp_video = FFprobe('/path/to/movie.mp4') video_codec = fp_video.metadata[0][0].get('codec', 'unknown') audio_codec = fp_video.metadata[0][1].get('codec', 'unknown') print(f"Video codec: {video_codec}, Audio codec: {audio_codec}") ``` -------------------------------- ### Convert Audio/Video Format Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Home Use the convert function to change the format or codec of an audio or video file. Specify input and output paths. ```python inp = 'path/to/music_folder/f.mp4' out = 'path/to/music_folder/f.mp3' ff = FFmpeg() output_file = ff.convert(inp, out) print(output_file) ``` -------------------------------- ### Extract Album Art with FFprobe Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Extract album art from audio files using `get_album_art()`. This method can save the art directly to a file or return it as bytes for further processing. ```python from pyffmpeg import FFprobe fp = FFprobe('/path/to/music.mp3') # Save album art to file fp.get_album_art('/path/to/cover_art.png') print("Album art saved to cover_art.png") # Get album art as bytes album_art_bytes = fp.get_album_art() if album_art_bytes: with open('album_cover.jpg', 'wb') as f: f.write(album_art_bytes) ``` -------------------------------- ### Extract Input Stream Metadata (Artist Name) Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Metadata Access the input stream metadata, which includes publicly known information like artist name. Use index -1 to specifically target the input stream. ```python ff = FFprobe('song.mp3') artist_name = ff.metadata[-1]['artist'] ``` -------------------------------- ### Set FFmpeg Log Level Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods Control the amount of information displayed in the console by setting the log level. The default is 'fatal'. ```python ff = FFmpeg() ff.loglevel = 'info' ff.convert('path/to/music_folder/f.mp3', 'f.wav') ``` -------------------------------- ### FFprobe.get_album_art() - Extract Album Art Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Extract album art from audio files, with options to save it directly to a file or retrieve it as raw bytes. ```APIDOC ## FFprobe.get_album_art() - Extract Album Art ### Description Extract album art from audio files, either saving to disk or returning as bytes. ### Method `get_album_art()` method of `FFprobe` object ### Endpoint N/A (Local library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pyffmpeg import FFprobe fp = FFprobe('/path/to/music.mp3') # Save album art to file fp.get_album_art('/path/to/cover_art.png') print("Album art saved to cover_art.png") # Get album art as bytes album_art_bytes = fp.get_album_art() # Pass None or no argument if album_art_bytes: with open('album_cover.jpg', 'wb') as f: f.write(album_art_bytes) ``` ### Response #### Success Response (200) Saves the album art to the specified file path or returns the album art as bytes. #### Response Example ``` Album art saved to cover_art.png ``` ``` -------------------------------- ### Access Duration Value Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/FFprobe Retrieve the duration of the media file from the initialized FFprobe object. ```python print(fp.duration) ``` -------------------------------- ### Set Video Duration Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods Specify the desired duration for the output video. ```python ff.input(input_file).duration(10).output(out).run() ``` -------------------------------- ### Control FFmpeg Log Level Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Set the `loglevel` attribute to control the verbosity of FFmpeg's console output. Available levels range from 'quiet' to 'trace'. The default is 'fatal'. ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Show detailed information ff.loglevel = 'info' ff.convert('/path/to/input.mp3', '/path/to/output.wav') ``` -------------------------------- ### Log Level Configuration Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Methods Configures the log level to control the amount of information displayed during processing. ```APIDOC ## PUT /api/log_level ### Description Sets the log level for FFmpeg to control the verbosity of console output. Possible values range from 'quiet' to 'trace'. ### Method PUT ### Endpoint /api/log_level ### Parameters #### Query Parameters - **level** (string) - Required - The desired log level (e.g., 'info', 'debug', 'warning'). ### Request Example ```json { "level": "info" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful log level update. #### Response Example ```json { "status": "Log level set to info" } ``` ``` -------------------------------- ### FFmpeg.loglevel - Control Logging Output Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Set the FFmpeg log level to control the verbosity of console output during media processing. ```APIDOC ## FFmpeg.loglevel - Control Logging Output ### Description Set the FFmpeg log level to control console output verbosity. ### Method `loglevel` attribute of `FFmpeg` class ### Endpoint N/A (Local library attribute) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Show detailed information ff.loglevel = 'info' ff.convert('/path/to/input.mp3', '/path/to/output.wav') ``` ### Response #### Success Response (200) Logs are displayed based on the set log level. #### Response Example Logs will vary based on the selected log level. Example for 'info': ``` [info] Processing input file... [info] Conversion started... ``` ### Notes Available log levels: 'quiet', 'panic', 'fatal', 'error', 'warning', 'info', 'verbose', 'debug', 'trace'. Default is 'fatal'. ``` -------------------------------- ### Control Overwrite Behavior Source: https://github.com/deuteronomy-works/pyffmpeg/wiki/Home Set the 'overwrite' attribute to False to prevent overwriting existing files and cause the process to exit immediately if a conflict occurs. ```python ff.overwrite = False ``` -------------------------------- ### Disable Streams with FFmpeg.disable() Source: https://context7.com/deuteronomy-works/pyffmpeg/llms.txt Remove video, audio, or subtitle streams from the output using FFmpeg.disable(). Specify the stream type to disable. ```python from pyffmpeg import FFmpeg ff = FFmpeg() # Extract audio only (disable video) ff.input('/path/to/video.mp4').disable('v').output('/path/to/audio.mp3').run() # Extract video only (disable audio) ff.input('/path/to/video.mp4').disable('a').output('/path/to/silent.mp4').run() # Disable subtitles ff.input('/path/to/video.mkv').disable('s').output('/path/to/nosubs.mkv').run() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.