It’s a simple thing but I ran into an issue converting an mkv to an mp4. After the conversion the video didn’t have sound when playing on html5. After looking into it further I found that my copy of Debian Linux had ffmpeg 5. I didn’t want to deal with compiling a newer version.
The Code
Adding a couple of operators I was able to get my file to convert with sound.
ffmpeg -i original-file.mkv -c copy -tag:v hvc1 -c:a aac -movflags +faststart new-file.mp4
If you want to run this for an entire directory you can run this command.
for i in *.mkv; do ffmpeg -i "$i" -codec copy -tag:v hvc1 -c:a aac -movflags +faststart "${i%.*}.mp4"; done
For clarification on the what a couple of the the items.
- -tag:v hvc1 – was used this to ensure h264 is used so that the videos would play on my iPad.
- -c:a aac – was used this so that audio would work when converting.
- +faststart – was used to ensure that if played over a network the video would play at page load instead of after the file was downloaded.
Conclusion
It’s just a simple snippet but it saved me a lot of time.