ffmpeg:每块刷新输出文件 [英] ffmpeg: flushing output file every chunk
问题描述
我正在使用ffmpeg实时生成正弦音调,持续10秒钟.不幸的是,ffmpeg似乎很少每隔几秒钟刷新一次输出文件.我希望它每2048个字节刷新一次(= 2个字节的样本宽度* 1024个样本,我的自定义块大小).
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).
以下脚本的输出:
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)
看起来像:
[...]
78
78
78
262222
262222
262222
[...]
使用#ffmpeg IRC的用户建议使用
A user on the #ffmpeg IRC proposed using
ffmpeg -re -f lavfi -i "sine=frequency=1000:duration=10" -f wav pipe: > test.wav
有效.但是,仅使用ffmpeg就能实现吗?
which works. But can this be achieved just using ffmpeg?
推荐答案
为了输出到文件,ffmpeg等待写入之前填充256 KiB的缓冲区.
For output to a file, ffmpeg waits to fill a buffer of 256 KiB before a write.
您可以使用flush_packets
禁用该行为.
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
这篇关于ffmpeg:每块刷新输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!