Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to transcode videos to be "HTML5 ready" for Chrome and Safari/Safari iOS using VLC. I have my reasons for using VLC rather than ffmpeg which might be an easier tool to use (more docs). For the curious, I really digg VLC ability to read multi part rar files.

So to aim a support on Chrome and Safari iOS it must be an mp4 container with h264(baseline) and AAC(low, and he).
Following the doc, this was my first try 1:

cvlc in.ext --sout="#transcode{vcodec=h264, acodec=aac, channels=2}:std{access=file, mux=mp4, dst=out.mp4}"

The first problem I've encounter came from what I think is a bug in VLC that I'll have to report. Encoding an mp4 h264 in anything but baseline profile create a corrupted stream with lots of dropped frame when read with VLC itself. It is playable in Chrome but you can notice a frame issue. In Safari it is a mess.
The solution I found is to precise the profile baseline to x264:

...transcode{vcodec=h264, acodec=aac, channels=2, venc=x264{profile=baseline}}...

With this you get it working fine in in Chrome but soundless in Safari/Safari iOS and Quicktime. After some digging it seems like this comes from a feature from Apple3:

in a mp4, the AAC audio stream must not be the first stream. Otherwise it will be ignore and only the video stream is played.

Which VLC seems to default to when transcoding. I can't find a way to change the stream order with VLC. There is some doc on how to play with streams with rtp in a the ts mux but nothing for mp4. My way out of this so far is to use ffmpeg to reorder the streams as such:

ffmpeg -i out.mp4 -map 0:1 -map 0:0  -c copy out-ffmpeg.mp4

Which is not terrible as it is quite fast (it does not seems to copy the content of the file, but just modifies it, or I have a really fast ssd :P).

But this is not the optimal solution and I might encounter problems, I'm not sure VLC always puts the audio stream first. And I'd rather not having to add more logic to handle this2.

Does anyone know how to handle reordering of stream with VLC ?


1 On OSX alias cvlc="/Applications/VLC.app/Contents/MacOS/VLC --intf rc"
2 This might be of these cases where you spend way more time finding an cleaner way than it take to go around it with more logic.
3 mp3 gave the same issue.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.