ffmpeg获取机器可读的输出

huangapple go评论91阅读模式
英文:

ffmpeg get machine readable output

问题

我正在尝试找到一种方法让FFmpeg返回可机器读取的输出。基本上,我只想知道视频转换是否成功。

我正在使用Go代码调用FFmpeg。

output, err := exec.Command("ffmpeg", "-i", source, "-vcodec", "h264", "-acodec", "aac", "-strict", "-2", destination).CombinedOutput()

上述代码执行了以下命令:

ffmpeg -i /tmp/pitchVideo-1494844705-102.mp4 -vcodec h264 -acodec aac -strict -2 /tmp/1494844705.mp4

我得到以下输出:

ffmpeg version 2.4.3-1ubuntu1~trusty6 Copyright (c) 2000-2014 the FFmpeg developers
  built on Nov 22 2014 17:07:19 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --prefix=/usr --extra-version='1ubuntu1~trusty6' --build-suffix=-ffmpeg --toolchain=hardened --extra-cflags= --extra-cxxflags= --libdir=/usr/lib/x86_64-linux-gnu --shlibdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --enable-shared --disable-stripping --enable-avresample --enable-avisynth --enable-fontconfig --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-opengl --enable-x11grab --enable-libxvid --enable-libx265 --enable-libdc1394 --enable-libiec61883 --enable-libzvbi --enable-libzmq --enable-frei0r --enable-libx264 --enable-libsoxr --enable-openal --enable-libopencv
  libavutil      54.  7.100 / 54.  7.100
  libavcodec     56.  1.100 / 56.  1.100
  libavformat    56.  4.101 / 56.  4.101
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  1.100 /  5.  1.100
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/pitchVideo-1494844705-102.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:00:39.28, start: 0.000000, bitrate: 2300 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480, 2231 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[libx264 @ 0x1e12640] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX LZCNT
[libx264 @ 0x1e12640] profile High, level 3.0
[libx264 @ 0x1e12640] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/tmp/new.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.4.101
    Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x480, q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc56.1.100 libx264
    Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, mono, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc56.1.100 aac
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame=  983 fps= 27 q=28.0 Lsize=    4134kB time=00:00:39.24 bitrate= 863.0kbits/s dup=1 drop=0    
video:3542kB audio:565kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.646525%
[libx264 @ 0x1e12640] frame I:9     Avg QP:19.44  size:  9936
[libx264 @ 0x1e12640] frame P:664   Avg QP:23.58  size:  4839
[libx264 @ 0x1e12640] frame B:310   Avg QP:25.50  size:  1045
[libx264 @ 0x1e12640] consecutive B-frames: 56.0%  4.3%  5.2% 34.6%
[libx264 @ 0x1e12640] mb I  I16..4: 33.9% 53.6% 12.5%
[libx264 @ 0x1e12640] mb P  I16..4:  6.7% 10.2%  0.9%  P16..4: 50.7%  8.3%  3.0%  0.0%  0.0%    skip:20.2%
[libx264 @ 0x1e12640] mb B  I16..4:  0.4%  0.4%  0.0%  B16..8: 41.7%  1.4%  0.1%  direct: 1.3%  skip:54.7%  L0:46.9% L1:50.4% BI: 2.8%
[libx264 @ 0x1e12640] 8x8 transform intra:56.8% inter:76.1%
[libx264 @ 0x1e12640] coded y,uvDC,uvAC intra: 37.0% 60.5% 13.9% inter: 17.8% 26.0% 0.3%
[libx264 @ 0x1e12640] i16 v,h,dc,p: 23% 35% 15% 27%
[libx264 @ 0x1e12640] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 27% 21%  4%  4%  4%  4%  5%  5%
[libx264 @ 0x1e12640] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 26% 14%  4%  5%  5%  5%  5%  4%
[libx264 @ 0x1e12640] i8c dc,h,v,p: 53% 22% 19%  6%
[libx264 @ 0x1e12640] Weighted P-Frames: Y:8.7% UV:3.5%
[libx264 @ 0x1e12640] ref P L0: 73.8% 15.7%  8.4%  2.0%  0.1%
[libx264 @ 0x1e12640] ref B L0: 92.9%  6.2%  0.9%
[libx264 @ 0x1e12640] ref B L1: 96.1%  3.9%
[libx264 @ 0x1e12640] kb/s:737.84

编辑1:也许我可以检查新生成的视频文件。但我不知道这是否是一种可靠的方法。

英文:

I am trying to find a way to get FFmpeg to return a machine readable output. basically, I just want to know if video conversion was successfull.

I am calling FFmpeg from go code.

output, err := exec.Command("ffmpeg", "-i", source, "-vcodec", "h264", "-acodec", "aac", "-strict", "-2", destination).CombinedOutput()

The above code executes this command :

ffmpeg -i /tmp/pitchVideo-1494844705-102.mp4 -vcodec h264 -acodec aac -strict -2 /tmp/1494844705.mp4

I get the following output:

ffmpeg version 2.4.3-1ubuntu1~trusty6 Copyright (c) 2000-2014 the FFmpeg developers
built on Nov 22 2014 17:07:19 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration: --prefix=/usr --extra-version='1ubuntu1~trusty6' --build-suffix=-ffmpeg --toolchain=hardened --extra-cflags= --extra-cxxflags= --libdir=/usr/lib/x86_64-linux-gnu --shlibdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --enable-shared --disable-stripping --enable-avresample --enable-avisynth --enable-fontconfig --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-opengl --enable-x11grab --enable-libxvid --enable-libx265 --enable-libdc1394 --enable-libiec61883 --enable-libzvbi --enable-libzmq --enable-frei0r --enable-libx264 --enable-libsoxr --enable-openal --enable-libopencv
libavutil      54.  7.100 / 54.  7.100
libavcodec     56.  1.100 / 56.  1.100
libavformat    56.  4.101 / 56.  4.101
libavdevice    56.  0.100 / 56.  0.100
libavfilter     5.  1.100 /  5.  1.100
libavresample   2.  1.  0 /  2.  1.  0
libswscale      3.  0.100 /  3.  0.100
libswresample   1.  1.100 /  1.  1.100
libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/pitchVideo-1494844705-102.mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf56.40.101
Duration: 00:00:39.28, start: 0.000000, bitrate: 2300 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480, 2231 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
Metadata:
handler_name    : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 64 kb/s (default)
Metadata:
handler_name    : SoundHandler
[libx264 @ 0x1e12640] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX LZCNT
[libx264 @ 0x1e12640] profile High, level 3.0
[libx264 @ 0x1e12640] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/tmp/new.mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf56.4.101
Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x480, q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
Metadata:
handler_name    : VideoHandler
encoder         : Lavc56.1.100 libx264
Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, mono, fltp, 128 kb/s (default)
Metadata:
handler_name    : SoundHandler
encoder         : Lavc56.1.100 aac
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame=  983 fps= 27 q=28.0 Lsize=    4134kB time=00:00:39.24 bitrate= 863.0kbits/s dup=1 drop=0    
video:3542kB audio:565kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.646525%
[libx264 @ 0x1e12640] frame I:9     Avg QP:19.44  size:  9936
[libx264 @ 0x1e12640] frame P:664   Avg QP:23.58  size:  4839
[libx264 @ 0x1e12640] frame B:310   Avg QP:25.50  size:  1045
[libx264 @ 0x1e12640] consecutive B-frames: 56.0%  4.3%  5.2% 34.6%
[libx264 @ 0x1e12640] mb I  I16..4: 33.9% 53.6% 12.5%
[libx264 @ 0x1e12640] mb P  I16..4:  6.7% 10.2%  0.9%  P16..4: 50.7%  8.3%  3.0%  0.0%  0.0%    skip:20.2%
[libx264 @ 0x1e12640] mb B  I16..4:  0.4%  0.4%  0.0%  B16..8: 41.7%  1.4%  0.1%  direct: 1.3%  skip:54.7%  L0:46.9% L1:50.4% BI: 2.8%
[libx264 @ 0x1e12640] 8x8 transform intra:56.8% inter:76.1%
[libx264 @ 0x1e12640] coded y,uvDC,uvAC intra: 37.0% 60.5% 13.9% inter: 17.8% 26.0% 0.3%
[libx264 @ 0x1e12640] i16 v,h,dc,p: 23% 35% 15% 27%
[libx264 @ 0x1e12640] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 27% 21%  4%  4%  4%  4%  5%  5%
[libx264 @ 0x1e12640] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 26% 14%  4%  5%  5%  5%  5%  4%
[libx264 @ 0x1e12640] i8c dc,h,v,p: 53% 22% 19%  6%
[libx264 @ 0x1e12640] Weighted P-Frames: Y:8.7% UV:3.5%
[libx264 @ 0x1e12640] ref P L0: 73.8% 15.7%  8.4%  2.0%  0.1%
[libx264 @ 0x1e12640] ref B L0: 92.9%  6.2%  0.9%
[libx264 @ 0x1e12640] ref B L1: 96.1%  3.9%
[libx264 @ 0x1e12640] kb/s:737.84

Edit 1: Maybe I can just check if new video file was generated. But I don't know if that is a dependable way to do it.

答案1

得分: 7

-progress url添加到ffmpeg选项中,然后您将每秒获得进度信息(以机器可读的key=value格式)。您可以将filename, tcp://, http://等作为url指定。进度信息中的最后一个键始终是progress=...。以下是一个示例输出(为了清晰起见,在进度信息之间添加了空行)。

frame=13164
fps=127.9
stream_0_0_q=29.0
bitrate= 508.9kbits/s
total_size=27962256
out_time_ms=439600181
out_time=00:07:19.600181
dup_frames=0
drop_frames=0
speed=4.27x
progress=continue
frame=13245
fps=128.0
stream_0_0_q=29.0
bitrate= 507.5kbits/s
total_size=28064283
out_time_ms=442386576
out_time=00:07:22.386576
dup_frames=0
drop_frames=0
speed=4.28x
progress=continue
frame=13298
fps=127.6
stream_0_0_q=-1.0
bitrate= 516.9kbits/s
total_size=28675700
out_time_ms=443779773
out_time=00:07:23.779773
dup_frames=0
drop_frames=0
speed=4.26x
progress=end

示例命令:

  1. 将进度信息写入文件:ffmpeg -progress progressinfo.txt ...
  2. 将进度信息发送到本地TCP服务器的端口8910:ffmpeg -progress tcp://127.0.0.1:8910 ...
英文:

Add -progress url to the ffmpeg options, then you will get progress information (machine readable key=value format) every second. You can specify filename, tcp://, http:// etc. as the url. Last key in the progress information is always progress=... The following is an example output (for clarity, blank line is added between progress information).

frame=13164
fps=127.9
stream_0_0_q=29.0
bitrate= 508.9kbits/s
total_size=27962256
out_time_ms=439600181
out_time=00:07:19.600181
dup_frames=0
drop_frames=0
speed=4.27x
progress=continue
frame=13245
fps=128.0
stream_0_0_q=29.0
bitrate= 507.5kbits/s
total_size=28064283
out_time_ms=442386576
out_time=00:07:22.386576
dup_frames=0
drop_frames=0
speed=4.28x
progress=continue
frame=13298
fps=127.6
stream_0_0_q=-1.0
bitrate= 516.9kbits/s
total_size=28675700
out_time_ms=443779773
out_time=00:07:23.779773
dup_frames=0
drop_frames=0
speed=4.26x
progress=end

Example command:

  1. Progress info to file: ffmpeg -progress progressinfo.txt ...
  2. Progress info to local TCP server in port 8910: ffmpeg -progress tcp://127.0.0.1:8910 ...

huangapple
  • 本文由 发表于 2017年5月15日 19:13:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/43978018.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定