Batch Convert WTV files to DVRMS and MPEG
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.batSET 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.batSET 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.
Thanks very much for this, I’ve been searching for a while for a good way of converting those useless WTV files.
Being a complete novice at DOS I used your first two batch files in a folder containing 6 wtv files. Ran the Convert .bat and all I get is a quick flash of the DOS screen. I cant see what the error is but it doesnt work for me. Am I supposed to change the Convert file in some way ?
Hi Jono! You may need to edit the scripts to ensure that the drive letters (for example) work for you. I used D: because I have a D drive. You may not. Do make sure DVRMSToolbox is installed in the path specified as well – or the script can end up deleting your wtv files alltogether (as I discovered last week after reinstalling Windows 7). Finally – if you run the batch file from a command prompt rather than just double clicking on it in Windows Explorer – you’ll be able to see any error messages. Best of Luck!
Be VERY cautious using this method… and remember to back up the original files just in case. I failed to do so, and lost a whole bunch of music videos I recorded because the files get deleted and DO NOT go to the recycle bin. Recovery software didn’t help either. Just a warning… don’t be stupid like I was, and BACKUP the data first!
Brad
Hi Brad! Yeah – I did exactly the same thing after a re-install. And kicked myself for not testing on a test file too! Sorry you lost your stuff. What the script needs is an IF EXISTS clause around the DELETE call to ensure that the output was created before deleting the input. That would make it safe with respect to script/path errors. Sorry again!
Thanks for the help and advice. I’ve got it working now the third batch file and DVRMSToolkit and it is by far the simplest method of batch converting to mpeg from wtv I’ve come across.I did a few test runs first and yes I did have files deleted and unrecoverable but when it set up right ir works great.I can highly recommend this method as a free conversion tool.
Thanks
Hi Guys – thanks for your feedback – note to self: not the best way to do testing – still, I’ve updated the scripts above so that in the event of an installation or path error, the input file will be left intact. Thanks for your help.
Thanks for an extremely useful and simple (since I happen to remember how to create/use batch files) way to convert to dvr-ms and mpg format.
Two things that happened to me on the way:
1. I needed a file called “comdlg32” in the c:\windows\syswow64 directory to use the dvrms toolkit
2. It has to be registered on the cmd line (in administrator mode)
Now a question–the converter for .wtv to .dvr-ms works in batch mode works, but the .dvr-ms to mpg requires me to enter a file name for each file converted — anyone know how to make that a batch process ?
Thanks, Rich
Two additional notes about my post:
1. the full filename is “comdlg32.ocx”
2. i have 64-bit windows 7–for those with 32-bit, the file goes in c:\windows\system32
Rich
Hi Rich – Unfortunately I’ve not seen the two issues that you had so I can’t offer any answers. The script as it stands should automatically use the stem of the existing dvrms filename when it creates the mpg – so it if isn’t, then that’s weird. Could you maybe post a sample filename that caused the problem? I’m thinking maybe there are some unusual characters in it.
Thanks, Danny
Hi Danny, I’m interested to know how long a conversion takes. Say for instance on a 15GB dvr-ms file?
Is it any quicker than MCEBuddy?
Thanks for sharing your efforts with us all.
Dave
No idea! I can only suggest that you test it. MCEBuddy looks pretty cool though – particularly if it can get ad removal reliably right.
I have some files with the ‘&’ character in them and its confusing the batch file.
an example name is
“Thomas & Friends_KOPBDT2_2011_01_25_14_28_36.wtv”
here is the output i get when i try to process that file.
I added some echo statements and the issue is in the wtvrunner.bat script but I’m a linux guy and am hoping someone will take pitty on me and tell me how to fix this easily?
“Create wtv file list…”
“Process wtv file list…”
In wtvRunner
‘Friends_KOPBDT2_2011_01_25_14_28_36.wtv’ is not recognized as an internal or external command,
operable program or batch file.
infile Thomas
outfile Tho – DVRMS.dvr-ms
“Cleaning Up”
Thanks!
Oooh – that’s a tricky one! DOS scripts are a bit of a black art in all honesty, so there’s a good chance this one isn’t trivial.
The short answer is that I will probably have to solve this at some point but I’m very short of time at the moment.
The poor man’s solution of course would simply be to rename the files removing the &. Not great but should keep you going for the time being.
The problem with & in filenames is that it causes the script to think this is a new command. You need to escape the and with ^.
e.g. & -> ^&
This is an update to part of the script
Setlocal enabledelayedexpansion
echo “Process wtv file list…”
for /f “usebackq delims=” %%a IN (d:\wtvlist.txt) do (
set file=%%a
set file=!file:^&=^^^&!
call wtvrunner.bat “!file!”
)
I’ve not tried my updates but the end result should be that the & are escaped in the call to the second script.
Dave, that is phenominal work. I’m absolutely slammed this month, but when I get some time I shall try to run it up and all being well – update the script in the main article to match.
Many thanks to you!
TIP: For anyone saying the DOS window flashes then goes away just add PAUSE as the last line in your command BAT or CMD text files so they pause for a key-press at the end before going away. Helps to debug issues with syntax or other mistakes while debugging new batches.
Anything quicker than MCEBuddy?
Not really. The slow reports are usually going to some other format besides MPG. If you simply go from DVRMS to MPG it is blazingly fast. I’ve watched it rip through 6 gig full size movie length recordings in a minute or two – no effective change in size or loss of quality tells me this is not recoding but simply rebuilding/remuxing the “wrappers” with direct stream copying. This is what you want (or what I want anyway to simply be rid of the useless WTV DVRMS format wrappers. If I wish to further archive a show from the MPG format I have many batchable MPG>AVI options such as pocketdivx4 which include two-pass and excellent choices for choosing your personal level of quality or small size that suits your viewing best.
Great work. I have been looking this for a while.
Thanks Danny.
This worked a treat – thanks for all your work 🙂
Now to go read and find out how to make the adverts dissapear 😉
Thanks ‘danny’ for posting this blog.
With Microsoft killing off WMC I fear one day I will be unable to register my Win 7 Home Premium version even if I did manage to re-install it after another forced downgrade to Win10. Therein goes my 1,000s of DRV-MS and WTV formatted files.
I’ve been using Windows Media Centre since Windows XP MCE edition. I have a simple USB free-to-air tuner, Green Button IR remote control, and survived using just the free-to-air Electronic Program Guide. It’s been a wonderful companion to my children, their grandparents and my parter and I for a long time.
So much for loyalty!
These batch files allows us to to convert our WMC Recorded TV files by simply stripping off the Microsoft ‘special’ bits and leaving just the raw MPG portion. These take just minutes per file – not the hours of those other ‘conversion’ software!
I made a small change; to make it easier, the batch files have to sit in the same directory of your WTV files – so make a new directory and copy a handful of WTV files there in case there is a problem; and there is a time start and time end entry so you can track how how it’s taking. (My files are at this link http://tinyurl.com/wtv2mpg).
Speed depends on your computer’s CPu availability and power (if the CPU is busy “running” malware in the background, it;ll take longer of course). In my case each 30 min file took under 2 minutes.
So, so long Microsoft: no more dollars from my family and friends to you anymore. You’ll be extinct like the dodo soon. Good riddance.
It feels good to NOT have any more Microsoft products in our home!
These converted files in MPG format now sit on a Linux PC with Emby Server running.
I use a browser from any other PC (Linux, Mac or Windows), iOS or Android device and view them without so much as a blink of an eyelid transcoding is done on the fly on the Emby Server (note, you don’t need to use the paid Emby app).
On a iPhone there’s no need to view in super hi-res, pick a lower resolution and Emby Server streams that to you.
My next challenge? Setting up a PVR with free-to-air EPG series recording capability! Anyone with experience, please share your pain and tips here, thanks.
Re: Win & Home Premium and the forced upgrade to Windows 10. I haven’t investigated this yet, for reasons to complicated to explain here, my Media Centre has been in the “off” position for the last year. However it will be coming back to life in another couple of months. I would imagine there will be ways to permanently switch off / hack out the Windows 10 upgrader so that you can stay on Windows 7. For example http://www.pcadvisor.co.uk/how-to/windows/how-stay-on-windows-7-8-forever-stop-upgrade-notifications-3614204/
Best of luck – I’m also a massive / long time fan of MCE. Unfortunately for Microsoft, it simply hasn’t been commercially successful for them.
bwhahahah i remember batch files.. anywAY I still use mce and decided i wanted commercials gone (lifeextender). nothing is supported anymore, need baTCH conversion of wtv to dvr-rs or whatever…\
\
from cmd copy con convtall.bat
..
..
..
^Z
haven’t done that since 1994 or something.. works a treat tho well done lol
oh and you can setup a windows7
“event” rather than filewatcher to monitor new wtv files. its a little cleaner i guess.