'PowerShell and ffmpeg or similar commands

I want to loop through all the files or in this specific case all the .mp4 files.

For each of the mp4 files I want to run the ffmpeg command.

something like this...

.\ffmpeg.exe -i  $file -c copy -map 0:v? -map 0:a? $filenew

My problem is this... the $filenew doesn't seem to have any value, and ffmpeg needs a new file name. It seems to read in $file ok... but hates it when I try to give it the output file.. Something easy I am sure and I am just missing it..

Here is what I have so far.. not matter what I do.. $filenew is blank.. so it trys to reuse the $file name

foreach ($file in $files){
  .\ffmpeg.exe -i  $file -c copy -map 0:v? -map 0:a? $filenew
}

Output:

  Stream #0:5[0x0]: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 720x1080 [SAR 1:1 DAR 2:3], 90k tbr, 90k tbn (attached pic)
  Stream #0:6[0x6](und): Data: bin_data (text / 0x74786574)
    Metadata:
      creation_time   : 2017-06-07T00:38:01.000000Z
File 'American Gangster.mp4' already exists. Overwrite? [y/N] y


Solution 1:[1]

I got it working with a new name.. but then I decided to just write the file to a new dir..

Here is the code I used..

'dir *.mp4 | foreach-object { $newname = (get-item $_ ).name ; .\ffmpeg.exe -i "$_" -c copy -map 0:v? -map 0:a? ./fixed/$newname}'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 regularguy