2

Sorry, the title isn't very descriptive, but I couldn't think of a better one.

I use this script to drag and drop video + audio file, and combine them with ffmpeg.

ffmpeg -i "%~1" -i "%~2" -c copy "C:\New Folder\%~n1".mp4

It works great, but the input, and subsequently output files have ".raw" ending before the extension. Is there an easy way remove the last 4 characters of %~n1 or replace ".raw" with ""? I want to manipulate the string before assigning it as file name with ffmpeg, I don't want to output the file with .raw.mp4 ending, and then rename it.

2 Answers 2

1

Is there an easy way remove the last 4 characters of %~n1?

You need to use the substring operator. Try the following cmd script:

@echo off
rem avoid polluting global environment space
setlocal
set "_file=%~n1"
rem strip last 4 characters from _file
set "_name=%_file~0,-4%"
rem run ffmpeg with new name
ffmpeg -i "%~1" -i "%~2" -c copy "C:\New Folder\%_name%".mp4
endlocal

Further Reading

9
  • I get an error C:\New Folder".mp4: Invalid argument
    – DD3R
    Commented Nov 29, 2022 at 11:34
  • Try moving the " after the 4
    – DavidPostill
    Commented Nov 29, 2022 at 13:49
  • That just outputs .mp4 file without a name. Feels like %_name% isn't passing anything.
    – DD3R
    Commented Nov 29, 2022 at 17:23
  • I assume you meant the last " in ffmpeg -i "%~1" -i "%~2" -c copy "C:\New Folder\%_name%".mp4
    – DD3R
    Commented Nov 29, 2022 at 18:05
  • Yes, "C:\New Folder\%_name%.mp4"
    – DavidPostill
    Commented Nov 29, 2022 at 19:21
1

Here's the answer that works

set filename=%~n1
set filename=%filename:.raw=%
ffmpeg -i "%~1" -i "%~2" -c copy "%filename%.mp4"
pause

You must log in to answer this question.

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