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)
Related
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.
I have a script for converting video using a batch and ffmpeg. however im confused as to why %%~nf and %%~n1 aren't returning the name of the file (without the format). I've tried various " ' % to see what the cause is, though im quite lost as the %~1 variable works fine.
if not %Vcodec% == h264 if not %Acodec% == ac3 (echo Converting Video, Converting Audio
'C:\ffmpeg\bin\ffmpeg.exe -i "%~1" -map 0 -vcodec libx264 -scodec copy -acodec ac3 -b:a 640K '%%~n1.mkv')
Produces
C:\Users\Desktop\to fix>if not mpeg4 == h264 if not mp3 == ac3 (
echo Converting Video, Converting Audio
'C:\ffmpeg\bin\ffmpeg.exe -i "S02E01.avi" -map 0 -vcodec libx264 -scodec copy -acodec ac3 -b:a 640K %~n1.mkv'
)
rather than SO2EO1. if i add another % to it, it returns
C:\Users\Desktop\to fix>if not mpeg4 == h264 if not mp3 == ac3 (
echo Converting Video, Converting Audio
'C:\ffmpeg\bin\ffmpeg.exe -i "S02E01.avi" -map 0 -vcodec libx264 -scodec copy -acodec ac3 -b:a 640K %S02E01.mkv'
)
So i don't understand why one variable works and the other doesn't event though it should? As in the example I've used to make this script "%%~nf".mkv works. I'm a novice to scripting, so if you do provide an answer an explanation or a link to an explanation would be great.
%1 is an internal variable, so
'%~n1.mkv'
See https://ss64.com/nt/syntax-args.html
%~n1 Expand %1 to a file Name without file extension C:\utils\MyFile
or if only a path is present (with no trailing backslash) - the last
folder in that path.
What we have:
test.mp3
test.mp4
We want to merge this using ffmpeg
ffmpeg -i "test.mp3" -i "test.mp4" -c copy D:\test_final.mp4
The thing is we just need this to do for tons of videos.
What we currently have:
for %%a in ("merge\*.*") do ffmpeg -i "%%a" -i "%%a" -c copy D:\%%~na
So, what's the correct form? I have no idea :/
In merge there are always mp3 and mp4 files with the same name.
What you have looks pretty darn good, and you didn't describe exactly how it does not work for you.
To match your desired line more exactly:
Get only *.mp3 files
Use %%~pa%%~na to get the path and filename-only, but no extension, then add a .mp4 on the end of it.
Add a _final to the resulting name
If this isn't working for you, please describe exactly how it fails.
for %%a in ("merge\*.mp3") do (
ffmpeg -i "%%a" -i "%%~pa%%~na.mp4" -c copy D:\%%~na_final.mp4 )
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.