<p>I wrote the below code and the results.txt file that is created has a carriage return in it and it's for some reason as far as I can tell messing up reading in the data back into the BITRATE variable.  I think I'm basicaly getting the blank line in the variable rather than the value on the first line:</p>
<pre><code>@echo off
setlocal EnableExtensions DisableDelayedExpansion

pushd &quot;\\server\e$\files&quot;
for %%f in (*.mp4) do (
SET BITRATE=&quot;&quot;
z:\ffmpeg\bin\ffprobe.exe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 &quot;%%f&quot; &gt; results.txt
SET /p BITRATE=&lt;results.txt
set BITRATE=%%BITRATE:~0,4%%
echo 'ffmpeg -strict 2 -hwaccel auto -i %%~f -c:v hevc_nvenc -rc:v cbr -b:v %BITRATE% -rc-lookahead:v 32 -c:a copy -map 0 -f matroska &quot;%%~nf.mkv&quot;'
del results.txt
)
popd
</code></pre>
<p>Any ideas on how to get rid of the space either when making the call to ffprobe or after the file is created?  Output of BITRATE in the end is ~0,4 for it's value which isn't the case running this outside the script file for reference.</p>
<p>Edited content:</p>
<pre><code>@echo off
setlocal EnableExtensions EnableDelayedExpansion

pushd &quot;\\server\e$\files&quot;
del results.txt
for %%f in (*.mp4) do (
z:\ffmpeg\bin\ffprobe.exe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 &quot;%%f&quot; &gt; results.txt
set /pbitrate=&lt;results.txt 
Set /a bit=!bitrate!
echo 'z:\ffmpeg\bin\ffmpeg -strict 2 -hwaccel auto -i %%~f -c:v hevc_nvenc -rc:v cbr -b:v !bit! -rc-lookahead:v 32 -c:a copy -map 0 -f matroska &quot;%%~nf.mkv&quot;'
REM :~,4
SET BITRATE=&quot;&quot;
del results.txt
)
popd
</code></pre>

CC BY-SA 4.0
2020-10-22T10:40:26.187Z
My suggestion is to apply the -print_format json on ffprobe and use jq to do the extraction.
xer-rex
CC BY-SA 4.0
2020-10-22T20:38:15.360Z
OK think I did it with a combination of EnableDelaydExpansion and using ! variables. Since I don't think it will show up here well adding it back to the above.  So The above now works, but I can't figure for the life of me how to get with the !bit! variable and EnableDelayedExpasion how to get the bit value to be itself times 0.6.  Just seems to return nothing or fails so guessing I have some format issue or something with the call.
John
<ffmpeg><script>
Get rid of carriage return for batch calls to ffprobe
John
# Get rid of carriage return for batch calls to ffprobe

(Asked by: username_0 on 2020-10-22)

I wrote the below code and the results.txt file that is created has a carriage return in it and it's for some reason as far as I can tell messing up reading in the data back into the BITRATE variable.  I think I'm basicaly getting the blank line in the variable rather than the value on the first line:
@echo off
setlocal EnableExtensions DisableDelayedExpansion

pushd "\\server\e$\files"
for %%f in (*.mp4) do (
SET BITRATE=""
z:\ffmpeg\bin\ffprobe.exe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "%%f" > results.txt
SET /p BITRATE=
Any ideas on how to get rid of the space either when making the call to ffprobe or after the file is created?  Output of BITRATE in the end is ~0,4 for it's value which isn't the case running this outside the script file for reference.
Edited content:
@echo off
setlocal EnableExtensions EnableDelayedExpansion

pushd "\\server\e$\files"
del results.txt
for %%f in (*.mp4) do (
z:\ffmpeg\bin\ffprobe.exe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "%%f" > results.txt
set /pbitrate=

**Tags:** ffmpeg, script

> **Comments:**
> **username_1**: My suggestion is to apply the -print_format json on ffprobe and use jq to do the extraction.  
> **username_0**: OK think I did it with a combination of EnableDelaydExpansion and using ! variables. Since I don't think it will show up here well adding it back to the above.  So The above now works, but I can't figure for the life of me how to get with the !bit! variable and EnableDelayedExpasion how to get the bit value to be itself times 0.6.  Just seems to return nothing or fails so guessing I have some format issue or something with the call.  

---

## 0 answers

