-1

I don't know much about .bat files or ffmpeg and spent the last hour on the internet searching how I can solve my problem, but didn't find anything. I want to make .bat file which removes the audio of a video and replaces it with the no-audio version. I already made a folder with my .bat file and ffmpeg and added an option to the context menu to open my .bat file.

That's my .bat file currently:

ffmpeg -i %1 -an -vcodec copy %1

But ffmpeg can't overwrite the file it's currently reading. It would be great if somebody helps me how to create a temporary file without the audio, and then replace the input file with the temporary one.

Thanks a lot in advance!

  • 2
    Use the command modifiers to your advantage. Open up a command prompt and read the help file for the `CALL` command. `call /?`. I would just output the file with a different file extension and then do a rename after the file conversion is done. – Squashman Jan 05 '21 at 22:09
  • Modify the line to `ffmpeg.exe -i %1 -an -vcodec copy "%~1.tmp" && move /Y "%~1.tmp" %1 || del "%~1.tmp" 2>nul`. The output file is now the input file with `.tmp` appended to file name created in same directory as the input file. If `ffmpeg.exe` exits with `0` for a successful operation, the command `move` is used to delete the input file and rename the temporary file to name of input file. This operation does just change the file table in file system, no data is moved on hard disk. The temporary file is deleted on `ffmpeg.exe` exits with a value not equal 0 indicating an error condition. – Mofi Jan 06 '21 at 09:42
  • See my answer on [Single line with multiple commands using Windows batch file](https://stackoverflow.com/a/25344009/3074564) for a detailed explanation of `&&` and `||` and run in a command prompt window `move /?` and `del /?` for help on those two commands or read about them in the Microsoft documentation for the [Windows Commands](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands) or even better [SS64.com - A-Z index of Windows CMD commands](https://ss64.com/nt/). – Mofi Jan 06 '21 at 09:46

1 Answers1

0

A simple way to mute a video in FFmpeg is

ffmpeg -i input.mp4 -filter:a "volume=0.0" output.mp4

volume = 0.0 inciated making audio to 0

I recommend using Python to code as u need to take all files from a folder and mute them all.I will share a sample code

here is a .bat file which u can wite and which will run python file when u click it

#!/bin/bash
function edit_2x()
{
    python file_name.py
    TIMEOUT 10
}

file_name.py

import os
Folder_Path = r'K:\\to_mute\\'
Output_Folder_Path = r'K:\\muted_videos\\'

fileNames = os.listdir(Folder_Path)

for fileName in fileNames:
    if 'Done' not in fileName:
        print("File Name :"+fileName ) 
        os.system("ffmpeg -i "+fileName+" -filter:a 'volume=0.0' "+fileName);
        os.rename(Video_Path+fileNamee,Video_Path+"Done "+fileNamee)

A simple explanation to code is it takes all file names and stores them in a list and u will take one file and mute them and store them in another folder and updating the original file name with Done so there will be no further confusion. Hope its clear

Education 4Fun
  • 176
  • 3
  • 16