Extract WAV from an MP4, process and then remux it back - batch-file

I have a large number of x264+AAC MP4 files. I have written an audio filter that operates on PCM wav files that I want to apply to the audio on all my videos, replacing the existing audio with the filtered version.

I eventually accomplished this with a DOS batch file and FFMPEG:
ffmpeg -i "%~f1" "%~f1.wav"
audiofilter "%~f1.wav"
ffmpeg -i "%~f1" -i "%~f1.wav" -vcodec copy -acodec libvo_aacenc "%~f1.complete.mp4"
move /Y "%~f1.complete.mp4" "%~f1"

Related

How to convert rmvb to mp4 with same quality by using ffmpeg?

I found a batch file that can convert rmvb to mp4 using ffmpeg command, but the filesize become very big after converted(700mb become 3gb), so can I change something in the script below to make the filesize smaller and same quality?
FOR /F "tokens=*" %%G IN ('dir /b *.rmvb') DO ffmpeg -i "%%G" -vcodec
mpeg4 -qscale:v 2 -acodec aac "%%~nG.mp4"
And also why Im keep getting this message? Is it something wrong with the script?
You can simplify the for loop to:
for %%G in (*.rmvb) do ffmpeg -i "%%~G" -c:v h264 -c:a aac "%%~nG.mp4"
This converts to h264 video and aac audio. These codecs quite common at present.
Video defaults to CRF 23 while audio should default to 128k.
This should give reasonable quality at perhaps a tenth of the bitrate shown in your image of 9300k down to perhaps under 1000k.
The duration errors happen sometimes and may seem a lot though the end video may still appear as good as the original.

ffmpeg Converting files in place

I use ffmpeg on a daily basis to convert multiple video files to various other formats. Because of this I can't be moving ffmpeg and multiple batch files all over the place.
I have the folder C:\ffmpeg which contains ffmpeg.exe and all my different batch file converters for the different formats. I then have a shortcut on the desktop to the batch file which I can drag and drop video files onto to convert them.
As it stands, I use this to convert the video files in place.
FOR %%A IN (%*) DO (
"%~dp0\ffmpeg.exe" -i %%A -c:v libx264 -crf 22 -c:a aac %%A_Converted.mp4
)
Dragging and dropping the video file example.avi from the folder C:\Users\User\Documents\Folder results in the file example.avi_Converted.mp4 being created in the same location (perfect!).
I am wanting to remove the original file type, .avi from the new file name - so the output file is example_Converted.mp4. I can do this using ~n, shown in the following code sample, although the new file then gets created in C:\ffmpeg instead of in C:\Users\User\Documents\Folder.
FOR %%A IN (%*) DO (
"%~dp0\ffmpeg.exe" -i %%A -c:v libx264 -crf 22 -c:a aac "%%~nA_Converted.mp4"
)
Is there a way to do this so that the output file is created is the same place as the input file?

ffmpeg batch script that combines multiple audio clips with one image > mp4

I found this script in another thread and edited it to make this:
#echo off
for %%F in (*.jpg) do (
if exist "%%~nF.mp3" (
ffmpeg -loop 1 -i "%%~nF.jpg" -i "%%~nF.mp3" -acodec libvo_aacenc -vcodec mpeg4 -shortest "%%~nF.mp4"
)
)
It combines all mp3 files with all jpeg files that share the same filename into a mp4 video with the static image running.
But the problem is - if I want to convert more than one mp3 file using the same image (let's say three mp3s), I have to duplicate the same jpeg image three times!
For example, if I have three Michael Jackson mp3 files:
MJ1.mp3
MJ2.mp3
MJ3.mp3
I would need to create:
MJ1.jpg
MJ2.jpg
MJ3.jpg
But really I only need one image for all three mp3s.
What edits do I need to make to the script combine all mp3s with one jpeg file? Let's say I wanted every mp3 file in the folder to convert with default.jpg. How would I do this?
Invert the loop. Instead of iterating over the images, iterate over the sound files.
#echo off
for %%F in (*.mp3) do (
ffmpeg -loop 1 -i "default.jpg" -i "%%~nxF" -acodec libvo_aacenc -vcodec mpeg4 -shortest "%%~nF.mp4"
)

Bulk converting MKV files to MP4 with AAC using a Windows batch file

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.

ffmpeg batch retains old filetype in name

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.

Resources