0

I have created a batch file (.bat) that uses FFmpeg to transcode various videos (with *.mov or *.mp4 file name extension) from an input folder to an output folder (with extension *.mkv) as batch process (Windows 10 environment). File names (without extension) from the input folder should be copied to the newly created output file names (that have the new file extension *.mkv).

@echo off

set CMD=ffmpeg -c:v ffv1 -level 3 -g 1 -coder 1 -context 1 -pix_fmt + -slices 24 -slicecrc 1 -report -c:a pcm_s24le

FOR /R input_folder %%G IN (*.mov,*.mp4) DO (
   echo %%G
   call set outputfile=%%~nG%.mkv
   call set inputfile=%%~nG%%~xG
   echo %CMD% -y output_folder/%outputfile% -i %inputfile%
)

But this script does not work as expected, i.e. nothing happens. Do you perhaps have an idea how to fix this? Thanks in advance!

3
  • Something does happen. Essentially your script will, determine whether there are any files in the tree of the current working directory to process and then process them before closing. In this particular case, if there are no files, then little will happen, because the DO portion of the script will not run. If there are files matching the *.mov or *.mp4 globs, then each of those will be echoed quickly to the screen, as will your written ffmpeg command before the script closes. Commented Mar 1, 2021 at 10:46
  • The first thing you need to do is to make sure that you have not turned echoing off, and run your script directly from the Command Prompt window, (with your target parent path/tree root as the current working directory). You should then see all of the output to determine what is really happening. I'd advise that you change echo %CMD% to %CMD%, if you really want ffmpeg to process matching files. BTW, both of your call set lines are redundant, you should remove them and change echo %CMD% -y output_folder/%outputfile% -i %inputfile% to %CMD% -y "output_folder\%%~nG.mkv" -i "%%G". Commented Mar 1, 2021 at 10:46
  • Thank you so much! It works! One last question: How can the script automatically delete the files in the input folder after the job? Commented Mar 1, 2021 at 11:44

1 Answer 1

1

Here's an example showing my suggestions from the comments, with the addition of the file deletion as requested in the comments too. This assumes that ffmpeg returns an errorlevel of 0 upon success, (you don't want to delete them if the processing failed), and that there is an existing directory named output_folder, in the current working directory.

@Echo Off
SetLocal EnableExtensions
Set "CMD=ffmpeg.exe -c:v ffv1 -level 3 -g 1 -coder 1 -context 1 -pix_fmt +"
Set "CMD=%CMD% -slices 24 -slicecrc 1 -report -c:a pcm_s24le"

For /R "input_folder" %%G In (*.mov *.mp4) Do (
    Echo %%G
    %CMD% -y "output_folder\%%~nG.mkv" -i "%%G"
    If Not ErrorLevel 1 Del /A /F "%%G"
)
Sign up to request clarification or add additional context in comments.

2 Comments

I know you just copied supplied ffmpeg command from the question, but to prevent unexpected behavior the general syntax should be ffmpeg [input options] -i input [output options] output. As is, it seems to be attempting to apply some output options to the input and will likely fail. Also, + is a valid option for -pix_fmt, but it appears to have been misplaced in the answer.
@llogan, you're correct that I copied it as is, without checking it, that's only because the OP had already stated that It works!. I'm not sure what you mean by misplaced though, unless you just mean the point at which I split the line over two, would have been more readable, had I included the + on the line above. I have assumed that is what you meant, so I've adjusted it accordingly, for better readability/understanding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.