ffmpeg: flushing output file every chunk

倾然丶 夕夏残阳落幕 提交于 2020-05-13 02:26:22

问题


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:


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


来源:https://stackoverflow.com/questions/50574086/ffmpeg-flushing-output-file-every-chunk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!