1

I am using ffmpeg to get some file durations Below is my code

$filename = '1aef53e6-92ac-4d28-89f8-4cce28fa0f58.mp4'
$duration = if ((ffmpeg -i $filename 2>&1 | Out-String) -match 'Duration:\s+([\d:.]+)') { $matches[1] }

Actual output would be like H :M :S : F 00:00:00.00

I need the output to be like 00:00:00:00 Between seconds and frame, there is a " . " full stop, I need it to be a " : "

any suggestions ?

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Use ffprobe, not ffmpeg. The output from ffmpeg is not meant to be machine parsed. See my answer in your previous question: [Can we declare a variable in ffmpeg ffprobe](https://stackoverflow.com/a/61214311/), then use the Windows equivalent of `sed` to change the `.` to `:`, (alternatively output the duration in seconds). – llogan Apr 16 '20 at 17:43
  • @llogan thank you very much – ilham zacky Apr 16 '20 at 18:01

1 Answers1

0

Add .Replace(".",":") after $matches[1]

$duration = if ((ffmpeg -i $filename 2>&1 | Out-String) -match 'Duration:\s+([\d:.]+)') { $matches[1].Replace(".",":") }

tom42
  • 36
  • 3