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.