0

I have a folder with a lot of videos that need to be trimmed at the beginning and I also have a text file with the time where the video must start:

  • Video_001.mxf
  • Video_001.txt
  • Video_002.mxf
  • Video_002.txt
  • Video_003.mxf
  • Video_003.txt
  • etc.

I can do this for one file and it works:

$start = Get-Content Video_001.txt
ffmpeg -ss $start -i Video_001.mxf -c:v copy -c:a copy ./Trim_Video_001.mxf

As there are like 200 videos within the folder, I'm trying to do this:

$files = get-childitem *.mxf
$time = get-childitem *.txt

$time | foreach-object {
    $timename = $_.name
}

$files | foreach-object {
    $filename = $_.name
    $start = Get-Content $timename
    ffmpeg -ss $start -i $filename -c:v copy -c:a copy ./'Trim_'$filename
}

But it trims all the videos with the time in the last text file. How can I fix the code so the mxf file takes its corresponding txt file?

I'm not a programmer, I'm a video editor so I'm kind of newbie on this matter :)

Thanks!

1 Answer 1

0

If there is a text file for each video with the same name, something like this should work from the command line. First enter the path where the videos are from the command line and than use this command:

for %a in (*.mxf) do @for /f "delims=" %b in ('type "%~na.txt"') do ffmpeg -ss %b -i "%a" -c:v copy -c:a copy "Trim_%~a"
5
  • I tried and it doesn't work... It looks like -ss can't read the text file: "Invalid duration specification for ss: Video_001" That's why I'm trying to do it with PowerShell. Thanks!
    – Ninu
    Commented Nov 23, 2022 at 12:38
  • What exactlly is inside the text file? Commented Nov 23, 2022 at 12:41
  • The time in seconds... For instance: 19.84 for the first text file
    – Ninu
    Commented Nov 23, 2022 at 12:43
  • Can you try again with the edits I made... Commented Nov 23, 2022 at 12:50
  • Awesome!!!!! Works like a charm! Thank you so, so much!!! :)
    – Ninu
    Commented Nov 23, 2022 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .