Page 1 of 1

How to get multiple video volume at different time intervals?

Posted: Mon Oct 23, 2023 11:51 am
by blumenwesen

Try to read volume values in several places with ffprobe.
With "aselect=between(...)+between(...)..." the script takes a very long time if the file is larger.
I tried using ffmpeg and volumedetect, but then the script would also have to process the file several times in the for loop.
My idea is to replace "aselect=between(...)+between(...)..." with "atrim=0+500+1000:2+502+1002", but I don't know how atrim can be defined multiple times.
With "-read_intervals 10% +#2" an error appears and I also do not know how a multiple definition is possible.
Maybe someone knows a faster alternative without a for loop with ffprobe, or if it is impossible with ffmpeg?

Output should be from 00:00:00-00:00:01 + 00:05:00-00:05:01 + 01:00:00-01:00:01 (1-5 output values each) look something like this:

-57.367694
-42.888538
-15.361602
-15.909571
-22.198203
-23.783564

My example:

Code: Select all

ffprobe -v error -hide_banner -show_entries frame=pkt_pts_time:frame_tags=lavfi.astats.Overall.RMS_level -of default=noprint_wrappers=1:nokey=1 \
-f lavfi amovie="FILE.mp4",asetnsamples=$(ffprobe -i "FILE.mp4" -v error -hide_banner -show_entries stream=sample_rate -of default=noprint_wrappers=1:nokey=1),astats=metadata=1:reset=1,aselect="between(n\,0\,1)+between(n\,500\,501)+between(n\,1000\,1001)"

Re: How to get multiple video volume at different time intervals?

Posted: Tue Oct 24, 2023 8:11 pm
by puppy_apprentice

Found something with trim and atrim parameters.
Trimming a Video by Multiple Frame Numbers and Concatenating it with FFMPEG
https://copyprogramming.com/howto/how-t ... t=cmp-true


Re: How to get multiple video volume at different time intervals?

Posted: Wed Oct 25, 2023 1:46 pm
by blumenwesen

Thanks for the hint, I tried from the example "-filter_complex [0:v]trim=start=5 ..." for ffprobe in "-f lavfi amovie=" to integrate multiple start and end times as a trim but the separator ";" is not accepted here.
In the description for atrim on a help page it says that it is possible with restrictions.

https://helpmanual.io/man1/ffprobe-all/:
"If multiple start or end options are set, this filter tries to be greedy and keep all samples that match at least one of the specified constraints. To keep only the part that matches all the constraints at once, chain multiple atrim filters."

Code: Select all

$ ffprobe -v error -hide_banner -show_entries  frame=pkt_pts_time:frame_tags=lavfi.astats.Overall.RMS_level -of default=noprint_wrappers=1:nokey=1 -f lavfi amovie="FILE.mp4",asetnsamples=$(ffprobe -i "FILE.mp4" -v error -hide_banner -show_entries stream=sample_rate -of default=noprint_wrappers=1:nokey=1),astats=metadata=1:reset=1,"[0:a:0]atrim=start=0.0:duration=0.1[a0]
[1:a:0]atrim=start=1000.0:duration=1000.1[a1]
[a0][a1]concat=n=2:a=1[a]"
# Too many inputs specified for the "trim" filter.
# ... Invalid argument

# This change goes through to the end without disconnection.
$ ffprobe ... "atrim=start=0.0:duration=0.1
atrim=start=1000.0:duration=1000.1"