#!/bin/bash
inotifywait -m /home/user/mkv_input -e create -e moved_to |
while read path action file; do
if [[ $file == *.mkv ]]; then
ffmpeg -i "$path/$file" -c:v libx264 -preset fast -c:a aac "/home/user/mp4_output/$file%.mkv.mp4"
rm "$path/$file" # Optional: delete original
fi
done
Save this, run it as a systemd service on your MyServerCom, and your server becomes an auto-transcoding factory.
location /videos/
vod hls;
vod_mkv_remux mp4;
vod_segment_duration 2000;
Result: MKV works seamlessly in any browser without quality loss.
"Work" often implies making the file ready for end-users. MKV files are not always optimized for streaming over the web, particularly if the metadata (moov atom) is located at the end of the file. The server has to download the whole file to read the duration. myservercom filemkv work
Remuxing for Fast-Start
You can use ffmpeg to move the metadata to the beginning of the file without losing quality (this is remuxing, not re-encoding, so it is very fast).
ffmpeg -i input.mkv -c copy -movflags +faststart output_streaming.mkv
Note: While MKV is a container, if you are converting to MP4 for web playback, the -movflags +faststart flag is crucial. Save this, run it as a systemd service
If you absolutely must serve the file via a basic myservercom web server without transcoding (e.g., you have a cheap shared hosting plan that cannot run Plex), you must convert the MKV to a web-friendly format like MP4.
The Tool: FFmpeg (free, command-line).
Run this command on your server or local machine, then re-upload:
ffmpeg -i input.mkv -c:v libx264 -c:a aac -movflags +faststart output.mp4
After this, http://myservercom/output.mp4 will play directly in any browser's HTML5 player. You lose the MKV container benefits but gain universal "workability." Result: MKV works seamlessly in any browser without
To get the best performance from myservercom filemkv work, tweak your server configuration:
Cause: The video codec (e.g., AV1) is unsupported.
Fix: Transcode only the video track:
ffmpeg -i input.mkv -c:v libx265 -c:a copy output.mkv