【问题标题】:bash: displaying filtered & dynamic output of ffmpegbash:显示 ffmpeg 的过滤和动态输出
【发布时间】:2014-07-03 07:59:27
【问题描述】:

question 之后,其答案部分解决了我的问题。 我想要一个 ffmpeg 的选定结果。 所以,用这个命令:

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':

但结果我错过了这条动态线:

frame= 1834 fps=166 q=-1.0 Lsize=    7120kB time=00:01:13.36 bitrate= 795.0kbits/s

这条线每秒都在变化。如何修改命令行以显示此行?我的程序应该读取这一行并就地显示“时间”更新。谢谢

解决方案:

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

【问题讨论】:

    标签: bash ffmpeg output


    【解决方案1】:

    您需要使用 CR(回车)作为分隔符来解析输出,因为这是 ffmpeg 用于在同一行上打印的内容。首先使用另一个带有常规分隔符的循环遍历第一行以获得“持续时间”和“输出”:

    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; }
    

    【讨论】:

    • 谢谢,这几乎就是我想要的。我也需要“持续时间”和“输出”,所以我可以在 awk 命令中添加它吗?
    • 它现在打印到位的时间信息。请考虑下次更详细地说明您的问题,因为它可能会节省人们回答问题的时间。谢谢。
    • 在您的帮助下,我的新代码在我的问题中得到了更新。再次感谢您。
    猜你喜欢
    • 1970-01-01
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 2023-03-14
    • 2023-03-19
    • 2017-09-07
    相关资源
    最近更新 更多