video - Reorder streams with VLC

24
2013-08
  • 3on

    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.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    video - How to stream multiple files on demand in VLC?
  • romkyns

    Is there any way at all that I can set up VLC on a server PC in such a way that I can access a list of all my videos from another PC, and pick one to be streamed on demand?

    I've been pointed at this streaming guide (pdf), but it's pretty useless. For a start, most of the menus in those screenshots don't match the actual current version VLC, and then it sort of assumes you already know what you're doing.

    So far I managed to figure out how to stream a single file, which I must choose before watching on the server PC - pretty useless if you ask me! The impenetrable "UI" doesn't help either...

    (P.S. The reason I'm going for streaming rather than the very simple to set up network drive is described in this question)


  • Related Answers
  • joe

    VideoLAN Manager is a small media manager designed to control multiple streams with only one instance of VLC. It allows multiple streaming and video on demand (VoD). This manager being a new feature, it can only be controlled by the telnet interface or the http interface.

    Steps : http://www.videolan.org/doc/streaming-howto/en/ch05.html

    For Exanmple

    vlm configuration files.

    new channel1 broadcast enabled
    setup channel1 input http://host.mydomain/movie.mpeg
    setup channel1 output #rtp{mux=ts,dst=239.255.1.1,sap,name="Channel 1"}
    
    new channel2 broadcast enabled
    setup channel2 input rtp://@239.255.12.42
    setup channel2 output #rtp{mux=ts,dst=239.255.1.2,sap,name="Channel 2"}
    
    control channel1 play
    control channel2 play
    

    Video On Demand Basic example

    First launch the vlc

    % vlc --ttl 12 -vvv --color -I telnet --telnet-password videolan --rtsp-host 0.0.0.0:5554

    Then you connect to the vlc telnet interface and create the vod object

    new Test vod enabled
    setup Test input my_video.mpg
    

    You can access to the stream with:

    % vlc rtsp://server:5554/Test
    
  • 8088

    In VLC :

    Click “File > Open File” to bring up the “Open” dialog box.

    alt text

    Click on the “Browse” button to bring up a standard Windows file selection box. Select the file you want to play. Then click “Open”. We've selected multiple files so VLC will build a playlist.

    alt text

    Your selection should appear in the text box next to the “Browse” button. Click the checkbox for “Stream Output” and then click the button “Settings.”

    alt text

    Check the box next to “Play Locally” under “Output Methods.” When streaming to another system you don't have to play the file on the server, but we will use this option to visually confirm that our video is playing properly before trying to access the stream from another computer.

    Check the box marked “UDP” and type in the IP address of the computer you want to stream the file to. Then click “OK”. The file is ready to play so click “OK” in the “Open” dialog box too.

    [This step did not work with my .flv video. Though the server was playing the video locally, the client (localhost:8181) did not play the video. Corrective action was to uncheck "UDP" checkbox" (this could be because my UDP transport protocol was not working on my laptop or MPEG-TS was not a corrective format container for streaming. MPEG-TS was the only format container or encapsulation method available when "UDP" is selected) and click "HTTP" checkbox, then set "Address" as 127.0.0.1 and port as "8181". Now select "ASF" as the encapsulation method and keep the rest of the "Stream output" dialog defaults. Click "OK" to go bakc to the "Open" dialog box and then click "OK" in the "Open" dialog box to start playing the video.]

    alt text

    The video or audio file should begin playing on the computer. The last thing to do before switching to your second computer is to turn on VLC’s web interface by clicking “Settings > Add Interface > Web Interface”.

    alt text

    Open VLC on your second machine. We are using a Linux machine.

    Click on “File > Open Network Stream”. UDP is already selected so you just need to click the “OK” button and VLC will start playing your stream.

    alt text

    Now that the stream is successfully playing on your computer you can open up a web browser to control VLC remotely. Type “http://:8080/” into the address bar. The web browser will present you with all of the controls you need to manage playlists and playback remotely.

    Source