0

I would like to convert videos and set time on them to be same as from source file. I use batch for converting files in folder with ffmpeg

for %%a in ("*.MP4") do ffmpeg -i "%%a" -c:v libx264 -c:a aac "%%~naC.mp4"
pause

And then I have a powershell code which I use with excel to match files LastWriteTime

powershell (Get-ChildItem 'P1290526C.mp4').LastWriteTime = (Get-ChildItem 'P1290526.MP4').LastWriteTime

Is there any way how I can joint this two codes togather so I will use just one script/bat file?

Thank you very much.

  • What does this have to do with excel? – DavidPostill Jan 6 at 19:02
1

Put the PowerShell command into the same for loop:

for %%A in ("*.MP4") do (
    ffmpeg -i "%%A" -c:v libx264 -c:a aac "%%~nAC.mp4"
    powershell -NoP -C "(gi '%%~nAC.mp4').LastWriteTime = (gi '%%A').LastWriteTime"
)

gi is the alias for Get-Item, no need to iterate with Get-ChildItem.

As this will invoke powershell for every converted file it is more efficient to either:

  • let powershell do the whole job

  • or run powershell only once after converting all files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.