0

I've created a .bat file that I can use to drag and drop an mp4 video file onto it to convert reddit videos format to a format supported by whatsapp. All this using ffmpeg
Here's the code of the .bat file:

"D:\Programas\ffmpeg\bin\ffmpeg.exe" -i "%~1" -vcodec libx264 -acodec aac ./out.mp4
PAUSE

As you can see, pretty straightforward.
My only issue resides on the ./out.mp4 part of the command, where if I drag and drop from say "Downloads", and the .batfile is sitting on the Desktop, the out.mp4 file will be created on Downloads instead of Desktop.

How can I alter this behavior (besides setting the output to /path/to/Desktop/out.mp4), so I can move the bat file elsewhere and still get the same intended behavior?

Thanks.

1 Answer 1

1

Okay, after RTFM https://ss64.com/nt/syntax-args.html
Section called: Links relative to the Batch Script

You can use %0 for the "batch file path"
So, the solution for this particular case would be:

"D:\Programas\ffmpeg\bin\ffmpeg.exe" -i "%~1" -vcodec libx264 -acodec aac "%~dp0/out.mp4"
PAUSE
4
  • Oh well, feel free to edit the answer then! Commented Dec 15, 2020 at 1:32
  • Yes, consistently on diferent directories and also across different hard drives. I Don't know if it works across network locations, as I don't have any. Commented Dec 15, 2020 at 1:37
  • 1
    to be consequent and safe, quote the output file too: "%~dp0/out.mp4" (there might be spaces or other poison chars in %~dp0)
    – Stephan
    Commented Dec 25, 2020 at 17:21
  • Ah okay, makes sense, edited. Commented Dec 26, 2020 at 4:57

You must log in to answer this question.

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