News:

--

Main Menu

Batch Convert Audio and Video Problem

Started by chucknolan, August 07, 2020, 03:57:14 PM

Previous topic - Next topic

chucknolan

Can someone please help me with this command?  The audio won't convert to the desired codec nor bitrate.  It just creates a copy of the original and changes the output to the desired (.mp4).

set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set videocodec=copy
set audiocodec=AAC
set audiobitrate=160
for %%f in (*.mkv) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --audio-bitrate %audiobitrate% --force-alt-h264 --load "%%f" --save "%%f.mp4" --quit

eumagga0x2a

Quote from: chucknolan on August 07, 2020, 03:57:14 PM
set audiocodec=AAC

There is no audio encoder called "AAC", this is why the command line fails in the first place. To encode to AAC, there is a choice of LavAAC, FDK_AAC and maybe also Faac (unsure whether faac is included in VC++ builds, but it doesn't matter much if it is missing as it is considered to be the worst of the three).

Quoteset audiobitrate=160
for %%f in (*.mkv) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --audio-bitrate %audiobitrate% --force-alt-h264 --load "%%f" --save "%%f.mp4" --quit


There is no such option "--audio-bitrate" and no "--force-alt-h264", you have probably picked up some terribly outdated documentation (well, there is no other aside from the source code). Apart from that, --load should come first.

To pass options to encoders, filters and muxers please use a project script (you might want to take a look at this topic).

dosdan

#2
Quote from: chucknolan on August 07, 2020, 03:57:14 PM
for %%f in (*.mkv) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --audio-bitrate %audiobitrate% --force-alt-h264 --load "%%f" --save "%%f.mp4" --quit

When it's simple stuff like this and you wish to do it to a lot of media files, I think it's kludgy/overkill to do it inside ADM (unless ADM's Copy option is doing significantly more checking/fixing than FFMPEG's).

Here is a batchfile to convert all MKVs in the current directory to MP4s with 160k AAC audio streams in the "converted" sub-directory.

Convert_MKV_To_MP4.bat
@echo off
cls
setlocal
set videocodec=copy
set audiocodec=aac
set audiobitrate=160k

if not exist converted\ md converted > nul

for %%F in (*.mkv) do (
ffmpeg -i "%%~dpnxF" -hide_banner -v error -y -c:v copy -c:a %audiocodec%  -b:a %audiobitrate% "%%~dpFconverted\%%~nF.mp4" && echo "%%~dpnxF" was converted to "%%~dpFconverted\%%~nF.mp4"
echo.
        shift
)
pause


Here's the screen display when running this batchfile inside a directory with 3 MKVs, the 2nd of which was purposely corrupt to check error-handling:
"C:\test directory\temp dir\test_file_1.mkv" was converted to "C:\test directory\temp dir\converted\test_file_1.mp4"

Truncating packet of size 9064 to 599
[matroska,webm @ 000001e905db70c0] EBML header parsing failed
C:\test directory\temp dir\test_file_2.mkv: Invalid data found when processing input

"C:\test directory\temp dir\test_file_3.mkv" was converted to "C:\test directory\temp dir\converted\test_file_3.mp4"

Press any key to continue . . .



Unless you specifically want to run different versions of FFMPEG, just place ffmpeg.exe (and any batchfiles you use regularly) in a directory mentioned in your PATH list of environmental variables, say "C:\utils".  Then you can run it from any location.

People often have more than one version of ffmpeg.exe on their PCs. To see which one will be executed if it's not in the current directory, and the PATH list is now being searched, use:
where ffmpeg.exe
C:\Mingw\media-autobuild_suite-master\local64\bin-video\ffmpeg.exe
c:\utilities\ffmpeg.exe



If more than one copy is found, the first one is the one that will be executed.  To see their date/times use:
where /t ffmpeg.exe
  38917120   20/07/2020   11:12:59 AM  C:\Mingw\media-autobuild_suite-master\local64\bin-video\ffmpeg.exe
  38917120   20/07/2020   11:12:59 AM  c:\utilities\ffmpeg.exe


If you create a shortcut to this batchfile and place the shortcut on your Windows desktop, you can the drag a directory name onto it to process all the MKVs in this directory, so you don't need to go to the CMD prompt. To suit that mode of operation, change the set of data specified in the FOR loop from (*.mkv) to (%*\*.mkv). The design could also be modified to recurse through sub-directories below the current directory or the directory that you dropped onto the icon.

Dan.