I'm trying to write a batch file that can be launched from Handbrake GUI with the "send file to" feature, that will split an MKV into chapters with MKVmerge, then convert all those new files into mp4s with ffmpeg. Handbrake passes only one argument into the batch file, the full file path of the output (surrounded by quotes). I'm very new to batch scripting and am having difficulty getting it all to work together -- all the individual parts work just fine when absolute paths are given. Here's the content of the .bat file:
START /WAIT "C:\Program Files\MKVToolNix\mkvmerge.exe -o output.mkv --split chapters:all %1"
for %%i in (*.mkv) do C:\ffmpeg\bin\ffmpeg.exe -i "%%i" -loop 1 -i "%%~dpi"\folder.jpg -map 1:v -map 0:a -c:a ac3 -b:a 640K -pix_fmt yuv420p -c:v libx264 -shortest -fflags +shortest -max_interleave_delta 100M "%%~ni.mp4"
Any glaring mistakes I'm making? I've been at this for hours reading SO threads and documentation, and can't figure it out for the life of me. Any help is appreciated, thanks in advance.
Related
can someone help me to keep original name in input as output
For example, i have a "Video.mp4" i need to convert it in mp3 as "Video.mp3"
but i cant find it how to do it!
i try
ffmpeg -i video.mp4 -b:a 192K -vn music.mp3
but the output file is "music.mp3" and i dont want it
soo i try ffmpeg -i A.mp4 -b:a 192K -vn *.mp3
and it gives error like :
*.mp3: Invalid argument
pls help me :(
[untried]
#echo off
ffmpeg -i "%~1" -b:a 192K -vn "%~n1.mp3"
As a batch file named tomp3.bat, use as tomp3 "video.mp4"
The quotes are not required unless the filename contains spaces (or some other symbols)
I am using this command in windows 8 to overlay a logo (mywatermark.png , 400x200) to a video file:
ffmpeg -i E:\source\video01.mp4 -i E:\logo\mywatermark.png -filter_complex "[1:v]scale=100:50 [ovrl], [0:v][ovrl
]overlay=W-w-10:H-h-10[watermark]" -map "[watermark]" -map 0:a -codec:v libx264 -preset veryfast -crf 18 -codec:a copy E:\output\video01.mp4
as you can see I am first rescaling my logo to 100:50 pixels, and then overlaying it to the bottom right corner.
This is working for me.
My question is:
How can I repeat this to all of the videos in the same directory, adding the same logo to all?
I want to save the output video files same as the original, of course in different folder. However, not to forget that my source video files are of different quality and resolution.
How can I add a parameter to the command line to proportionnally scale the logo in regard to the video file resolution?
I am afraid that if I don't do this, the logo will be small in one file and bigger in another.
thanks a lot
How can I repeat this to all of the videos in the same directory, adding the same logo to all?
Windows command line processor - cmd.exe - offers the command FOR for executing a command on all files in a directory.
#echo off
for %%I in ("E:\source\*.mp4") do ffmpeg.exe -i "%%I" -i E:\logo\mywatermark.png -filter_complex "[1:v]scale=100:50 [ovrl], [0:v][ovrl]overlay=W-w-10:H-h-10[watermark]" -map "[watermark]" -map 0:a -codec:v libx264 -preset veryfast -crf 18 -codec:a copy "E:\output\%%~nI.mp4"
Running in a command prompt window for /? or help for outputs help for this command over several display pages. As help of command FOR is long, it is advisable to redirect the output help into a text file and read the file with Notepad or any other text editor.
for /? >"%USERPROFILE%\Desktop\Help_FOR.txt"
Notepad "%USERPROFILE%\Desktop\Help_FOR.txt"
In above batch code %%I is replaced by name of current *.mp4 file with full path and %%~nI with just name of current *.mp4 file without path and without file extension.
As #LordNeckbeard commented, you can use the scale2ref filter to proportionally scale the watermark, like so
ffmpeg -i E:\source\video01.mp4 -loop 1 -i E:\logo\mywatermark.png \
-filter_complex "[1:v][0:v]scale2ref=iw/8:-1[ovrl][0v]; \
[0v][ovrl]overlay=W-w-10:H-h-10[watermark]" \
-map "[watermark]" -map 0:a \
-codec:v libx264 -preset veryfast -crf 18 -c:a copy E:\output\video01.mp4
The iw/8 specifies that the watermark's width and height be scaled to 1/8th of the base video's width and height. The scale2ref filter has the same options available as the scale filter.
So I have been trying for days to work out how to do this and this site has helped me but I am still stuck.
I basically want to run a batch file and it goes through a folder including all subdirectories and changes the container of all mkv files to mp4 converting the sound to AAC if necessary. Preferably it will create the new mp4 file in the same place with the same name and then delete the mkv.
All I have so far is this which if I place it in a certain folder will create the mp4's in a specified folder called newfiles. I am not sure if I have used libfaac correctly either. Would greatly appreciate any advice. I would have liked to use libfdk_aac but I have tried everything to get it and I cant find it.
for %%a in ("*.mkv") do C:\ffmpeg\bin\ffmpeg -i "%%a" -vcodec copy -acodec libfaac "Z:\newfiles\%%~na.mp4"
pause
Try this for variable bit rate (VBR):
for %%a in (*.mkv) do C:\ffmpeg\bin\ffmpeg -i "%%~a" -vcodec copy -c:a libfaac -q:a 100 "%%~na.mp4"
pause
Range for -q:a is 10-500 and is similar to using the -q option in standalone faac. 100 is a good value to try.
or try this for average bit rate (ABR):
for %%a in (*.mkv) do C:\ffmpeg\bin\ffmpeg -i "%%~a" -vcodec copy -c:a libfaac -b:a 192k "%%~na.mp4"
pause
FFmpeg and AAC Encoding Guide: libfaac
Note that you will not get as good results as with libfdk_aac.
The license of libfdk_aac is not compatible with the GPL, so the GPL does not permit distribution of binaries containing code licensed under these licenses when GPL-licensed code is also included. Therefore this encoder has been designated as "non-free", and you cannot download a pre-built ffmpeg that supports this. This can be resolved by compiling ffmpeg yourself. You can do this for example with the help of this project.
I'm using the following ffmpeg script to convert all .mp4 files in the folder to .webm.
for %%A IN (*.mp4) DO ffmpeg -i "%%A" -c:v libvpx -crf 4 -b:v 3M -c:a libvorbis "%%A.webm"
I am trying to make it go from "xxx.mp4" to "xxx.webm"
However when I run the script the file name goes from "xxx.mp4" to "xxx.mp4.webm"
Any suggestions are highly appreciated.
Use %%~nA.webm to select the name-part of the filename.
see for /? from the prompt or documentation.
To recursively convert in webm all the mp4 video files in nested folders, you can try this command:
find '~/Video/' -iname '*.mp4' -exec bash -c 'D=$(dirname "{}"); B=$(basename "{}"); mkdir "$D/webm/"; ffmpeg -i "{}" -c:v libvpx -crf 4 -b:v 3M -c:a libvorbis "$D/webm/${B%.*}.webm"' \;
It will create a folder named "webm" inside the one with mp4 video files and, inside the "webm" folder, it will save relative webm files, without keeping the old file extension in the name.
i have a folder full of .avi files and i want to use ffmpeg to convert them to .mp4 files. I followed an online tutorial to create a batch file that does just this, here is the code:
"C:\ffmpeg\ffmpeg.exe" -y -i %1 -sameq -ar 22050 -vcodec libx264 "C:\videos\Series 1\S01E01.mp4"
This works fine if i just drag and drop the .avi files onto the createmp4.bat file containing the above code. However i want to be a little bit smarter about this and use another batch file that will iterate through the .avi files in the folder and run createmp4.bat on all of them and copy them to the C:\videos\Series 1\ directory.
I would also like to change the name of the files if possible to S01E01.mp4, S01E02.mp4 and so on if possible.
Any help on this would be greatly appreciated. Oh and just in case you hadn't guessed i am fairly clueless about writing batch files!!
Thanks
try this (example):
#echo off & setlocal
pushd "X:\My AVI folder"
for %%i in (*.avi) do "C:\ffmpeg\ffmpeg.exe" -y -i "%%~fi" -sameq -ar 22050 -vcodec libx264 "C:\videos\Series 1\%%~ni.mp4"
popd