Linux – How do I get the Overall.RMS_level in real time from a UDP stream as an integer attached to the log file?


My goal is to monitor the audio of a UDP stream in real time to see if the audio is missing or too quiet. At the end, attach to a log file that contains the integer values ​​in decibels.

I've tried ffprobe and ffmpeg and the only valid output I could get is using ffmpeg.

ffmpeg gives the correct results, however the output file specified as "log.txt" is open for the output lock of ffmpeg and no data is written to it until you press Ctrl-C to end the process at the time when the output file is closed. I'm going to write a script to query the output file in real time as the file is being written, but only if I can figure out how to instruct ffmpeg to append "log.txt" for each sample taken.

Please provide an alternative method or a solution for this method.

Attempt 1 using ffmpeg

ffmpeg -i 'udp://@232.1.1.5:30120' -af astats=metadata=1:reset=1,ametadata=print:key=lavfi.astats.Overall.RMS_level:file=log.txt -f null -

Example of the contents of the "log.txt" file according to Ctrl-C

frame:0    pts:0       pts_time:0
lavfi.astats.Overall.RMS_level=-34.210103
frame:1    pts:1536    pts_time:0.032
lavfi.astats.Overall.RMS_level=-31.515254
frame:2    pts:3072    pts_time:0.064
lavfi.astats.Overall.RMS_level=-32.894668
frame:3    pts:4609    pts_time:0.0960208
lavfi.astats.Overall.RMS_level=-33.187652

Experiment 2 Using ffprobe

ffprobe -i 'udp://@232.1.1.5:30120',astats=metadata=1:reset=1 -show_entries frame=pkt_pts_time:frame_tags=lavfi.astats.Overall.RMS_level,lavfi.astats.1.RMS_level,lavfi.astats.2.RMS_level -of csv=p=0

This works and only shows the time code. Empty lines are shown in the console output for lavfi.astats.Overall.RMS. I think the problem has to do with lavfi?

Sample output to the console:

22508.110500
22507.361267


22508.143867
22507.393267


22508.177244
22507.425267

I tried to change the command line to specify -f-lavfi before typing -i, but it returned an error:

ffprobe -f lavfi  -i 'udp://@232.1.1.5:30120',astats=metadata=1:reset=1 -show_entries frame=pkt_pts_time:frame_tags=lavfi.astats.Overall.RMS_level,lavfi.astats.1.RMS_level,lavfi.astats.2.RMS_level -of csv=p=0

Returns:

[lavfi @ 0x55c69784f840] No such filter: 'udp://'
udp://@232.1.1.5:30120,astats=metadata=1:reset=1: Invalid argument