1

I have this as-is in a PS script; it is a call to the program, Ffmpeg, with switches, variable input/output file names and redirected error output to a file:

C:\Users\User\Documents\Computer\FfMPEG\bin\ffmpeg -loglevel error -hide_banner -nostats -y -itsoffset 0.2 -i $videofile.Name -i $videofile.Name -map 0:0 -map 1:1 -vf yadif -c:v:0 libx264 -ar 44100 -scodec copy $newmp4filename 2> C:\Users\User\Documents\Computer\FfMPEG\ffreport.txt

The error output begins with:

At C:\Users\User\Documents\Computer\FfMPEG\TStoMP4.ps1:120 char:1
+ C:\Users\User\Documents\Computer\FfMPEG\bin\ffmpeg -loglevel error -h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ([mpeg2video @ 0...dimensions 0x0.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError 

but then the command continues and its normal processing error output continues. Note the Ffmpeg conversion error showing up in the PowerShell "Not Specified" error. There are not problems with the variables or any other part if the script.

It works (surprisingly), but I am not sure it should be implemented as so. I have tried using methods Start-Process, Invoke-Expression, <referenced line as above> | Invoke-Expression and & but ran into problems using these cmdlets. The error output seems irregular/mixed, and I can't tell what's going on.

This is the function the line is within:

function StarTrek {
# Star Trek TS to MP4 conversion and SRT extraction...
#
$videofile = Get-ChildItem Star*.ts
$newmp4filename = [io.path]::ChangeExtension($videofile.Name, '.mp4')
$newsrtfilename = [io.path]::ChangeExtension($videofile.Name, '.srt')
Stop-Transcript
Start-Transcript -Path C:\Users\User\Videos\StarTrek.log -Append
Write-Host "`nInput:" $videofile.Name # Working .ts file name
# ---INPUT FILE NAME CANNOT HAVE ANY SPACES!!!!!
#
# **** FFMPEG MP4 CONVERSION WITH OFFSET AUDIO ****
C:\Users\User\Documents\Computer\FfMPEG\bin\ffmpeg -loglevel error -hide_banner -nostats -y -itsoffset 0.2 -i $videofile.Name -i $videofile.Name -map 0:0 -map 1:1 -vf yadif -c:v:0 libx264 -ar 44100 -scodec copy $newmp4filename 2> C:\Users\User\Documents\Computer\FfMPEG\ffreport.txt
#
Write-Host "-loglevel error -hide_banner -nostats"
Write-Host "`nOutput: $newmp4filename" # Name from this function
#
# **** FFMPEG SRT EXTRACTION (offset time not needed) ****
Write-Host "`nNext below is SRT extraction..."
C:\Users\User\Documents\Computer\FfMPEG\bin\ffmpeg -loglevel error -hide_banner -nostats -y -f lavfi -i movie=$newmp4filename[out0+subcc] -vn -an -codec:s subrip -map_metadata -1 $newsrtfilename
#
Write-Host "-loglevel error -hide_banner -nostats"
Write-Host "SRT output: $newsrtfilename" # Name from this function
move star*.ts C:\Users\User\Videos\z_Hold_Trash
#
Powershell.exe -ExecutionPolicy Unrestricted -command ". C:\Users\User\Documents\Computer\FfMPEG\StarTrek_scrape_rename.ps1"
# **Moving of st*.mp4 and st*.srt happens with weekly batch file (separate task)**
Write-Host "`nExiting StarTrek function"
Stop-Transcript
#Write-Host "Exiting Task..."
powercfg /setactive 5972a947-7da1-45c0-8a89-0b0cc0cfa3be # powercfg My Custom Plan
#stop-process -name sendscroll; $ss=0 # Turn off SendScroll
&C:\Users\User\Documents\Computer\FfMPEG\SendScrollStop.exe; $ss=0
&C:\Users\User\Documents\Computer\FfMPEG\ScrollLock.exe off
#taskkill /IM sendscroll.exe /F; $ss=0
EXIT
#pause
}

The above referenced line was used in CMD, and I näively did the same in PowerShell. Correction: it was used without the 2> redirect. Since using 2> redirect, that is when I believe the Start-Process, Invoke-Expression, <referenced line as above> | Invoke-Expression and & methods stopped working.

How/which method should I best use to implement the command?

Win10Pro, PS v.5

BTW, now noticing, it might be missing .exe on Ffmeg. Double quotations were tried/removed at the time too.

8
  • I'm not sure how I can be any more clear with the question. These boards seem to be getting ridiculously picky.
    – LouF
    Commented Oct 28, 2022 at 6:09
  • The problem is, we don't understand your question. Its impossible to help you if we don't understand it. What is it that you want to achieve, what error or symptom do you get and why do you think this is what you need to do? If it works, then it is okay, right!? Also, it will help if you post your entire script. Given that you are using variables, you cannot be using a one-liner as a script.
    – LPChip
    Commented Oct 28, 2022 at 6:32
  • I've added the initial PS error message and more explicitly asked how to correctly implement the command
    – LouF
    Commented Oct 28, 2022 at 6:52
  • The rest of the script is irrelevant to the thrown error and involves 4 files.
    – LouF
    Commented Oct 28, 2022 at 7:44
  • The function the line appears in is included now.
    – LouF
    Commented Oct 28, 2022 at 7:51

2 Answers 2

2

I used:

Start-Process -NoNewWindow -Wait "C:\Users\User\Documents\Computer\FfMPEG\bin\ffmpeg.exe" -ArgumentList "-loglevel error -hide_banner -nostats -y -itsoffset 0.2 -i $videofilename -i $videofilename -map 0:0 -map 1:1 -vf yadif -c:v:0 libx264 -ar 44100 -scodec copy $newmp4filename" -RedirectStandardError "C:\Users\User\Documents\Computer\FfMPEG\ffreport.txt"

Note that in my use, -NoNewWindow and -Wait was necessary. Also, the input variable could not use .Name operation on the object.

1

The command you are using is the following command:

C:\Users\User\Documents\Computer\FfMPEG\bin\ffmpeg.exe

The above is a way you can use in powershell, so your command becomes:

C:\Users\User\Documents\Computer\FfMPEG\bin\ffmpeg.exe -loglevel error -hide_banner -nostats -y -itsoffset 0.2 -i $videofile.Name -i $videofile.Name -map 0:0 -map 1:1 -vf yadif -c:v:0 libx264 -ar 44100 -scodec copy $newmp4filename 2> C:\Users\User\Documents\Computer\FfMPEG\ffreport.txt

You can of course also do this:

cd C:\Users\User\Documents\Computer\FfMPEG\bin\

.\ffmpeg.exe -loglevel error -hide_banner -nostats -y -itsoffset 0.2 -i $videofile.Name -i $videofile.Name -map 0:0 -map 1:1 -vf yadif -c:v:0 libx264 -ar 44100 -scodec copy $newmp4filename 2> ..\ffreport.txt

or even this if you want to make it more readable:

cd C:\Users\User\Documents\Computer\FfMPEG\bin\

.\ffmpeg.exe -loglevel error `
             -hide_banner `
             -nostats `
             -y `
             -itsoffset 0.2 `
             -i $videofile.Name `
             -i $videofile.Name `
             -map 0:0 `
             -map 1:1 `
             -vf yadif `
             -c:v:0 libx264 `
             -ar 44100 `
             -scodec copy $newmp4filename `
             2> ..\ffreport.txt

notice the use of the linebreak ` char, required to tell powershell the command continues on the next row.

4
  • Thankyou. I didn't think that is acceptable without operators. Following, why is error handling getting screwed up? Regular command line seems to be getting the output of the error stream. This is why I first inquired about the command call.
    – LouF
    Commented Oct 29, 2022 at 12:17
  • I do not have anything here that I can test with, but the documentation says that it should be correct. See: learn.microsoft.com/en-us/powershell/module/…
    – LPChip
    Commented Oct 29, 2022 at 13:27
  • I provided my own answer. The error message is no longer happening. Thanks for your attempt; examples will be used for future reference.
    – LouF
    Commented Oct 30, 2022 at 13:30
  • Glad I could help. I've voted up your answer. Feel free to return the curtasy and vote up mine as well as a thank you. :)
    – LPChip
    Commented Oct 30, 2022 at 14:26

You must log in to answer this question.

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