Creating a batch file with the "IF" command

batch-file, command, command-line, windows

Solution

I'm not sure if FFMPEG returns a standard error code in case of failure, but if it does, you can use the following:

ffmpeg -i %namefile%.mp4 -c:v libx264 -crf 19 %destinationfile%.flv
if not errorlevel 1 goto Done
ffmpeg -i %namefile%.mp4 -c:v libx264 -ar 22050 -crf 28 %destinationfile%.flv
:Done

If this approach doesn't work, you can check the existence of the destination file to determine further action:

ffmpeg -i %namefile%.mp4 -c:v libx264 -crf 19 %destinationfile%.flv
if exist %destinationfile%.flv goto Done
ffmpeg -i %namefile%.mp4 -c:v libx264 -ar 22050 -crf 28 %destinationfile%.flv
:Done

Hope one of these works.

Problem

I have created a little batch file for helping people to convert MP4 video to FLV with FFMPEG. A way to make it simple to everyone i know to use it. I was thinking the line i've put in was perfect for every situation (converting a MP4 file to FLV), but few days ago, it didn't work for a file. (audio sample to high for FLV format) I found with the help of people a other codeline to convert it, but i don't know how to correctly integrate it, in my batch file. There is what i use right now : echo "Enter the name of the file, whitout the extension" : set /p namefile= echo "Enter the name you what to give to the destination file" : set /p destinationfile= ffmpeg -i %namefile%.mp4 -c:v libx264 -crf 19 %destinationfile%.flv And i want to add a "IF". Because if that doesn't work with this line, use that one : ffmpeg -i %namefile%.mp4 -c:v libx264 -ar 22050 -crf 28 %destinationfile%.flv How can i do that ? Thank you very much for your help and if i'm unclear on something, just tell it to me and i will do my best to make it clear. Thanks !

Original source