10

I'm using ffmpeg to generate a sine tone in real time for 10 seconds. Unfortunately, ffmpeg seems to flush the output file only rarely, every few seconds. I'd like it to flush every 2048 bytes (=2bytes sample width*1024 samples, my custom chunk size).

The output of the following script:

import os
import time
import subprocess

cmd = 'ffmpeg -y -re -f lavfi -i "sine=frequency=440:duration=10" -blocksize 2048 test.wav'    

subprocess.Popen(cmd, shell=True)

time.sleep(0.1)
while True:
    print(os.path.getsize("test.wav"))
    time.sleep(0.1)

looks like:

[...]
78
78
78
262222
262222
262222
[...]

A user on the #ffmpeg IRC proposed using

ffmpeg -re -f lavfi -i "sine=frequency=1000:duration=10" -f wav pipe: > test.wav

which works. But can this be achieved just using ffmpeg?

1 Answer 1

18

For output to a file, ffmpeg waits to fill a buffer of 256 KiB before a write.

You can disable that behaviour, using flush_packets.

ffmpeg -y -re -f lavfi -i "sine=f=440:d=10" -blocksize 2048 -flush_packets 1 test.wav
Sign up to request clarification or add additional context in comments.

2 Comments

how can i detect is this working or no ? i put -blocksize 32 -flush_packets 1 but it output is 600 byte data after 3-4 second! i use libopencore_amrnb codec and need to get data every second.
libopencore_amrnb might be doing some internal buffering?

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.