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 !
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.
Similar to EitanT's first solution, but without using GOTO.
ffmpeg -i %namefile%.mp4 -c:v libx264 -crf 19 %destinationfile%.flv
if errorlevel 1 ffmpeg -i %namefile%.mp4 -c:v libx264 -ar 22050 -crf 28 %destinationfile%.flv
or
Edited - the code had gotten truncated, all fixed now
ffmpeg -i %namefile%.mp4 -c:v libx264 -crf 19 %destinationfile%.flv||ffmpeg -i %namefile%.mp4 -c:v libx264 -ar 22050 -crf 28 %destinationfile%.flv
Similar to EitanT's second solution, but without using GOTO
ffmpeg -i %namefile%.mp4 -c:v libx264 -crf 19 %destinationfile%.flv
if not exist %destinationfile%.flv ffmpeg -i %namefile%.mp4 -c:v libx264 -ar 22050 -crf 28 %destinationfile%.flv
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.