以小时:分钟:秒为单位获取视频长度将结果转换为秒

Too*_*day 4 command-line video

现在我正在使用以下命令来获取视频持续时间的输出

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal 'video file.mp4'
Run Code Online (Sandbox Code Playgroud)

结果是0:33:29.410000

我需要使用以下内容更改此结果

  • 额外的 0 必须在前面 0:33:29.410000
  • 秒数必须向上或向下四舍五入。最终输出应该是00:33:29

pLu*_*umo 5

使用awk

awk -F: '{printf "%02d:%02d:%02d\n",$1,$2,$3}'
Run Code Online (Sandbox Code Playgroud)

或者如果您想在转换前检查格式以防止错误:

awk -F: '/^[0-9]+:[0-9]+:[0-9]+/ {printf "%02d:%02d:%02d\n",$1,$2,$3}'
Run Code Online (Sandbox Code Playgroud)
$ ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal 'video file.mp4' | awk -F: '{printf "%02d:%02d:%02d\n",$1,$2,$3}'
00:33:29
Run Code Online (Sandbox Code Playgroud)