Reduce ffmpeg buffer size

0

1

I'm testing transcoding from rtmp to hls. As I see, ffmpeg seems to flush every 256k to file. I tried several options like bufsize, flush_packets but it didn't work. I want to flush frame video as soon as possible.

My command is:

/usr/bin/ffmpeg -i rtmp://localhost:1935/live/test -y -acodec copy -vcodec copy -hls_time 2 -hls_list_size 8 -pix_fmt yuv420p -keyint_min 60 -flush_packets 1 -hls_segment_filename /tmp/test/%3d.ts -hls_flags delete_segments /tmp/test/_tmp.m3u8

I use ffmpeg version 3.4.6.

Thanks.

newvalue

Posted 2019-07-05T13:39:34.800

Reputation: 1

Share the commands you tried. – Gyan – 2019-07-05T15:17:41.130

I updated my question. – newvalue – 2019-07-06T01:03:28.720

Add -avioflags +direct -hls_ts_options fflags=+flush_packets and check. – Gyan – 2019-07-06T05:01:57.990

It doesn't work. To eliminate other issues related to rtmp, I try to test to transcode from file:

/usr/local/bin/ffmpeg -re -i ./sample.mp4 -y -hls_time 2 -hls_list_size 8 -pix_fmt yuv420p -keyint_min 60  -avioflags +direct -hls_ts_options fflags=+flush_packets -hls_segment_filename /tmp/lhls1/test/%3d.ts -f hls /tmp/lhls1/test/_tmp.m3u8
 – newvalue  – 2019-07-06T06:01:13.373

I monitor the changing in the directory, and here is the log:

/tmp/lhls1/test/000.ts size:  786432
/tmp/lhls1/test/000.ts size:  884164
/tmp/lhls1/test/001.ts size:  0
/tmp/lhls1/test/001.ts size:  75200
/tmp/lhls1/test/002.ts size:  0
/tmp/lhls1/test/002.ts size:  262144
/tmp/lhls1/test/002.ts size:  524288
/tmp/lhls1/test/002.ts size:  786432
/tmp/lhls1/test/002.ts size:  936428
/tmp/lhls1/test/003.ts size:  0
/tmp/lhls1/test/003.ts size:  262144
/tmp/lhls1/test/003.ts size:  524288
/tmp/lhls1/test/003.ts size:  786432
/tmp/lhls1/test/003.ts size:  1048576
 – newvalue  – 2019-07-06T06:02:17.250

After diving in ffmpeg codebase, I found that ffmpeg change buffer size to 256k when output to file. I tried to remove this code and it worked well.

https://github.com/FFmpeg/FFmpeg/blob/3e10223385b83358f013cbf6ba069f15fedc731a/libavformat/file.c#L238

– newvalue – 2019-07-06T08:18:37.673

Yes, but that requires code maintenance. flush_packets overrides that but the hls muxer isn't passing that to child muxers, based on your results. Add an option to the hls muxer to adjust the AVIOContext of the child muxers to enable flush_packets – Gyan – 2019-07-06T10:57:25.177

No answers