0

I'm using the following command in a batch file that I double-click in the folder containing the resp. webm video and m4a audio files:

for %%a in ("*.webm") do "C:\AVConvert\ffmpeg.exe" -i "%%~fa" -i "%%~na.m4a" -c:v copy -c:a copy -map 0:0 -map 1:0 "%%~na.mkv"

It works great and muxes webm with m4a audio into one mkv file. It even automatically batch-converts multiple webm/m4a files present in the same folder. Now, I wanna make the batch file available as one of multiple conversion options in the right-click context menu of media files in Windows Explorer.

Background: I have created a collection of ffmpeg batch files similar to the one above to convert between various media file types or losslessly extract audio streams from videos (among other features). For convenience, I organized the access to the batch files in cascaded context menu entries in the context menu of media files.

For now, all the batch files which are triggered when a user clicks on a context menu entry are of the following format: "C:\AVConvert\ffmpeg.exe" -i "%~1" -map_metadata 0 -codec:a pcm_s24le -write_bext 1 "%~d1\%~p1\%~n1.wav". The batch files work in whatever directory the media files are right-clicked and with as many files as the user had selected prior to triggering the right-click conversion option. Output folder is always the same as the input folder.

All batch files reside in C:\AVConvert\Batches, ffmpeg.exe is located in C:\AVConvert\. Various registry entries make the resp. batch files available in media file context menues. Problem is that the batch file containing the for loop above doesn't work when triggered via the context menu entry.

Sonic
  • 13

2 Answers2

0

Your request is still unclear for me but here is what you should begin to start with :


@echo off
Title Convert *.webm to *.mkv using Batch and ffmpeg
Set "MyFile=%~1"
If "%MyFile%"=="" ( 
    MODE 95,4 & Color 0C & echo(
    echo(    You should drag and drop any "file.webm" over this batch to be converted into "file.mkv"
    Timeout /T 10 /nobreak>nul & exit
)

Set "ffmpeg=C:\ffmpeg\ffmpeg.exe" Set "MKV_Folder_OutPut=%~dp0MKV_Folder_OutPut" If Not Exist "%ffmpeg%" color 0C & echo( & echo( "%ffmpeg%" dosen't exists Please check location of this program ! & Timeout /T 10 /Nobreak>nul & EXIT If Not Exist "%MKV_Folder_OutPut%" MD "%MKV_Folder_OutPut%" @for %%a in ("*.webm") do "%ffmpeg%" -i "%MyFile%" -c:v copy -c:a copy -map 0:0 "%MKV_Folder_OutPut%%%~na.mkv" pause & exit

Hackoo
  • 1,410
0

enter image description here

The windows registry will not manage its queue of objects (files) and connect them already managing the delivery to a bat file (cmd.exe), and at the same time monitoring the evolution of the events involved one by one during execution.

On the other hand, the cmd.exe (command interpreter), you will only receive a string with a complete path to your file, and in a single argument... which will point to a single file, the first in the queue, one line, that's all.

In the way you have been searching, it would be better to consider using Send To, where several items of the selection will be passed in another way (with multiplicity), as arguments...

  • To run only on the selected file, 1 per run, use:
@echo off

setlocal EnableExtensions 2>nul cd /d "%~dp1"|| goto :eOf

color 0a & mode 110,3 & title <nul title ..\FFmpeg 4AVConvertMuxVA ..%~nx0 & echo
set "_flags=-c:v copy -c:a copy -map 0:0 -map 1:0 -hide_banner -v error -stats"

if not "%~1" == "" for /f usebackq^tokens^=*delims^= %%i in (echo\ ^&amp; set /p &quot;'=%1&quot;^&lt;con: ^&lt;nul)do if exist "%%~dpni.m4a" "C:\AVConvert\ffmpeg.exe" -i "%%~i" -i "%%~ni.m4a" %_flags% "%%~ni.mkv"

endlocal

  • To run on all your mp4 files in the selected file folder, use:
@echo off

setlocal EnableExtensions 2>nul cd /d "%~dp1"|| goto :eOf

color 0a & mode 110,3 & title <nul title ..\FFmpeg 4AVConvertMuxVA ..%~nx0 & echo
set "_flags=-c:v copy -c:a copy -map 0:0 -map 1:0 -hide_banner -v error -stats"

for /f tokens^=^delims^= %%i in ('^<con: 2^>nul "%AppDir%where.exe" .:.webm ')do if exist "%%~dpni.m4a" "C:\AVConvert\ffmpeg.exe" -i "%%~i" -i "%%~ni.m4a" %_flags% "%%~ni.mkv"

endlocal


  • Windows registry entry for Menus with Submenu's in ContexMenuWsubMenu.Reg:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\SystemFileAssociations.webm\Shell\4AVConvertMuxVA] "MUIVerb"="4AVConvertMuxVA" "icon"="wmploc.DLL,-1110" "SubCommands"="Windows.01_M4A;Windows.02_M4A"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.01_M4A] "MUIVerb"="01_M4A" "icon"="wmploc.DLL,-1110"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.02_M4A] "MUIVerb"="02_M4A" "icon"="wmploc.DLL,-1110"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.01_M4A\command] @=""C:\Windows\System32\cmd.exe" /c >con: cd /d "%W" && "C:\AVConvert\Batches\WEBMV+M4AA.bat" "%V""

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.02_M4A\command] @=""C:\Windows\System32\cmd.exe" /c >con: cd /d "%W" && "C:\AVConvert\Batches\WEBMV+M4AA.bat" "%V""

This %~n1 does not work in Windows registry
Pipe multiple files into a single batch file using explorer-highlight

Io-oI
  • 9,237