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

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.

Related

FFMPEG, convert video same as input size with watermark in Batch

I would like to watermark some videos in a directory. I use a png watermark of 3840x2160 in size. The watermark should go in fullsize on the video. Because my videos have different resolutions I use this batch script
set /p add_watermark=Wasserzeichen Addieren? (Standard: ja/nein):
if /i "%add_watermark%" == "" set add_watermark=ja
if /i "%add_watermark%" == "ja" (
for %%f in (%cd%\output\tmp\*.mp4) do (
set "filename=%%~nf"
ffmpeg -i "%%f" -i %cd%\watermark\watermark.png -filter_complex "[0:v][1:v]scale2ref=oh*mdar:ih[v0][v1];[v0][v1]overlay=main_w-overlay_w-0:0" -c:a copy -map 0 -y "%cd%\output\%%~nf.mp4"
)
)
That works well with videos in 4k but if my input is a HD video it will scale the output up to 4k in the size of the watermark.
If I try to add
-c:v copy FFMPEG is giving out the error
Streamcopy requested for output stream fed from a complex filtergraph. Filtering and streamcopy cannot be used together.
My question is, how can I set the output as same size as the input video with the scaled watermark without doing this in two steps.
Because it seems there is no other idea how to archive this in on step without re-encoding i did a batch script that extracts the resolution from the video files and use it to change the link to a watermark.png in different resolutions.
As example:
watermark_1920x1080.png
watermark_2560x1440.png
watermark_3840x2160.png
and so on. This is only a impractical workarround (but well it works) i let this question open.

Troubleshooting ffmpeg batch-file. mkv to mp4 conversion with subtitle hardcode

I am trying to batch convert a large number of .mkv video files to .mp4 while hard coding the subtitles included in the .mkv files. I would like to retain as much quality as possible.
I am not an adapt at using ffmpeg or writing batch files, so I have been searching online for batch files which will do what I need. I found some which successfully convert without the subtitles, and I found one that included the command for hard coding the subtitles, but that one also had excessive commands that I didn't want to delve into, so I am attempting to combined the relevant parts of the two scripts. That is where the problem is obviously coming from.
for %%a in (*.mkv) do ffmpeg -i "%%~a" -vf subtitles=%%~na.mkv copy -c:a aac -q:a 100 "%%~na.mp4"
pause
It is worth noting that the script was originally:
for %%a in (*.mkv) do ffmpeg -i "%%~a" -vcodec copy -c:a aac -q:a 100 "%%~na.mp4"
pause
But I changed it as best I could to include a section of script I found which should apparently hard code the subtitles. My lack of knowledge about how this scripting language actually functions probably just made me insert the command in the wrong place or in the wrong way. I hope that background information makes this problem easier to solve.
Expected results: convert each .mkv file in the current folder and leave the .mp4 file in the same folder.
Actual results:
[NULL # 0000026a399f1440] Unable to find a suitable output format for 'copy': Invalid argument.
Not a batch file user, but I can comment on the ffmpeg command. Use:
for %%a in (*.mkv) do ffmpeg -i "%%~a" -vf subtitles=%%~na.mkv "%%~na.mp4"
pause
You can't use -vcodec copy/-c:v copy with -vf because filtering requires encoding.
If the input audio is already AAC then add -c:a copy to stream copy (re-mux) the audio instead of re-encoding it.
This will rely on the default stream selection behavior. See the -map option if you want to include/exclude certain streams such as if your input has multiple video and/or audio streams.
I figured this out, thanks to comments from people here which helped me search out relevant info.
One of the main, and most embarrassing problems is that the original batch file was in Linux format and I am running on Windows.
This is the working batch file that I pieced together by editing someone else's batch file. I will leave a link to the original batch file as well.
for %%A IN (*.mkv) DO ffmpeg -i "%%A" -vf subtitles="%%A" "%%A.mp4"
pause
This is where I got the original code from: https://superuser.com/questions/470500/batch-convert-avi-files-using-ffmpeg#470510
And this is where I got information about hard coding the subtitles: https://superuser.com/questions/932730/ffmpeg-mkv-to-mp4-conversion-loses-subtitles
Thanks again :)

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.

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

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"

Resources