0

Using Windows Batch scripting, I want to get the max_volume value (-2.9 in the following example) from a ffmpeg output written to a log file:

[Parsed_volumedetect_0 @ 0000000005428b20] n_samples: 13406208

[Parsed_volumedetect_0 @ 0000000005428b20] mean_volume: -20.4 dB

[Parsed_volumedetect_0 @ 0000000005428b20] max_volume: -2.9 dB

[Parsed_volumedetect_0 @ 0000000005428b20] histogram_2db: 7

[Parsed_volumedetect_0 @ 0000000005428b20] histogram_3db: 181

[Parsed_volumedetect_0 @ 0000000005428b20] histogram_4db: 963

[Parsed_volumedetect_0 @ 0000000005428b20] histogram_5db: 2774

[Parsed_volumedetect_0 @ 0000000005428b20] histogram_6db: 6614

[Parsed_volumedetect_0 @ 0000000005428b20] histogram_7db: 14743

Once I know that value I intend to use it in some calculations.

Thanks a lot in advance.

Mapg

2 Answers 2

2
for /f "tokens=5" %a in ('find /i "max_volume" ffmpeg.log') do set max_volume=%a

echo %max_volume%

it case-insensitively searches the file, determines the line, and then gets its 5th element (token) delimited by whitespace by default (absent delims option) saving the value in the max_volume variable

2
  • +1, but you forgot to double your percents for use in a batch script.
    – dbenham
    Nov 24, 2014 at 4:28
  • haha, i thought of it but felt it's getting ugly to repeat it under ps on my posts every time i answer about using the batch for loop. besides the question wasn't explicitly about executing the batch instructions through script files, and yeah, i think some kind of signature on posts could implement it notifying questioners about common traits, best practices etc :-)
    – user373230
    Nov 24, 2014 at 5:40
0

You'll need to split the string.

Check this link to see how to do it right: https://stackoverflow.com/questions/1707058/how-to-split-a-string-in-a-windows-batch-file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .