http interface - Change selected audio track

All you've ever wanted to know about the ActiveX, Mozilla plugins, the web interface and various PHP extensions
emcodem
Blank Cone
Blank Cone
Posts: 10
Joined: 05 Jul 2022 12:12

http interface - Change selected audio track

Postby emcodem » 05 Jul 2022 12:25

Dears,

sorry that i am totally new here and directly post my first question, i hope this is not offending to anyone.

Using VLC latest release 3.0.17.4.
I am spawning vlc from nodejs and configure it to send "what it plays" to stdout (which is forwarded to a jsmpeg webplayer).
This all seems to work pretty well but i would like to be able to change the playing audio track, just as i would do it on the main vlc interface in the audio->tracks menu.
So, using an example source file that has 4 stereo tracks, it works to select the tracks from the VLC UI but 2 things do not work:

1) add audio-track=1 to the commandline transcode settings (e.g. directly after height=250).

2) calling the http api like this (i didnt find any documentation about this but reading the source code, it could potentially work: https://github.com/videolan/vlc/blob/e3 ... quests.lua ):

Code: Select all

http://localhost:1235/requests/status.xml?command=audio_track&val=1
Here is how i spawn vlc from my code:

Code: Select all

var vlc = spawn("C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe", [ "-I","http", config.file, "--sout-avformat-mux","mpeg2ts", "--sout-avformat-options", "muxdelay=50", "--no-sout-all", //prevent downmix all channels "--play-and-pause", //pause at last frame //"--start-paused", //audio-track=1 in encode below dont work ':sout=#transcode{,vcodec=mp1v,acodec=mpga,vb=1256k,ab=256k,width=512,height=250}:duplicate{dst=standard{access=udp},dst=standard{access=file,mux=avformat{mux=mpegts,options={muxdelay=0.001}},dst="-"}}', //"--sout-avcodec-keyint=10", "--http-host" ,"127.0.0.1", "--http-port", "1235", '--http-pass','SUPERSECRET', ] );
Above command explained: "--no-sout-all" Disables the automatic downmix of all channels to the main output, the duplicate and udp output is needed because udp seems to force "realtime encoding", if i don't do that, it will encode and stream the wanted mpeg1 ts in maximum possible speed.

What happens in both versions (commandline option or http api) is that either just the first track plays or silence plays.
Any clues what i am doing wrong?

emcodem
Blank Cone
Blank Cone
Posts: 10
Joined: 05 Jul 2022 12:12

Re: http interface - Change selected audio track

Postby emcodem » 09 Jul 2022 02:27

Small update, i changed the strategy and dropped the udp output for forcing realtime but instead i do spawn ffmpeg paralell to vlc and pipe the vlc output via stdin to ffmpeg.
ffmpeg does a codec copy and -re for forcing realtime output. This seems to work a lot more stable than vlc directly streaming in realtime with mpeg-1.

Additionally i need to correct myself, "--audio-track=1" on commandline works but it still does not work for the running encode stream using

Code: Select all

http://localhost:1235/requests/status.xml?command=audio_track&val=1

namxam
New Cone
New Cone
Posts: 1
Joined: 03 Jan 2023 12:07

Re: http interface - Change selected audio track

Postby namxam » 03 Jan 2023 12:21

I just stumbled upon this topic while researching a way to change the language via http interface. Thanks for the quick link to VLC's source code. But I can report, that it works flawlessly via requests to

Code: Select all

/requests/status.xml?command=audio_track&val=2
It takes a few milliseconds to switch the audio track. But it requires the file too be playing or being paused. When playing a new file, it always starts with the default language. I created the file via

Code: Select all

ffmpeg -i video_with_default_lang.mp4 \ -i lang_2.mp3 \ -i lang_3.mp3 \ -map 0:a -map 1:a -map 2:a \ -metadata:s:a:0 language=ger \ -metadata:s:a:1 language=eng \ -metadata:s:a:2 language=non \ -disposition:a:0 default \ -c:v copy \ -shortest \ output.mp4
And it is important, that the languages are 0 based. To play the default language, you have too specify 0.


Return to “Web and scripting”

Who is online

Users browsing this forum: No registered users and 12 guests