If I use ffprobe to output the duration of a video file with:

ffprobe -i input.mkv -show_entries format=duration -v quiet -of csv="p=0"

I will get something like


How can I get the output in second only without the decimals? I do not mind if ffmpeg or Mediainfo has a better function for this. I just need to get the output in seconds.

I am using CMD in Win10.

  • I am unaware of an option within ffprobe to do what you want, but you can truncate or round the duration value using your preferred shell or scripting language.
    – llogan
    Aug 20, 2017 at 17:27
  • With cmd you have to write your own rounding function. stackoverflow.com/questions/23116014/batch-rounding-a-number Have you considered using Powershell? Then it's just [math]::round(x). Note that you'll have to extract the number from ffprobe's output somehow.
    – stib
    Aug 21, 2017 at 5:22
  • [math]::round((ffprobe 'input.mkv' -show_entries format=duration -v quiet -of csv="p=0")) works in powershell. Note the double brackets.
    – stib
    Aug 22, 2017 at 8:46

1 Answer 1


Ended up using a batch file to export the timings to a text file and then turncate the value as a set variable.

ffprobe -i {filepath$} -show_entries format=duration -v quiet -of csv="p=0" >> duration.txt
setlocal enabledelayedexpansion
for /f "tokens=1,2,3,8 delims=\ " %%a in (duration.txt) do (
  for /f "tokens=1 delims=." %%i in ("%%a") do set _stime=%%i
  • You've gotta try powershell some time. You won't regret it.
    – stib
    Aug 23, 2017 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.