如何使用 python 子进程将多个音频流添加到在 vlc 中打开的视频
How to add multiple audio streams to a video opened in vlc using python subprocess
我已经学会了如何使用 python 子进程使用代码在 vlc 中打开视频文件:
import os, subprocess
vlcPath = "C:/Program Files/VideoLAN/VLC/vlc.exe"
vid = "vid.mp4"
aud = "aud.mp3"
aud2 = "aud2.mp3"
#To open just the video in vlc, the following code works:
subprocess.Popen([vlcPath, vid])
现在如何让这段代码加载其他音频文件,以便它们作为编解码器同时加载,并且用户可以轻松地在来自 vlc 的特定音频文件之间切换。
我可以直接从 vlc 实现同步流,方法是将选项设置为另一个文件,单击选项 "Play another media asynchronously (extra audio file,...)" 并在额外媒体部分添加路径。
这样做时,vlc 添加了一个选项“:input-slave=[filename]”
现在我怎样才能在 python 中做同样的事情,因为以下方法不起作用:
subprocess.Popen([vlcPath, vid, aud, aud2])
或
subprocess.Popen([vlcPath, "{} :input-slave={}".format(vid, aud)])
或
subprocess.Popen([vlcPath, vid, ":input-slave=", aud, ":input-slave=", aud2])
我在上面尝试的第一个和第三个解决方案,打开 "vlcPath" 之后的所有索引项目,作为 vlc 播放列表中的单独项目。第二种解决方案导致我出错。
我已经尽力详细解释了我的问题,但是如果您需要更多详细信息,请随时问我,我会尽力回答您的问题。
谢谢。
好的,我刚刚找到了解决我自己问题的方法。
我从 Synetech 的 答案中找到了以下 post 的解决方案:https://superuser.com/questions/685507/how-to-play-a-soundless-video-and-add-a-audio-file-at-the-same-time
为了让它工作,我尝试做的就是将 --input-slave= 添加到音频文件中,例如:
subprocess.Popen([vlcPath, vid, "--input-slave="+aud])
虽然这可行,但如果我尝试使用此方法添加其他音频,则它不起作用,即:
subprocess.Popen([vlcPath, vid, "--input-slave="+aud, "--input-slave="+aud2])
这行不通。
因此,如果您对此也有解决方案,那将很有帮助。
谢谢。
回答太晚了,但对于下一个人,你可以使用类似的东西:
subprocess.Popen([vlcPath, vid, "--input-slave="+aud+"#"+aud2])
来自VLC command line documentation
--input-slave=<string> Input slave (experimental)
This allows you to play from several inputs at the same time. This
feature is experimental, not all formats are supported. Use a '#'
separated list of inputs.
我已经学会了如何使用 python 子进程使用代码在 vlc 中打开视频文件:
import os, subprocess
vlcPath = "C:/Program Files/VideoLAN/VLC/vlc.exe"
vid = "vid.mp4"
aud = "aud.mp3"
aud2 = "aud2.mp3"
#To open just the video in vlc, the following code works:
subprocess.Popen([vlcPath, vid])
现在如何让这段代码加载其他音频文件,以便它们作为编解码器同时加载,并且用户可以轻松地在来自 vlc 的特定音频文件之间切换。
我可以直接从 vlc 实现同步流,方法是将选项设置为另一个文件,单击选项 "Play another media asynchronously (extra audio file,...)" 并在额外媒体部分添加路径。
这样做时,vlc 添加了一个选项“:input-slave=[filename]”
现在我怎样才能在 python 中做同样的事情,因为以下方法不起作用:
subprocess.Popen([vlcPath, vid, aud, aud2])
或
subprocess.Popen([vlcPath, "{} :input-slave={}".format(vid, aud)])
或
subprocess.Popen([vlcPath, vid, ":input-slave=", aud, ":input-slave=", aud2])
我在上面尝试的第一个和第三个解决方案,打开 "vlcPath" 之后的所有索引项目,作为 vlc 播放列表中的单独项目。第二种解决方案导致我出错。
我已经尽力详细解释了我的问题,但是如果您需要更多详细信息,请随时问我,我会尽力回答您的问题。
谢谢。
好的,我刚刚找到了解决我自己问题的方法。
我从 Synetech 的 答案中找到了以下 post 的解决方案:https://superuser.com/questions/685507/how-to-play-a-soundless-video-and-add-a-audio-file-at-the-same-time
为了让它工作,我尝试做的就是将 --input-slave= 添加到音频文件中,例如:
subprocess.Popen([vlcPath, vid, "--input-slave="+aud])
虽然这可行,但如果我尝试使用此方法添加其他音频,则它不起作用,即:
subprocess.Popen([vlcPath, vid, "--input-slave="+aud, "--input-slave="+aud2])
这行不通。
因此,如果您对此也有解决方案,那将很有帮助。
谢谢。
回答太晚了,但对于下一个人,你可以使用类似的东西:
subprocess.Popen([vlcPath, vid, "--input-slave="+aud+"#"+aud2])
来自VLC command line documentation
--input-slave=<string> Input slave (experimental)
This allows you to play from several inputs at the same time. This
feature is experimental, not all formats are supported. Use a '#'
separated list of inputs.