bash:显示已过滤ffmpeg的动态输出 [英] bash: displaying filtered & dynamic output of ffmpeg
问题描述
在这个问题之后,答案已经部分解决了我的问题。
我想要一个ffmpeg的选择结果。
所以,使用这个命令:
After this question whose the answer had partially resolved my problem. I would like to have a selected result of ffmpeg. So, with this command:
ffmpeg -y -i "${M3U2}" -vcodec copy -acodec copy "${Directory}/${PROG}_${ID}.mkv" 2>&1 | egrep -e '^[[:blank:]]*(Duration|Output|frame)'
结果是:
Duration: 00:12:28.52, start: 0.100667, bitrate: 0 kb/s
Output #0, matroska, to '/home/path/file.mkv':
但是在结果我错过了这个动态行:
But in the result I am missing this dynamic line:
frame= 1834 fps=166 q=-1.0 Lsize= 7120kB time=00:01:13.36 bitrate= 795.0kbits/s
此行每秒更改一次。如何修改命令行来显示这行?我的程序应该看这行,并且就地显示时间更新。谢谢
This line changes every second. How can I modify the command line to display this line? My program should read this line and display the "time" updating in-place. Thanks
ffmpeg -y -i "${M3U2}" -vcodec copy -acodec copy "${Directory}/${PROG}_${ID}.mkv" 2>&1 |
{ while read line
do
if $(echo "$line" | grep -q "Duration"); then
echo "$line"
fi
if $(echo "$line" | grep -q "Output"); then
echo "$line"
fi
if $(echo "$line" | grep -q "Stream #0:1 -> #0:1"); then
break
fi
done;
while read -d $'\x0D' line
do
if $(echo "$line" | grep -q "time="); then
echo -en "\r$line"
fi
done; }
感谢ofrommel
Thanks to ofrommel
推荐答案
您需要使用CR(回车符)作为分隔符解析输出,因为这是ffmpeg用于在同一行上打印的。首先使用另一个循环与常规分隔符来遍历第一行以获取持续时间和输出:
You need to parse the output with CR (carriage return) as a delimiter, because this is what ffmpeg uses for printing on the same line. First use another loop with the regular separator to iterate over the first lines to get "Duration" and "Output":
ffmpeg -y -i inputfile -vcodec copy -acodec copy outputfile 2>&1 |
{ while read line
do
if $(echo "$line" | grep -q "Duration"); then
echo "$line"
fi
if $(echo "$line" | grep -q "Output"); then
echo "$line"
fi
if $(echo "$line" | grep -q "Stream mapping"); then
break
fi
done;
while read -d $'\x0D' line
do
if $(echo "$line" | grep -q "time="); then
echo "$line" | awk '{ printf "%s\r", $8 }'
fi
done; }
这篇关于bash:显示已过滤ffmpeg的动态输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!