3

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.

4
  • 1
    Can't you just check the exit code for 0? File check is dependable if size > 0. Actually, there are a couple of edge cases, but they involve wonky input rather than processing errors.
    – Gyan
    May 15, 2017 at 11:29
  • @Mulvya Yes I can check exit code but I don't know if it will be accurate. I am hoping for a reliable way to do it. Is it something you would do with confidance?
    – Jya
    May 15, 2017 at 11:32
  • Yes, 0 will be success. Failure otherwise.
    – Gyan
    May 15, 2017 at 11:41
  • It might be an overkill but there are Go bindings to libav, and you can just open the file with it and analyze it May 15, 2017 at 11:58

1 Answer 1

6

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 ...
6
  • Thank you, this is great. More than I wanted :-). One thing I noticed is that it doesn't have a line between each section as shown above. But no problem.
    – Jya
    May 15, 2017 at 13:07
  • You're welcome. About the new line, I mentioned it in the answer i.e. I added the blank line for clarity. You can split the section using progress=.... Or, in addition to the main program, create simple tcp server with golang to retrieve the progress info.
    – putu
    May 15, 2017 at 13:18
  • 1
    Have you checked whether this logs error if it occurs?
    – Gyan
    May 15, 2017 at 14:02
  • 1
    @Mulvya Error message is not recorded in the progress output. Instead, it will be available through stderr (what will be shown depends on -loglevel option) or if -report option is specified, all the console output will be written to a log file. If error occurs or ffmpeg is terminated before finishing the job, the progress output will not contains progress=end line or it will be empty.
    – putu
    May 15, 2017 at 14:33
  • @Mulvya Thanks for asking. I am currently checking if progress=end is present
    – Jya
    May 17, 2017 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.