1

To extract audio from a .webm file, using the ffmpeg tool:

ffmpeg -i "input.webm" -acodec copy "output.opus"

The command above works perfectly, however it extracts only one file at the time. What would be a command to extract all .webm files in specific directory, keeping the original names of the files and only changing the file extension from .webm to .opus? I also need to extract .aac audio from .mp4 files using ffmpeg. What would be the proper command for that?

2
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Nov 2, 2022 at 3:28
  • Hi, Superuser works best if you only ask one question per Question post. Can you edit your Question post down to a single question?
    – Spiff
    Nov 2, 2022 at 3:38

1 Answer 1

2

Something like this:

for %a in (*.mp4 *.webm) do if "%~xa"==".webm" (ffmpeg -i "%a" -acodec copy "%~na.opus") else (ffmpeg -i "%a" -acodec copy "%~na.aac")

To do each type individually:

mp4:

for %a in (*.mp4) do ffmpeg -i "%a" -acodec copy "%~na.aac"

webm:

for %a in (*.webm) do ffmpeg -i "%a" -acodec copy "%~na.opus"
2
  • Thank you. The .mp4 and .webm files are in a separate directories, so I would prefer to extract one file type at the time. Are the commands below correct?___1. webm to opus: for %a in (.webm) do if "%~xa"==".webm" (ffmpeg -i "%a" -acodec copy "%~na.opus") ___2. mp4 to aac: for %a in (.mp4) do if "%~xa"==".mp4" (ffmpeg -i "%a" -acodec copy "%~na.aac")
    – Zen99
    Nov 3, 2022 at 6:01
  • Please see updated answer.... Nov 3, 2022 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .