In PowerShell, i want declare a variable to ffmpeg:
## DOSSIERS DE TRAVAIL
$Ingest = "C:\INGEST\" ## DOSSIER WATCHE
$outPath = "C:\TRANSCODE\" ## DOSSIER DE DESTINATION, A definir
$TEMP = "C:\temp\" ## dossier temporaire de récupération des essences (de-wrapp fichier ingesté)
$MAPaudio = ""
$Filesaudio = ""
for ($i = 1; $i -le $nombreAudios; $i ) {
$TEMP_AUDIO = $TEMP "audio" $i ".wav"
##Extraction de l'audio et conversion en 48000hz (Obligatoire pour le MXF)
$MAPaudio = " -map " $i ":a "
$Filesaudio = " -i " $TEMP_AUDIO
}
$TEMP_VIDEO = $TEMP "video.mxf"
write-host $MAPaudio
write-host $Filesaudio
##Encapsulage de la vidéo
$result = " -i $TEMP_VIDEO $Filesaudio -c copy -map 0:v:0 $MAPaudio -y c:\transcode\test.mxf".tostring()
ffmpeg "$result"
I have an error:
Output #0, mxf, to ' -i C:\temp\video.mxf -i C:\temp\audio1.wav -i C:\temp\audio2.wav -i C:\temp\audio3.wav -i C:\temp\audio4.wav -c copy -map 0:v:0 -map 1:a -map 2:a -map 3:a -map 4:a -y c:\transcode\test.mxf':
Output file #0 does not contain any stream
Yet, if i give the variable to ffmpeg without powershell, it works !!! I don't understand why, ffmpeg doesn't want my variable.
CodePudding user response:
You are effectively calling ffmpeg
like this:
ffmpeg " -i $TEMP_VIDEO $Filesaudio -c copy -map 0:v:0 $MAPaudio -y c:\transcode\test.mxf"
Note the double quotes that are automatically added by PowerShell, when you pass a variable that contains whitespace, as an argument to a native command!
As a result, ffmpeg
sees only a single argument, that it doesn't understand.
If you want to store multiple arguments in a variable, it has to be an array instead of a single string. PowerShell unrolls and quotes (as necessary) the individual arguments, when passing the arrays to the command.
To fix the code:
$TEMP = "C:\temp" ## dossier temporaire de récupération des essences (de-wrapp fichier ingesté)
$MAPaudio = @() # create empty array
$Filesaudio = @() # create empty array
for ($i = 1; $i -le $nombreAudios; $i ) {
$TEMP_AUDIO = Join-Path $TEMP "audio$i.wav"
##Extraction de l'audio et conversion en 48000hz (Obligatoire pour le MXF)
# Append two elements to the argument array
$MAPaudio = "-map", "${i}:a"
# Append two elements to the argument array
$Filesaudio = "-i", $TEMP_AUDIO
}
$TEMP_VIDEO = Join-Path $TEMP "video.mxf"
# Finally pass the arguments separately, instead of a single string
ffmpeg -i $TEMP_VIDEO $Filesaudio -c copy -map 0:v:0 $MAPaudio -y 'c:\transcode\test.mxf'
CodePudding user response:
I test this:
##Récupération et formatage du nom de la vidéo
$name=[string]$_
$nameFileToEncode=$name.split('.')[-2]
$nameFileToEncode=$nameFileToEncode.replace(" ","_")
##Path complet de la Video de sortie
$outVideo="$outPath" "\" "$nameFileToEncode" ".mxf"
$MAPaudio=""
$Filesaudio=""
for($i=1;$i -le $nombreAudios;$i )
{
$TEMP_AUDIO=$TEMP "audio" $i ".wav"
##Extraction de l'audio et conversion en 48000hz (Obligatoire pour le MXF)
$MAPaudio = " -map " $i ":a "
$Filesaudio =" -i " $TEMP_AUDIO
}
$TEMP_VIDEO=$TEMP "video.mxf"
write-host $MAPaudio
write-host $Filesaudio
##Encapsulage de la vidéo
&ffmpeg -i $TEMP_VIDEO $Filesaudio -c copy -map 0:v:0 $MAPaudio -y 'c:\transcode\test.mxf'
but i have this error:
Output #0, wav, to ' -i C:\temp\audio1.wav -i C:\temp\audio2.wav -i C:\temp\audio3.wav -i C:\temp\audio4.wav':
Output file #0 does not contain any stream
Curiously, it says that is a output then this is inputs...