gpt4 book ai didi

perl - yt-dlp 获取仅音频链接 -> ffmpeg 管道音频 -> ffplay

转载 作者:行者123 更新时间:2023-12-04 22:56:40 26 4
gpt4 key购买 nike

好的,我有一个 perl 脚本,我试图弄清楚它为什么会引发 io 错误。首先,我使用 yt-dlg 仅获取音频的链接 - 这可以按预期工作,我可以很好地导航到浏览器中的链接。然后我在 perl 中打开一个 ffmpeg 管道,然后尝试从 ffmpeg 读取输出,最终,如果我可以让它工作,我将处理 ffmpeg 输出然后发送到命名管道。
当我处理通过 yt-dlp 获得的链接中的数据时,问题来自 ffmpeg,我认为这与我的 while 循环有关,但我不确定是什么。我有一个名为“输入”的命名管道。我用以下命令召唤 ffmpeg:

#/usr/bin/perl
use strict;
use warnings;

my $file = /path/to/named/pipe
my $read_len = 1024;

open (my $SOURCE_AUDIO, '-|', "ffmpeg -y -i \'$link\' -map 0 -c copy -ac 2 -f opus -ar 48000 pipe:1");
binmode($SOURCE_AUDIO);

# process the ffmpeg output.i have a function i want to implement here,
# but i need to be able to parse ffmpeg output in set read lengths

while( read($SOURCE_AUDIO, my $buf, $read_len)){
print $file $buf;
};
但在播放结束之前,在音频流 ffmpeg 结尾附近的某个地方会抛出如下错误:
[tls @ 0x5d0de00] Error in the pull function..2kbits/s speed=1.21x
[tls @ 0x5d0de00] IO error: Connection reset by peer
[tls @ 0x5d0de00] The specified session has been invalidated for some reason.
Last message repeated 1 times
https://rr3---sn-(truncated): Input/output error
size= 1021kB time=00:01:18.36 bitrate= 106.7kbits/s speed=1.21x
video:0kB audio:1012kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.808163%
我不确定是什么导致它提前结束,或者是什么导致它被终止。我可以下载文件并重新编码(如果需要),然后使用 ffplay 完美播放它,但我无法终生解析 ffmpeg 输出并将其写入命名管道。任何帮助肯定会不胜感激。谢谢
附言我正在使用最新更新的 Windows 11 和 WSL 内置的 perl:
This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux-gnu-thread-multi
(with 50 registered patches, see perl -V for more detail)

Copyright 1987-2019, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

最佳答案

通过让 yt-dlp 处理下载,然后将 yt-dlp 输出通过管道传输到 ffmpeg,我能够解决此错误。然后我能够在我的 while 循环中读取 ffmpeg 输出:

#!/usr/bin/perl
use warnings;
use strict;

my $query = shift;

open my $file, '+>', "/home/user/pipes/input" or die $!;
binmode($file);

# system("yt-dlp -q -f bestaudio[acodec=opus] ytsearch:'$query' -o - | ffmpeg -hide_banner -loglevel error -i pipe: -map 0 -c copy -ac 2 -f opus -ar 48000 pipe: | ffplay -i pipe:");

open(my $SOURCE_AUDIO, '-|', "yt-dlp -q -f bestaudio[acodec=opus] ytsearch:'$query' -o - | ffmpeg -hide_banner -loglevel error -i pipe: -map 0 -c copy -ac 2 -f opus -ar 48000 pipe:");
binmode($SOURCE_AUDIO);

while ( <$SOURCE_AUDIO> ) {
print $file $_;
print length($_) . "\n"; # prints length of current data stream captured from ffmpeg
}
像我期望的那样工作。

关于perl - yt-dlp 获取仅音频链接 -> ffmpeg 管道音频 -> ffplay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72510900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com