95
Views

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.

Article Tags:
Article Categories:
Coding
SDATIC

Web developer and former photographer by trade...gamer and all around tech enthusiast in his free time. Christoph started sdatic.com as a way to organize his ideas, research, notes and interests. He also found it enjoyable to connect and share with others who parallel his interests. Everything you see here is a resource that he found useful or interesting and he hopes that you will too.

Leave a Reply

Your email address will not be published. Required fields are marked *