Search code examples
powershellffmpegmp4box

How to use output file in another powershell command?


I'm using auto-editor first to cut out motionless parts, then Mp4Box to add my intro.

I can't figure out how to automatically use the output from auto-editor into Mp4Box.

This is what I have so far.

Get-ChildItem -Filter *.mp4 | ForEach -Process {mp4box -add c:\intro.mp4 -cat $_ -new $a($_.BaseName + '.mp4') -force-cat && del $_ && auto-editor $a --edit_based_on motion --motion_threshold 0.000001% --no_open}

I tried adding $a to make the output into a variable but that doesn't work. I have the script reversed for testing purposes as Mp4Box is a lot faster than auto-editor.


Solution

  • You have to create the variable $a on a separate statement, before calling any of the commands that uses it.

    Get-ChildItem -Filter *.mp4 | ForEach {
         $a = $_.BaseName + '.mp4'
         mp4box -add c:\intro.mp4 -cat $_ -new $a -force-cat && 
         del $_ &&
         auto-editor $a --edit_based_on motion --motion_threshold 0.000001% --no_open
    }
    

    I've also added some line breaks to make the code more readable.