1

I am trying to capture output from ffmpeg and storing that in memory, deciding at a later stage if I want to write it to disk.

Is it possible to analyze the output of ffmpeg before writing it onto the HDD?

Since I do not really know how to approach the thing, I cannot yet provide a code example.

EDIT: Yes, I am trying to write small chunks of the captured avi/mp4 to RAM and analyze them before writing to disc.

tarrasch
  • 2,630
  • 8
  • 37
  • 61

3 Answers3

2

to redirect the output of ffmpeg to be the input of your process use the following:

ffmpeg -i inputfile [ ... options ... ] 2>&1 | your-process 

where your process will gets the data to stdin.

example:

ffmpeg -y -i inputfile -acodec copy -vcodec copy outputfile 2>&1 | cat
EladG
  • 794
  • 9
  • 21
  • You can also create the ffmpeg process from python and consume its output directly. I've had success with this approach the other way around, to feed ffmpeg with frames to compress from memory. Which worked just fine. – rotoglup Jun 14 '12 at 06:39
  • @rotoglup right, but I wonder how or even if such technic can work with complex encoding such as x264 where most of the frames are p and b frames... if it does, this is probably a better way! – EladG Jun 14 '12 at 06:52
  • Cool, if it doesn't work (it should, but you know how it is...), use @rotoglup advice. – EladG Jun 17 '12 at 13:20
0

If you mean capturing the video output I think not, because it would require alot of ram, better use a temporary file and keep track of it.

If you mean capturing information from the outputted file try to use ffmpeg -i /some/file.avi without any other arguments, this will dump a lot of information about the video file.

Example:

dorkbot:~ lamer1$ ffmpeg -i ~/Downloads/Dead\ Gerhardsens\ -\ They\ dont\ know.mp4 
ffmpeg version 0.7.8, Copyright (c) 2000-2011 the FFmpeg developers
  built on Nov 24 2011 14:31:00 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
  configuration: --prefix=/opt/local --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libopenjpeg --enable-libxvid --enable-libx264 --enable-libvpx --enable-libspeex --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/gcc-4.2 --arch=x86_64 --enable-yasm
  libavutil    50. 43. 0 / 50. 43. 0
  libavcodec   52.123. 0 / 52.123. 0
  libavformat  52.111. 0 / 52.111. 0
  libavdevice  52.  5. 0 / 52.  5. 0
  libavfilter   1. 80. 0 /  1. 80. 0
  libswscale    0. 14. 1 /  0. 14. 1
  libpostproc  51.  2. 0 / 51.  2. 0

Seems stream 1 codec frame rate differs from container frame rate: 50000.00 (50000/1) -> 25.00 (25/1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/lamer1/Downloads/Dead Gerhardsens - They dont know.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isomavc1mp42
    creation_time   : 2008-07-01 00:53:26
  Duration: 00:01:37.76, start: 0.000000, bitrate: 303 kb/s
    Stream #0.0(und): Audio: aac, 44100 Hz, stereo, s16, 125 kb/s
    Metadata:
      creation_time   : 2008-07-01 00:53:26
    Stream #0.1(und): Video: h264 (Baseline), yuv420p, 384x288 [PAR 1:1 DAR 4:3], 175 kb/s, 25 fps, 25 tbr, 25k tbn, 50k tbc
    Metadata:
      creation_time   : 2008-07-01 00:53:26
At least one output file must be specified

Its not a perfect solution but you can parse that output.

Karl-Bjørnar Øie
  • 5,554
  • 1
  • 24
  • 30
0

You could use the Pyffmpeg library to call directly ffmpeg from within python.

jkrcma
  • 1,180
  • 9
  • 14
Nicolas Barbey
  • 6,639
  • 4
  • 28
  • 34