Copyright 2009-2012 by djg. All Rights Reserved.

Wonky Gibbon Ramblings



Batch Convert WTV files to DVRMS and MPEG 23

Posted on August 19, 2010 by danny

When Microsoft released Windows 7 / the TV Service Pack for VISTA, they changed the file format from dvr-ms, as used in MCE 2005 to a new wtv format.

What does this new wtv format do for us that dvr-ms did not? Well that’s probably a subject for wikipedia, but for those of us watching Freeview in the UK – not a lot.

However what it does do, is stop us using other nice utilities such as DVRMSToolbox plus wtv files are half as big again as the dvr-ms files they replace. So a 3GB wtv file is equivalent to a 2GB dvr-ms file. Or to put it another way, that 1TB drive you bought so you could keep lots of shows, is now only worth 666GB. Which sucks.

So I want to convert my wtv files to dvr-ms files.

A very easy solution is simply to right click on the wtv file and select the option “Convert to .dvr-ms” format. However this has to be done one right click at a time (there’s no multi select) and rapidly becomes very tedious.

DVRMSToolbox with a bit of profile tweaking and using it’s FileWatcher feature can be made to do it automatically for you – but it is a bit fiddly to setup, and you have to have FileWatcher running continually.

However you can automate the whole process using DOS batch files. And if you want it to run periodically, use the Windows Scheduler service to kick it off, say, daily in the middle of the night.

So what would such a batch file look like? Well – this did take a couple of hours and a bit of research as my DOS batch scripting skills aren’t all that great – hence why I share it here.

ConvertAll.bat
@echo off

echo "Create wtv file list..."
dir /b *.wtv > d:\wtvlist.txt

echo "Process wtv file list..."
for /f "usebackq delims=" %%a IN (d:\wtvlist.txt) do call wtvrunner.bat "%%a"

echo "Cleaning Up"
del d:\wtvlist.txt

Drop the batch file into the directory you want to convert.

It works by creating a temporary file list in a txt file and looping through each entry in that file and passing it to a second batch file called “wtvrunner.bat”.

The wtvrunner.bat file then calls the standard windows utility for converting from wtv to dvr-ms (the same one used by the right click method above), converts the file and (if the output file was successfully created) deletes the wtv original. It’s a good idea to delete the wtv files as you go along rather than with a single del *.wtv at the end as it greatly limits the amount of free disk space required to convert a batch of files.

wtvrunner.bat
SET infile=%~1
SET outfile=%infile:~0,-4%
SET "outfile=%outfile% - DVRMS.dvr-ms"
echo %outfile%
c:\windows\ehome\WTVconverter.exe "%infile%"
IF EXIST "%outfile%" del "%infile%"

(NB: wtvconverter.exe is not available on Windows XP. Copying it onto an XP box doesn’t work either as it relies on other Windows 7 assemblies. So this is really Windows 7 only).

That works well then. Double Click the ConvertAll.bat file and a whole directory of wtv files gets converted to dvr-ms files.

However for other reasons, my workflow required me to then convert all the dvr-ms files to mpg files. So now I needed to add to the scripts to use DVRMSToolbox to do the conversion from dvrms to mpg.

So now ConvertAll.bat looks like this:

ConvertAll.bat
@echo off

echo "Create wtv file list..."
dir /b *.wtv > d:\wtvlist.txt

echo "Process wtv file list..."
for /f "usebackq delims=" %%a IN (d:\wtvlist.txt) do call wtvrunner.bat "%%a"

echo "Create dvr-ms file list..."
dir /b *.dvr-ms > d:\dvrmslist.txt

echo "Process dvr-ms file list..."
for /f "usebackq delims=" %%a IN (d:\dvrmslist.txt) do call dvrmsrunner.bat "%%a"

echo "Cleaning Up"
del d:\wtvlist.txt
del d:\dvrmslist.txt

This introduces a third batch file called “dvrmsrunner.bat” which handles the conversion of the dvr-ms files to mpg’s using DVRMSToolbox. This looks like this:

dvrmsrunner.bat
SET infile=%~1
SET outfile=%infile:.dvr-ms=.mpg%
"C:\Program Files (x86)\DVRMSToolbox\DVRMStoMPEG.exe" /if="%infile%" /of="%outfile%" /p=16384 /act="ffmpeg"
IF EXIST "%outfile%" del "%infile%"

Again this deletes the input files (if the output was successfully created) as soon as the conversion is finished to save space.

Job done.

NB: Scripts updated to only delete input files on success.

References:

Jim 2.5’s Blog – Article on DOS loops
John John’s post from this thread on looping through lists of filenames that have spaces in.
This article on dos string manipulation for replacing .dvr-ms extension with .mpg
macdad’s post from this thread on stripping off three character file extensions from file names.



↑ Top