0

I created a batch script for windows that I use for mux mkv files. When launch this command:

ffprobe -v 0 -select_streams s -show_entries stream=index:disposition=default -of compact=nk=0 file.mkv | findstr disposition:default=1

Output is:

stream|index=3|disposition:default=1

How can filter and print only number "3" and put it in a variable?

  • There are several approaches to achieve this. Can you point out which parts of your output are fixed and which are subject to change? Can you please specify if you just want to extract the single digit or is it desired to grab a number like "33" as well? – Antares May 01 '20 at 06:20

2 Answers2

0

Batchfile approach

You need to execute your command inside a for statement inside a batch file to be able to capture the output lines and process them further. Check for /? on the command line and the part with for /f and learn about "usebackq".
The key point is, that you need to escape several special characters from your command, if it is executed in the for statement and not on the command line prompt directly.
Try getting this piece to work and post your solution as update to your answer if you like. Then we can get to the second part of extracting the number.

Antares
  • 605
  • 3
  • 14
  • Ok, when launch batch all "=" inside ffprobe command disappear. Command: `FOR /F "delims=, tokens=1" %%# IN ('ffprobe -v 0 -select_streams s -show_entries stream=index:disposition=forced:stream_tags=language -of csv=nk=1:p=0 file.mkv ^| FINDSTR /C:"1,ita"') DO SET subid=%%#` Output: `FOR /F "tokens=1 delims=," %# IN ('bin\ffprobe.exe -v 0 -select_streams s -show_entries stream index:disposition forced:stream_tags language -of csv nk 1:p 0 file.mkv | FINDSTR /c:"1,ita"') DO SET subid=%#` – Michele Del Popolo May 01 '20 at 17:42
  • 1
    Please update your answer with the new findings/changes and present your code and a description what you changed or which problems occured in a formatted and easy to read manner :) Then delete this comment here. --What do you mean when saying "disappear"... where do you observe that they are missing? – Antares May 02 '20 at 00:48
0

I submit a new command that simplify output:

ffprobe -v 0 -select_streams s -show_entries stream=index:disposition=forced:stream_tags=language -of csv=nk=1:p=0 file.mkv | FINDSTR /C:"1,ita"

Output is:

3,1,ita

"3" is track id, "1" is forced flag, "ita" is track language. To create a variable that contains only the track id (e.g. 3) to be inserted in a mkvmerge command, I ran this command:

FOR /F "delims=, tokens=1" %%# IN ('ffprobe -v 0 -select_streams s -show_entries stream=index:disposition=forced:stream_tags=language -of csv=nk=1:p=0 file.mkv ^| FINDSTR /C:"1,ita"') DO SET subid=%%#

But nothing happens! Mkvmerge report this error: Error: Invalid track ID or language code in '-s '.

I don't really know where the mistake is!

  • That is merely a question update, not an answer... please merge it with your initial problem description (e.g. append an "Update:" section) and/or get rid of old parts of your question which are not valid anymore (or at least comment on which is not wanted anymore). It seems you changed "everything" now :) But still you did not tell which part of the outputs are subject to change or if you like to have all of "3,1,ita" in one variable. I need information about that to point out a solution. – Antares May 02 '20 at 00:58
  • There are some syntax mistakes in your code. `%%#` is not a valid variable. You need to pick a single letter as name. Try `%%a` instead. Also the first step is, that you do an `echo %%a` inside of your for loop and nothing else. If you see the desired output printed, you can begin changing the inside of the loop and try to get your substring from `%%a`. – Antares May 02 '20 at 01:00