macos - 管道和正则表达式 bash 输出

标签 macos bash ffmpeg terminal zsh

我正在尝试使用 ffmpeg 获取视频的尺寸。我使用命令 ffprobe video.mov获取以下数据:

ffprobe version 1.0 Copyright (c) 2007-2012 the FFmpeg developers
  built on Jan 14 2013 10:18:07 with Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.0 --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'linebubble.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 0
    compatible_brands: qt
    creation_time   : 2013-03-12 02:59:34
  Duration: 00:00:14.05, start: 0.050000, bitrate: 135 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 502x288 [SAR 1:1 DAR 251:144], 137 kb/s, 7.84 fps, 60 tbr, 6k tbn, 12k tbc
    Metadata:
      creation_time   : 2013-03-12 02:59:34
      handler_name    : Core Media Data Handler

现在我想将它通过管道传递到一个正则表达式中以获得 502x288 在倒数第四行。

我已经看到了一些使用 python 和 perl 的解决方案,但我希望这是简单的 bash。我该怎么办?

最佳答案

你可以用 2 打方法做到这一点。这里是使用 grepawk :

ffprobe video.mov 2>&1 | grep 'Stream #0' | awk '{print $10}'

关于macos - 管道和正则表达式 bash 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15364358/

相关文章:

python - 从 Adob​​e Premiere/Encoder in Python 和 FFMPEG 中生成的 MP4 获取时间码

python - 在 Swift OS X 应用程序中使用 Python 模块

bash - 在 bash 中,如何打印列表的前 n 个元素?

bash - 字符串的符号错误号

linux - shell 中包含 3 个表达式的 if 语句

audio - ffmpeg 仅分段我的音频文件的第一部分

objective-c - 有符号的 Char 到 Int

java - Mac OS X 10.6.7 Java Path Current JDK 令人困惑

linux - 获取大型已安装驱动器的文件数或文件列表时遇到问题

android - 使用 ffmpeg 将低延迟 RTSP 视频流式传输到 android