好的,我有一个perl脚本,我试图弄清楚它为什么要抛出io错误。首先,我使用yt来获取音频的链接--这和预期的一样工作,我可以在浏览器中导航到该链接。然后我在perl中打开一个ffmpeg管道,然后尝试从ffmpeg读取输出,最后,如果我能够完成这个工作,我将处理ffmpeg输出,然后发送到一个指定的管道。
当我处理从yt获得的链接的数据时,问题来自ffmpeg,我认为它与我的while循环有关,但我不确定是什么。我有一个叫做“输入”的命名管道。我在以下几个方面进行了传讯:
#/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输出并将它写到一个指定的管道中。如果能提供任何帮助,我们将不胜感激。谢谢
P.S.我正在使用最新更新的windows 11和用perl构建的WSL:
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.发布于 2022-06-05 22:20:26
我能够避免这个错误,让handle处理下载,然后管道handle输出到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
}就像我期望的那样。
https://stackoverflow.com/questions/72510900
复制相似问题