Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG mkv to mp4 conversion lacks audio in HTML5 player

I used ffmpeg to convert an mkv file to mp4 using this command line:

ffmpeg -i input.mkv -c copy file-1.mp4

The resulting mp4 plays fine (video and audio) on Linux Mint's Xplayer. But after uploading file-1, it played with no audio. So I uploaded another mp4 file-2, one I didn't have to convert, and it plays both video and audio without a problem. So whatever's going on with file-1 seems to be with my use of ffmpeg.

The player I'm using is called afterglow. But the HTML5 player handles these two files the same way: file-1 & file-2

Does anyone know why the ffmpeg converted file is soundless when played online? Is there a different conversion command that ensures converted mkv files will play with sound by online players?

like image 448
fmc Avatar asked Sep 27 '17 20:09

fmc


People also ask

Does FFmpeg convert MP4 video without audio?

After converting videos using FFmpeg, most of the users have observed that the converted MP4 video lacks audio. In addition to this, users have also found that the converted MP4 videos does not have the subtitles that where originally present in MKV source video. Most of the times, the conversion command does not work when using FFmpeg.

How to convert MKV to MP4 without losing quality?

The easiest way to "convert" MKV to MP4, is to copy the existing video and audio streams and place them into a new container. This avoids any encoding task and hence no quality will be lost, it is also a fairly quick process and requires very little CPU power. The main factor is disk read/write speed.

How to modify the codecs of a video using FFmpeg?

For that, FFmpeg also allows you to modify the codecs to a certain one. For example, if you want to FFmpeg convert to MP4 with H264 codec. You can input: ffmpeg –i input.mkv –c:v h264 output.mp4 -c:v means the following character is used to nominate the codec of video.

How to FFmpeg convert to MP4 with H264 codec?

For example, if you want to FFmpeg convert to MP4 with H264 codec. You can input: ffmpeg –i input.mkv –c:v h264 output.mp4 -c:v means the following character is used to nominate the codec of video.


1 Answers

I see several issues:

  1. The input has DTS audio. Although it is supported in MP4 I guess it doesn't work with HTML5. You'll have to convert to AAC. Add -c:a aac after the -c copy.

  2. Your ffmpeg is old. The FFmpeg AAC encoder had improvements that your version is missing. Avoid any other potential issues by downloading a recent version.

  3. Add -movflags +faststart. This will move some info in the file after encoding so it can begin playback quicker; otherwise it will have to download the whole video before playing.

Example command:

ffmpeg -i input.mkv -c copy -c:a aac -movflags +faststart output.mp4
like image 107
llogan Avatar answered Oct 26 '22 07:10

llogan