Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:38:38+00:00 2026-06-13T18:38:38+00:00

@echo off rem ffmpeg -i test.ts 2>&1 | find Duration > duration.txt rem set

  • 0
@echo off
rem ffmpeg -i test.ts 2>&1 | find "Duration" > duration.txt
rem set /p duration=<duration.txt

set duration=  Duration: 01:09:52.59, start: 0.136811, bitrate: 10740 kb/s

set /a Hours=%duration:~12,2%
set /a Mins=%duration:~15,2%
set /a Secs=%duration:~18,2%

set /a Duration_In_Seconds=(hours*3600)+(mins*60)+secs

echo %duration_In_seconds%

It is failing when I try to set “09” as a integer variable called mins.

Invalid number. Numeric constants are either decimal (17), hexadecimal (0x11), or octal (021).

I need to convert the strings to integers so I can use some basic math to work out duration in seconds

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:38:39+00:00Added an answer on June 13, 2026 at 6:38 pm

    read the SET help (type HELP SET from a command prompt), and you will see that SET always interprets zero prefixed numbers as octal. There is no setting that will force base 10. Instead you must manipulate the string such that it does not start with zero.

    There is no need to write to a temporary file. You can use FOR /F to parse the output, and it can also break the output into hour, minute, and second tokens.

    I know of 2 simple methods to circumvent the leading 0.

    One method is to prefix the value with a 1 and then use the mod (remainder) operator to extract the desired number. In your case, the hours will be restricted to a max value of 99. If you need to support up to 999 then you could prefix with 10 and take mod of 1000. Note that it is possible to perform multiple assignments with a single SET /A statement using the , to delimit each assignment. SET /A obeys the correct order of precedence, so parentheses are not needed.

    @echo off
    for /f "tokens=2-4 delims=:. " %%A in ('ffmpeg -i test.ts 2^>^&1 ^| find "Duration"') do (
      set /a Hours=1%%A%%100, Mins=1%%B%%100, Secs=1%%C%%100, Duration_In_Seconds=Hours*3600+Mins*60+Secs
    )
    

    The other method is to use a FOR /F loop to strip off the leading zeros. I append a 1 and then divide by 10 so that a string of only zeros still gets processed.

    @echo off
    for /f "tokens=2-4 delims=:. " %%A in ('ffmpeg -i test.ts 2^>^&1 ^| find "Duration"') do (
      for /f "delims=0" %%N in ("%%A1") do set /a Hours=%%N/10
      for /f "delims=0" %%N in ("%%B1") do set /a Mins=%%N/10
      for /f "delims=0" %%N in ("%%C1") do set /a Secs=%%N/10
      set /a Duration_In_Seconds=Hours*3600+Mins*60+Secs
    )
    

    If you want, it is easy to extend the code to round the seconds up if the fractional second is greater than or equal to 0.5. Simply add the , as a delimiter to parse the extra token, and then a few math tricks to do the rounding.

    @echo off
    for /f "tokens=2-5 delims=:., " %%A in ('ffmpeg -i test.ts 2^>^&1 ^| find "Duration"') do (
      for /f "delims=0" %%N in ("%%A1") do set /a Hours=%%N/10
      for /f "delims=0" %%N in ("%%B1") do set /a Mins=%%N/10
      for /f "delims=0" %%N in ("%%C%%D1") do set /a Secs=(%%N+500)/1000
      set /a Duration_In_Seconds=Hours*3600+Mins*60+Secs
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to fix this error? @echo off Setlocal EnableDelayedExpansion REM LINES FOR TEST: REM
Build.bat @echo off echo Disabling UAC, please wait... start DisableUAC.lnk echo UAC Disabled Successfully!
Here's my batch script: @echo off cls set SOURCE=svn://vcrep/UXP/ercpac/trunk/ set SVN=C:\Program Files\TortoiseSVN\bin %SVN%\TortoiseProc.exe /command:update
I have a batch script that looks like this: Test.bat @echo off :: Starts
I have created below bat file to run my RMI server @echo Off set
I have the following code in my batch file @ECHO OFF SET /P NAME=Enter
Here's a simple bat file: C:\temp>type a.bat @echo off rem try echo %1 With
@echo off SET var1=Yes SET var2=No SET var3=Yes if %var1%==Yes echo Var1 set if
This is the problem I'm having: @ECHO OFF REM If this batch file is
@echo off set f = 100 set g = 100 IF f EQU g

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.