6

I'm using ffmpeg to convert chunks of media in webm format to a wav file in a "continuous stream" mode.

Using a python wrapper, I'm feeding ffmpeg a webm chunk (let's say 1 chunk each second) and ffmpeg continuously writes the output wav (then, in a separate thread I'm reading this wav file and pass the new data forward).

This works well most of the time, but some times, I get this weird behavior:

  • after some chunks are processed and output to the wav file, ffmpeg stops writing to the output file (the file stops growing but ffmpeg keeps getting the webm chunks)
  • this can go on like this for several minutes, and then ffmpeg resumes writing to the wav file
  • eventually, the complete wav file is written successfully, but this causes huge delays in the streaming process.

Looking at CPU and memory usage, this doesn't seem to be the issue.

Any ideas as to what could cause ffmpeg to stop streaming for several minutes and then resume? This can happen after 30 seconds, after 3 minutes or after an hour of streaming media chunks and the time it takes ffmpeg to resume also varies.

In my python code, I'm basically opening a subprocess.Popen() process and write to the process' stdin to feed ffmpeg the media chunks.

So my code looks something like:

ffmpeg_proc = subprocess.Popen('ffmpeg -y -f webm -i - -ac 1 -ar 16000  -f wav /tmp/out.wav', shell=True, stdin=subprocess.PIPE)

for chunk in chunks:
    ffmpeg_proc.stdin.write(chunk)

I'm using python 3.6 and ffmpeg version 2.8.14-0ubuntu0.16.04.1

Thanks in advance!

EliA
  • 61
  • 3
  • I know this was a long time ago, but did you find a solution to this? – Alessandro Valentino May 12 '22 at 12:23
  • @AlessandroValentino this was indeed a long time ago, but IIRC, the issue was that we would some times feed `ffmpeg` with webm chunks in the wrong order (e.g. 1, 2, 3, 5, 4, 6, 7...) or one of the chunks was simply missing (e.g. 1, 2, 3, 5, 6, 7...). – EliA May 15 '22 at 06:06

0 Answers0