在下载使用YouTube-DL和FFMPEG库下载修剪的YouTube视频的音频数据时面临问题
我正在尝试使用youtube-dl(v2021.12.17)和ffmpeg(v4.2.2)python上的YouTube视频的音频内容下载YouTube视频的音频内容,在Windows 10 PC上。当在Pycharm终端执行命令时,我可以下载音频数据,但是在使用OS.System()命令时无法下载相同的内容。
执行命令时,我可以下载数据
"ffmpeg -ss 30 -t 10 -i $(youtube-dl -f best -g https://www.youtube.com/watch?v=3NGZcpAZcl0) -- output1.wav"
例如,当我在Pycharm终端
。但是,我遇到了一个错误,当我尝试在编辑器窗口中执行相同的操作,如下所示,
os.system('ffmpeg -ss 30 -t 10 -i $(youtube-dl -f best -g https://www.youtube.com/watch?v=3NGZcpAZcl0) -- output1.wav')
error: $(youtube-dl: No such file or directory
我还尝试将$()链接封闭在引号中,然后执行。但是,在执行此操作之后,我遇到了不同的错误,如下所示
os.system('ffmpeg -ss 30 -t 10 -i "$(youtube-dl -f best -g https://www.youtube.com/watch?v=3NGZcpAZcl0)" -- output1.wav')
error: $(youtube-dl -f best -g https://www.youtube.com/watch?v=3NGZcpAZcl0): Invalid argument
,你们中的任何一个人都可以帮助我解决此错误吗?
I'm trying to download the audio content of a trimmed YouTube video using youtube-dl (v2021.12.17) and FFmpeg (v4.2.2) libraries in python, on Windows 10 PC. I am able to download the audio data when the command is executed on the Pycharm terminal, but not able to download the same content when using os.system() command.
For example, I'm able to download the data when I execute
"ffmpeg -ss 30 -t 10 -i $(youtube-dl -f best -g https://www.youtube.com/watch?v=3NGZcpAZcl0) -- output1.wav"
command on the Pycharm terminal.
But, i'm getting an error, when I try to execute the same in the Editor window as shown below,
os.system('ffmpeg -ss 30 -t 10 -i $(youtube-dl -f best -g https://www.youtube.com/watch?v=3NGZcpAZcl0) -- output1.wav')
error: $(youtube-dl: No such file or directory
I also tried enclosing the $() link in quotes and then executed it. But, after doing this, I am getting a different error as shown below
os.system('ffmpeg -ss 30 -t 10 -i "$(youtube-dl -f best -g https://www.youtube.com/watch?v=3NGZcpAZcl0)" -- output1.wav')
error: $(youtube-dl -f best -g https://www.youtube.com/watch?v=3NGZcpAZcl0): Invalid argument
So, can any of you help me in resolving this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它不起作用,因为您的命令实际上是一个shell脚本,通过
$(...)
从另一个系统调用中插入字符串。 Python的OS.System()
一次只能运行一个shell命令(基于观察)。这是什么意思?您需要运行
YouTube-DL
和ffmpeg
用subprocess
分别命令:It doesn't work because your command is actually a shell script inserting a string from another system call by
$(...)
. Python'sos.system()
can run only one shell command at a time (based on observation).What does this mean? You need to run
youtube-dl
andffmpeg
commands separately withsubprocess
:我怀疑这是一个路径问题。
尝试指定YouTube-DL的完整路径:
I suspect it's a PATH problem.
Try specifying the full path of youtube-dl: