Advanced: Automating Post-Processing with ffmpeg-python
Table of Contents
Once Cam Software finishes a recording, you might want to perform additional tasks: converting to a more compressed format (H.265), merging multiple segments from the same session, or extracting thumbnails. While Cam Software has built-in tools, automating this with ffmpeg-python allows for complex, multi-terabyte workflows.
1) Installation
You’ll need Python and the ffmpeg-python wrapper.
pip install ffmpeg-python
2) Automatically Merging Segments
If a stream disconnected and reconnected, you might have part1.mp4 and part2.mp4. Here is a script to merge them losslessly.
import ffmpeg
import os
def merge_segments(files, output_name):
# Create a temporary concat file
with open('inputs.txt', 'w') as f:
for file in files:
f.write(f"file '{os.path.abspath(file)}'\\n")
(
ffmpeg
.input('inputs.txt', format='concat', safe=0)
.output(output_name, c='copy')
.run()
)
os.remove('inputs.txt')
# Example usage:
# merge_segments(['stream_part1.mp4', 'stream_part2.mp4'], 'full_session.mp4')
3) Batch Converting to H.265 (HEVC)
To save up to 50% disk space while maintaining quality, convert your archives to H.265.
import ffmpeg
def compress_video(input_file, output_file):
(
ffmpeg
.input(input_file)
.output(output_file, vcodec='libx265', crf=24, preset='slow')
.run()
)
4) Extracting “Best” Thumbnails
Instead of a random frame, you can extract a frame every 5 minutes to create a contact sheet or find the best preview image.
import ffmpeg
def extract_thumbnails(input_file, output_pattern):
(
ffmpeg
.input(input_file)
.filter('fps', fps='1/300') # One frame every 5 minutes
.output(output_pattern)
.run()
)
5) Integration with Cam Software
You can run these scripts as part of your Move-to-Archive workflow. By checking the folder for files older than 24 hours (ensuring the recording has finished), you can trigger the compression or merging process automatically before moving the files to your NAS.
Summary
ffmpeg-python brings the full power of the command line to your automation scripts. By combining it with your existing Python workflows, you can manage a massive library with zero manual intervention.
Related guides
- Professional File Organization & Archiving
- Automated Library Backups (Rclone & Crontab)
- Video Formats & Codecs Guide
Loading comments...