0

After executing any ffmpeg command

ffmpeg -i "in.mov" -c:v libx264 "out.mp4"

a lot of encoding stats are outputted in the console e.g.

  ffmpeg version git-2020-07-15-a54b367 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200621
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 55.100 / 56. 55.100
  libavcodec     58. 96.100 / 58. 96.100
  libavformat    58. 48.100 / 58. 48.100
  libavdevice    58. 11.101 / 58. 11.101
  libavfilter     7. 87.100 /  7. 87.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    creation_time   : 2021-11-19T04:54:24.000000Z
    encoder         : Blackmagic Design DaVinci Resolve Studio
  Duration: 00:00:15.02, start: 0.000000, bitrate: 513581 kb/s
    Stream #0:0: Video: dnxhd (DNXHR SQ) (AVdh / 0x68645641), yuv422p(tv, bt709/bt709/unknown), 2560x1440, 511272 kb/s, SAR 1:1 DAR 16:9, 60 fps, 60 tbr, 15360 tbn, 15360 tbc (default)
    Metadata:
      creation_time   : 2021-11-19T04:54:24.000000Z
      handler_name    : VideoHandler
      encoder         : DNxHR SQ
      timecode        : 00:32:01:20
    Stream #0:1: Audio: pcm_s24le (lpcm / 0x6D63706C), 48000 Hz, stereo, s32 (24 bit), 2304 kb/s (default)
    Metadata:
      creation_time   : 2021-11-19T04:54:24.000000Z
      handler_name    : SoundHandler
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s
    Metadata:
      creation_time   : 2021-11-19T04:54:24.000000Z
      handler_name    : TimeCodeHandler
      timecode        : 00:32:01:20
Stream mapping:
  Stream #0:0 -> #0:0 (dnxhd (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 000001f24216e180] using SAR=1/1
[libx264 @ 000001f24216e180] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001f24216e180] profile High 4:2:2, level 5.1, 4:2:2, 8-bit
[libx264 @ 000001f24216e180] 264 - core 160 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - 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=36 lookahead_threads=6 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 'out.mp4':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf58.48.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv422p(progressive), 2560x1440 [SAR 1:1 DAR 16:9], q=-1--1, 0.02 fps, 15360 tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2021-11-19T04:54:24.000000Z
      handler_name    : VideoHandler
      timecode        : 00:32:01:20
      encoder         : Lavc58.96.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp (24 bit), 128 kb/s (default)
    Metadata:
      creation_time   : 2021-11-19T04:54:24.000000Z
      handler_name    : SoundHandler
      encoder         : Lavc58.96.100 aac
frame=  901 fps= 60 q=-1.0 Lsize=   99089kB time=00:00:15.01 bitrate=54048.5kbits/s speed=   1x    
video:98829kB audio:235kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.024975%
[libx264 @ 000001f24216e180] frame I:7     Avg QP:27.22  size:382635
[libx264 @ 000001f24216e180] frame P:276   Avg QP:29.78  size:217960
[libx264 @ 000001f24216e180] frame B:618   Avg QP:33.24  size: 62079
[libx264 @ 000001f24216e180] consecutive B-frames:  8.4%  0.2%  0.3% 91.0%
[libx264 @ 000001f24216e180] mb I  I16..4:  2.8% 85.3% 11.8%
[libx264 @ 000001f24216e180] mb P  I16..4:  1.2% 24.3%  3.5%  P16..4: 28.1% 25.0% 14.0%  0.0%  0.0%    skip: 3.8%
[libx264 @ 000001f24216e180] mb B  I16..4:  0.0%  0.8%  0.2%  B16..8: 44.2% 12.3%  4.1%  direct: 6.9%  skip:31.5%  L0:38.4% L1:37.0% BI:24.7%
[libx264 @ 000001f24216e180] 8x8 transform intra:83.3% inter:52.4%
[libx264 @ 000001f24216e180] coded y,uvDC,uvAC intra: 83.2% 82.7% 23.4% inter: 33.1% 24.3% 1.9%
[libx264 @ 000001f24216e180] i16 v,h,dc,p: 13% 49%  7% 31%
[libx264 @ 000001f24216e180] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 22% 14%  6%  8%  8% 11%  8% 10%
[libx264 @ 000001f24216e180] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 21% 11%  7% 11% 10% 11%  7%  7%
[libx264 @ 000001f24216e180] i8c dc,h,v,p: 55% 16% 22%  7%
[libx264 @ 000001f24216e180] Weighted P-Frames: Y:5.1% UV:2.9%
[libx264 @ 000001f24216e180] ref P L0: 60.6% 17.4% 18.7%  3.2%  0.1%
[libx264 @ 000001f24216e180] ref B L0: 96.2%  3.2%  0.5%
[libx264 @ 000001f24216e180] ref B L1: 99.0%  1.0%
[libx264 @ 000001f24216e180] kb/s:53913.39
[aac @ 000001f242170dc0] Qavg: 235.206

After running the ffmpeg command I'd like to save the following line

Lsize=   99089kB time=00:00:15.01 bitrate=54048.5kbits/s speed=   1x

to bash variable so that I can use this info later in my script. Is it possible?

I tried to do it with x=$(ffmpeg ...) syntax but the variable was empty afterwards

1
  • Yes it seems to be possible. Use a grep command to extract the line containing that text and store that line to a temp file. Then read that file and store the line in a bash variable. Commented Nov 19, 2021 at 9:45

1 Answer 1

1

Try something like this:

x=$(ffmpeg... 2>&1 | grep -Eo 'Lsize=.*$')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.