So, I'm trying to refactor some old code that should remove video streams, compress the audio stream and repack the mp4, which should be a video file with only an audio stream. I later intend to replicate it to work with .wmv.
According to the author, it works like this:
Use mediainfo.exe to get AudioStreamID (1 or 2)
mediaindo --inform=Audio;%ID% "filename.mp4"
Use mp4box.exe and ID from above to extract audio track. Eg. with ID=1:
mp4box -raw 1 "filename.mp4" -out "filename.aac"
Compress audio track with ffmpeg.exe and fdkaac.exe
ffmpeg -i "filename.aac" -f caf - | fdkaac -b16 -I -p29 - -o "filename.m4a"
Remove old audio and video tracks and add a new compressed audio track
mp4box -rem 1 -rem 2 -add "filename.m4a" "filename.mp4"
Then someone else put it into batch:
@echo off
echo CBFT MP4 to SDVL converter
chcp 65001>nul
echo %~n1
setlocal
set mp4box=P:\progz\multimedia\gpac\mp4box.e xe -quiet
set ffmpeg=P:\progz\multimedia\ffmpeg\bin\ff mpeg.exe -hide_banner -v 0
set fdkaac=P:\progz\multimedia\fdkaac\fdkaac .exe
set mediainfo=P:\progz\multimedia\MediaInfo\ MediaInfo.exe
for /R %1 %%f in (*.mp4) do (
echo.
echo %%~nxf
if exist "%%~dpnf.aac" del "%%~dpnf.aac">nul
if exist "%%~dpnf.m4a" del "%%~dpnf.m4a">nul
for /f "tokens=1,2* delims=:" %%a in (
'%mediainfo% --inform^=Audio^;%%ID%%:%%Duration/String3%% "%%f"') do (
echo %%c
%mp4box% -raw %%a "%%f" -out "%%~dpnf.aac" )
%ffmpeg% -i "%%~dpnf.aac" -f caf - | %fdkaac% -b16 -I -p29 - -o "%%~dpnf.m4a"
%mp4box% -flat -rem 1 -rem 2 -add "%%~dpnf.m4a":name= "%%f"
if exist "%%~dpnf.aac" del "%%~dpnf.aac">nul
if exist "%%~dpnf.m4a" del "%%~dpnf.m4a">nul
)
endlocal
And it seemed to work by then, with mp4. Now it breaks in the ffmpeg part, here is my attempt to rebuild it until now:
echo CBFT MP4 to SDVL converter
chcp 65001>nul
echo %~n1
for /R %1 %%f in (*.mp4) do (
echo STARTING
echo %%~nxf
if exist "%%~dpnf.aac" del "%%~dpnf.aac"
if exist "%%~dpnf.m4a" del "%%~dpnf.m4a"
echo start ABOVE
echo mediainfo BELOW
pause
for /f "tokens=1,2* delims=:" %%a in (
'mediainfo --inform^=Audio^;%%ID%%:%%Duration/String3%% "%%f"') do (
echo %%c
mp4box -raw %%a "%%f" -out "%%~dpnf.aac" )
echo mp4box ABOVE
echo ffmpeg BELOW
pause
## This line should compress the audio stream ##
echo ffmpeg ABOVE
echo mp4box BELOW
pause
mp4box -flat -rem 1 -rem 2 -add "%%~dpnf.m4a":name= "%%f"
if exist "%%~dpnf.aac" del "%%~dpnf.aac"
if exist "%%~dpnf.m4a" del "%%~dpnf.m4a"
)
endlocal
Note that it's missing the stream compression section and that I removed fdkaac completely. I'm also guessing that the whole process could be done by a single ffmpeg command (plus the looping part), which would be specially useful when I try to get it to work with the .wmv files.
Could you give some directions on what I should do? That single ffmpeg command, if it is possible, or help me with multiple of them so I make them all work together?
To clarify: my goal is to reproduce steps 1 through 4 with ffmpeg. I believe there are capabilities to filter out streams and probably they're way more economic than this old code. How should I use ffmpeg for this?