Use FFmpeg to process a tree of MKV files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Styreman
Posts: 2
Joined: 04 Mar 2014 20:34

Use FFmpeg to process a tree of MKV files

#1 Post by Styreman » 04 Mar 2014 20:47

Hello all,

I'm very new to the batch code scene and have been familiarizing myself lately will all the commands. I've been struggling to create a batch code which does the following:

Scans folder for any *.mkv files (will only be 1 in folder)
Takes file location and file name
inputs this command (replacing FILENAME with name from file): ffmpeg -i FILELOCATION\FILENAME.mkv -c:v copy -c:a copy FILENAME.mp4
renames FILENAME.mp4 to FILENAME.avi

It's basically a rewrite of this code, but in DOS (mines using ffmpeg instead of avconv)

#!/bin/bash
#avconv --help
IFS=$'\n'
clear
for filename in *.mkv
do
echo "$filename"
newfilename="${filename%.mkv}.mp4"
echo "${newfilename}"
avconv -i $filename -vcodec copy -acodec copy $newfilename
done

Any help would be greatly appreciated!!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Batch code

#2 Post by foxidrive » 04 Mar 2014 20:57

Test this. It should create the AVI file in the same folder as the MKV folder.

Code: Select all

@echo off
for /r "c:\base\folder" %%a in (*.mkv) do (
   ffmpeg -i "%%a" -c:v copy -c:a copy "%%~dpa\%%~na.avi"
)

Styreman
Posts: 2
Joined: 04 Mar 2014 20:34

Re: Help with Batch code

#3 Post by Styreman » 04 Mar 2014 21:30

Works great!

Care to explain what this command is doing? %%~dpa\%%~na.avi

Thanks for the quick reply, I really appreciate it

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help with Batch code

#4 Post by Ed Dyreen » 04 Mar 2014 22:38

Styreman wrote:Care to explain what this command is doing? %%~dpa\%%~na.avi
issue /? on for

Code: Select all

>for /?

Code: Select all

% ~ dI - expands% I to a drive letter
% ~ pI - expands% I to a path
% ~ nI - expands% I to a file name
you used `a` as token, so %%~dpa expands `a` to a drive and path

Post Reply