当我在背景中播放带有 mpv 的视频时,我得到了这个:
$ tail -f nohup.out
Playing: https://www.facebook.com/TBN/videos/1580372468665943/
(+) Video --vid=1 (*) (h264 1266x720 30.000fps)
(+) Audio --aid=1 (*) 'DASH audio' (aac 1ch 48000Hz) (external)
File tags:
Artist: TBN
Date: 20180113
Title: Joseph Prince joins Matt & Laurie TONIGHT on PRAISE... watch NOW!
AO: [pulse] 48000Hz mono 1ch float
VO: [gpu] 1266x720 yuv420p
AV: 00:00:00 / 00:56:50 (0%) A-V: 0.000
AV: 00:00:00 / 00:56:50 (0%) A-V: 0.000
AV: 00:00:00 / 00:56:50 (0%) A-V: 0.000
... # THERE ARE QUITE A LOT OF LINES
AV: 00:00:03 / 00:56:50 (0%) A-V: 0.000
AV: 00:00:03 / 00:56:50 (0%) A-V: 0.000
Saving state.
Exiting... (Quit)
^C
但我希望有这个输出(就像我在没有 的情况下播放文件时一样nohup
):
$ mpv --no-resume-playback https://www.facebook.com/TBN/videos/1580372468665943/
Playing: https://www.facebook.com/TBN/videos/1580372468665943/
(+) Video --vid=1 (*) (h264 1266x720 30.000fps)
(+) Audio --aid=1 (*) 'DASH audio' (aac 1ch 48000Hz) (external)
File tags:
Artist: TBN
Date: 20180113
Title: Joseph Prince joins Matt & Laurie TONIGHT on PRAISE... watch NOW!
AO: [pulse] 48000Hz mono 1ch float
VO: [gpu] 1266x720 yuv420p
AV: 00:00:03 / 00:56:50 (0%) A-V: 0.000
Saving state.
Exiting... (Quit)
EDIT1:我使用 tty like /dev/pts/2
,因此如果我键入stty inlcr
它应该会影响当前的 tty。
我仍然得到相同的混乱输出tail -f nohup.out
EDIT2:根据@mosvytail
的说法,这不是罪魁祸首,而是mpv
。
我想出了一种方法来对mpv
's进行 S&R stderr
:
$ mpv --no-resume-playback https://www.facebook.com/TBN/videos/1580372468665943/ 2>&1 | perl -p -e '$| = 1;s/\n/\r/g if $_ =~ /^AV:/;s/Saving state/\nSaving state/' | tee mpv_all.log
Playing: https://www.facebook.com/TBN/videos/1580372468665943/
(+) Video --vid=1 (*) (h264 634x360 30.000fps)
(+) Audio --aid=1 (*) (aac 1ch 48000Hz)
AO: [pulse] 48000Hz mono 1ch float
VO: [gpu] 634x360 yuv420p
AV: 00:00:08 / 00:56:50 (0%) A-V: 0.000 Cache: 1024s+86MB
Saving state.
[ffmpeg] https: Will reconnect at 63421312 in 0 second(s), error=End of file.
Exiting... (Quit)
编辑 3:@mosvy 谢谢,它现在可以工作了:
$ nohup sh -c ' mpv --no-resume-playback https://www.facebook.com/TBN/videos/1580372468665943/ 2>&1 | perl -p -e '\''$| = 1;s/\n/\r/g if $_ =~ /^AV:/;s/Saving state/\nSaving state/'\'' ' &
$ tail -f nohup.out
Playing: https://www.facebook.com/TBN/videos/1580372468665943/
(+) Video --vid=1 (*) (h264 634x360 30.000fps)
(+) Audio --aid=1 (*) (aac 1ch 48000Hz)
AO: [pulse] 48000Hz mono 1ch float
VO: [gpu] 634x360 yuv420p
AV: 00:00:08 / 00:56:50 (0%) A-V: 0.000 Cache: 1767s+147MB
Saving state.
[ffmpeg] https: Will reconnect at 103693952 in 0 second(s), error=End of file.
Exiting... (Quit)
^C
编辑 4:感谢@jw013 的另一个解决方案:
export perl_script='$| = 1;s/\n/\r/g if $_ =~ /^AV:/;s/Saving state/\nSaving state/'
mpv="command mpv"
args=("$@")
nohup sh -c "$mpv ${args[*]} 2>&1 | perl -p -e '$perl_script' | tee ~/mpv_all.log" &
我怎样才能做到这一点 ?解决了 !
tail
不替换为。_\r
\n
是您的
mpv
程序根据其 stderr 是否为终端来调整其状态输出。关于
tail
不替换\r
with的简单测试\n
:就像它的 parent 一样
mplayer
,mpv
当有人试图以与作者想象的不同的方式运行它时,它是相当讨厌的;当 stderr 是常规文件或管道时,我无法找到任何选项让它以与终端相同的方式打印其状态。您可以做的最简单的事情是在单独的screen
/tmux
窗口中运行它,而不是使用nohup
.