This module is a simple wrapper around FFmpeg. Its main purpose is to simplify the process of trimming and concatenating video files. It includes functionalities to handle video file information, collect video files based on patterns, trim videos, concatenate videos, and manage configuration through YAML files.
- FileInfo Class: Represents a video file and its intended processing tasks, such as trimming.
- Video Trimming: Trim videos based on start and end timestamps.
- Video Concatenation: Concatenate multiple video files into a single output file.
- Configuration Management: Generate and read YAML configuration files for batch processing.
To use this module, ensure you have FFmpeg installed on your system. You can download it from the official FFmpeg website.
The FileInfo
class holds information about a video file, including its name, start and end timestamps for trimming, and methods for generating trimmed filenames.
To trim a video, use the do_trim
function. It takes a FileInfo
object and an output filename, trimming the video based on the start and end timestamps.
Example:
file_info = FileInfo("video.mp4", "00:00:10", "00:00:20")
return_code = do_trim(file_info, "trimmed_video.mp4")
if return_code == 0:
print("Trimming successful")
To concatenate multiple video files, use the do_concat
function. It reads filenames from a join file and concatenates them using FFmpeg.
Example:
write_join_file("join.txt", ["video1.mp4", "video2.mp4"])
do_concat("join.txt", "output.mp4")
Generate a configuration file with details of the videos to process, or read an existing configuration file to process videos as specified.
Example configuration (concat_config.yml
):
codec: hevc_nvenc
files:
file1:
name: video1.mp4
start: 00:00:10
end: 00:00:20
file2:
name: video2.mp4
The main script provides command-line options to generate or use a configuration file for video processing.
Usage:
python main.py --generate-config # Generates a config file with the current directory's video files
python main.py --use-config # Processes videos based on the generated config file
--debug
: Enable debug logging.--generate-config
: Generate a configuration file based on the current directory's video files.--use-config
: Use an existing configuration file to process videos.
To run the main script with debug logging enabled:
python main.py --debug
To generate a configuration file:
python main.py --generate-config
To process videos using an existing configuration file:
python main.py --use-config
python setup.py sdist bdist
This module is licensed under the MIT License.
Contributions are welcome! Please submit issues and pull requests for any improvements or bug fixes.
- FFmpeg for the powerful multimedia processing tools.