Search code examples
batch-fileffmpegaacm4a

ffmpeg/batch file: input format stays in output file name


I created this batch file to put all aac files in one directory into an m4a container. The command works so far, but every new file generated has the format of the input file in the output files name.

For example: test(.aac) is in an m4a container but is NAMED test.aac(.m4a)

Here is the .bat file:

for /r %%X in (*.*) do (
    ffmpeg -i "%%X" "%%X.m4a"
)
pause

I'll be grateful for any easy solution, best regards and thanks to everyone


Solution

  • you need to extract just the name without extension

    for /r %%X in (*.aac) do (
        ffmpeg -i "%%X" "%%~dpnX.m4a"
    )
    

    see HELP FOR for an explanation of the %%~dpn syntax, in short

    %%~X - expands %%X removing any surrounding quotes (")
    %%~fX - expands %%X to a fully qualified path name
    %%~dX - expands %%X to a drive letter only
    %%~pX - expands %%X to a path only
    %%~nX - expands %%X to a file name only

    I have also changed a bit the FOR selection mask to iterate only over .aac files.