Project Update: Enhanced Media Automation & Robust Transcoding
The mkv-2-mp4.sh script, which runs as a scheduled midnight systemd task, has been overhauled to improve automation, reliability, and hardware efficiency. This script acts as the "cleanup crew" for the Mini Pi Media Server, ensuring all new downloads are standardized for DLNA streaming.
Key Features of this Update:
- Intelligent "Promotion" Phase: The script now automatically scans Transmission download subfolders. If a folder contains exactly one video file, it "promotes" it to the main library, deletes the leftover clutter (NFOs, samples, etc.), and removes the empty directory.
- Power-Loss Protection: To prevent file corruption during a power failure, the script now uses a
PROMOTING_orCONVERTING_prefix for temporary files. The final filename is only applied upon successful completion of the move or transcode. - Adaptive Hardware Encoding: It leverages the Raspberry Pi's hardware acceleration (
h264_v4l2m2m). The script now calculates an adaptive bitrate—aiming for 70% of the source quality—to balance file size and visual fidelity dynamically. - Smart Fallback Logic: If the hardware encoder fails , busy or running on a Raspberry Pi 5, the script automatically falls back to a multi-threaded software encode (
libx264) with a specialized mobile-friendly resolution (960x540) to ensure the task finishes. - Automated Library Maintenance: After processing, the script handles the "housekeeping" by resetting permissions for the
minidlnauser and restarting the service to trigger an immediate library re-index.
Workflow Logic:
- Locking: Prevents multiple instances from running simultaneously.
- Stream Copying: If the source is already H.264/AAC, it copies the streams without re-encoding to preserve 100% quality and save CPU.
- Cleanup: Automatically deletes the original
.mkvfiles only after a successful.mp4conversion is verified.
You can download / upgrade by running the following on the Raspberry Pi (either SSH into the Pi or on the actual Pi) :-
wget -qO- https://raw.githubusercontent.com/diddy-boy/mini-pi-media-server/main/install.sh | bash
diddy
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.