0

I am having a similar issue as referenced here, but it seems I am doing everything right and still this happens. Here is the faulty part my code, with the goal to convert from one file format to another with ffmpeg:

set    subfolder=converted
set   source_ext=.avi
set   target_ext=.mov

md %subfolder%
set path=%~dp0

setlocal enabledelayedexpansion
FOR %%I IN ("*!source_ext!") DO (
  echo 1 %%I
  set this_file=%%I
  echo 2 !this_file!
  set filename_new=!!this_file:%source_ext%=!!
  set output=!path!%subfolder%\!filename_new!!target_ext!)

  %ffmpegpath%\ffmpeg.exe -i "!this_file!" -vcodec copy -acodec copy "!output!"
    echo CONVERTED !this_file!
)

The output I am looking for is this:

1 file1.ext
2 file1.ext
CONVERTED file1.ext
1 file2.ext
2 file2.ext
CONVERTED file2.ext
1 file3.ext
2 file3.ext
CONVERTED file3.ext

What I get, strangely, is this:

1 file1.ext
2 file1.ext
1 file2.ext
2 file2.ext
1 file3.ext
2 file3.ext
CONVERTED file3.ext

I am stumped!

Community
  • 1
  • 1
Phil Strahl
  • 165
  • 1
  • 1
  • 8

1 Answers1

1

Your error is due to the incorrect placing of a closing parenthesis before the ffmpeg command line. Just removing that parenthesis should fix the issue.

Your script only uses delayed expansion to echo unnecessary commands to the prompt window, so I have removed that stuff in the below rewrite.

If Not Exist "%ffmpegpath%\ffmpeg.exe" GoTo :EOF

Set "subfolder=converted"
Set "source_ext=.avi"
Set "target_ext=.mov"

If /I Not "%CD%\"=="%~dp0" CD /D "%~dp0"

If Exist *%source_ext% (
    If Not Exist "%subfolder%" MD "%subfolder%"
) Else GoTo :EOF

For %%A In ("*%source_ext%") Do (
    "%ffmpegpath%\ffmpeg.exe" -i "%%A" -vcodec copy -acodec copy "%subfolder%\%%~nA%target_ext%"
)
Compo
  • 36,585
  • 5
  • 27
  • 39
  • Thank you very much for taking the time to even clean up my code! Now that you pointed out the mistake, it's really obvious! – Phil Strahl May 07 '17 at 22:32