Mathew Inkson

Converting .Wtv to .Mpg in Windows 7

  |   technology

Update 2014-02-25: As Marc has said in a comment below, ffmpeg now supports wtv files natively, so the dvr-ms step is unnecessary. I no longer use this process at all so I haven’t updated it, but will leave it here for posterity.

I use a PlayStation 3 to watch TV programmes recorded in Windows 7.  The media sharing functionality in 7 is much better than in Vista, and it’s quite simple to share the Recorded TV folder and watch .wtv files on the PS3. However, I prefer to convert the .wtv files to .mpg, and use the excellent PS3 Media Centre to serve them. In my experience, .wtv files on the PS3 are:

The WTV format is relatively new, having replaced the DVR-MS format that Windows used previously. Windows 7 provides the functionality to convert .wtv files “back” to .dvr-ms files, and to do so is as easy as right-clicking the source file and selecting “Convert to dvr-ms Format”. This is crucial functionality since, while WTV is completely new, DVR-MS is based on the well-known ASF format. This makes it easy to retrieve the core MPEG2 data.

To produce a .mpg file from a .dvr-ms file, we can use ffmpeg from the command line:

ffmpeg.exe -y -i "showname.dvr-ms" -vcodec copy -acodec copy -f dvd "showname.mpg"

Here are the options explained (taken from ffmpeg’s documentation):

-y              overwrite output files
-i filename     input file name
-vcodec codec   force video codec ('copy' to copy stream)
-acodec codec   force audio codec ('copy' to copy stream)
-f fmt          force format

Essentially I’m telling ffmpeg to copy the audio and video streams just as they are, and to put them into DVD format (MPEG2). It doesn’t perform any re-encoding, so it quickly produces a nice .mpg file that plays natively and perfectly on my PS3.

I quickly tired of having to complete a two-step process  to watch a TV show, and I wrote a batch script to do the lot at once. For each .wtv file in my Recorded TV folder, it will:

To use this script just paste it into a .bat file and change the paths accordingly. You shouldn’t need to change the value of wtvconv.

@echo off
 
set recordedtv="D:\Recorded TV\"
set destfolder="D:\taped\"
set ffmpeg="C:\programs\ffmpeg\ffmpeg.exe"
set wtvconv="C:\Windows\ehome\WTVConverter.exe"
 
for %%f in (%recordedtv%*.wtv) do (
  %wtvconv% "%%f" "%%f.dvr-ms"
  %ffmpeg% -y -i "%%f.dvr-ms" -vcodec copy -acodec copy -f dvd "%%f.mpg"
  del "%%f.dvr-ms"
  move "%%f.mpg" %destfolder%
)

I have thought about having it delete the .wtv files, too, but I prefer to check that the conversion has worked before deleting them manually. On rare occasions the process has failed with no explanation, but simply running it again has done the trick.

A couple of caveats, now. I have found that recent versions of ffmpeg sometimes fail during conversion with “error, non-monotone timestamps.” I found a solution from another blogger, who suggested downloading an older version from here. I don’t know why or how, but this works for me.

Secondly - and seemingly only when converting high-def video - ffmpeg sometimes complains, “packet too large, ignoring buffer limits to mux it”, yet still appears to do the job correctly. I assume that this has something to do with the default buffer size used in DVD creation, but I haven’t found a way to fix it. It doesn’t seem to cause any problems, but for completeness’ sake I’d like the solution. Please let me know if you can help!

Finally, I anticipate the question, “why don’t you just use a program that records directly to .mpg?” Well, I have. I’ve used GB-PVR, for example, and combined it with a variety of multiplexers. To my eyes the quality has never matched the output produced by Windows Media Centre. This has more to do with the multiplexers than the application, of course, but I also prefer using Media Centre to browse and schedule recordings. This is the best solution I’ve found to suit my preferences (so far).

Last updated February 25, 2014


Comments

Comments are no longer supported—please contact me elsewhere.
The following have been migrated from an old site and may have formatting errors.

Qman

Does the mpg format support the recorded show information, ie the description that comes down via the EPG data? Anyway way to convert with that tag info maintained?
Mathew's gravatar

Mathew

I don’t think this is possible with the .mpg format, which is quite basic. If you were to use a richer container format like .mp4 or .mkv you would be able to add metadata using the following option (taken from the ffmpeg documentation):

“-metadata key=value” Set a metadata key/value pair. For example, for setting the title in the output file: ffmpeg -i in.avi -metadata title=“my title” out.flv

There’s probably an easy way to retrieve this data from the .wtv and then use the above command to insert them, but I don’t know how.

I convert to .mpg because of the excellent native performance on the PS3. Rather than convert to something like .mkv, which would have to be transcoded, I’d just use the original .wtv file. Having no metadata is a tradeoff I choose to make.

Spooky

I get a lot of “buffer underflow” errors while ffmpeg runs. The resulting mpg file plays quite choppy, seems to be that several frames are missing. The source file is recorded with Windows 7 Media Center and a DVB-T USB stick.

Do you have any ideas?

Mathew's gravatar

Mathew

Spooky: I get the same errors (scrolling down the command window in the hundreds). I spent a while searching for a fix but couldn’t find anything definite. This is a typical list of responses: http://forum.doom9.org/archive/index.php/t-132773.html

Manually setting the buffer size doesn’t seem to make any difference: as someone says in the above link perhaps the copy mode ignores the bufsize flag completely. I gave up on the issue because it doesn’t seem to make any difference for me. The videos I have produced are fine so far; they run well in MPC-HC in Windows 7 (http://mpc-hc.sourceforge.net/) and on my PS3 via PS3 Media Centre. Is playback any better for you in other programs?

Anyway, the buffer underflow may or may not be the issue in your case. There could be something different about your source file or your version of ffmpeg that wasn’t apparent for me. I wouldn’t have thought that the DVB-T stick would be a problem, because Media Centre takes the raw input from whatever hardware and produces the same type of file. Or maybe it does something that I’m not aware of depending on the source?

This is all just guessing, though. I wish I could help. Please let me know if you fix it and/or the buffer underflow warnings.

Bob

Hi There,

This was a TOTALLY helpful post. The one last barrier I’m experiencing is I’m trying to copy the resulting movie file to a USB key to play on my PS3 and some of the files are bigger than 4GB (max size supported by FAT32 which is the only thing PS3 supports).

Can you recommend a good MPEG2 splitter program? I’ve literally tried something like 10 of them off the web and none of them have done the job right. Thanks in advance!

Bob bobspam@yahoo.com

Mathew's gravatar

Mathew

Bob: Glad it helped! I’ve never had your particular problem because I play my media over my home network.

I haven’t done much video editing stuff so I can’t help you there. I do hear that all the cool kids use avidemux. Have you tried it? There’s a Windows version. http://fixounet.free.fr/avidemux/

Kosh

Thanks, it works! The older version of ffmpeg at any rate, the latest versions do not, and not with the error message you reported.

@Bob: stream the .mpg video direct to your PS3 using WMP or TVversity or some other media server using a (W)LAN connection. (Wired is superior.)

Mike

A slightly belated question but can anyone please explain how to change the code posted above so that I might convert to a different format such as avi or even mp4 ?

I’m not well versed in using the command options of ffmpeg as you may have gathered.

many thanks,

Mike.

Mathew's gravatar

Mathew

Mike: I’m not an expert, but this is the most straightforward guide I’ve found on using ffmpeg to convert video formats. Perhaps it can help you out with picking the correct options?

http://www.linuxjournal.com/article/8517

The line (in my code) that you’ll want to change with help from the above examples is:

%ffmpeg% -y -i “%%f.dvr-ms” -vcodec copy -acodec copy -f dvd “%%f.mpg”

Mike

many thanks Matthew for taking the time to forward the link…:)

resago

make powershell run in remotesigned mode by typing “powershell Set-ExecutionPolicy RemoteSigned” at the start bar

you may have to run powershell as administrator to the above command to work

Set-ExecutionPolicy RemoteSigned

Mathew's gravatar

Mathew

resago: Thanks, that’s very useful.

bob sagget

Doe snot work for me. I copy pasted that line of code into the CMD prompt, and made sure the filenames matched, then it spit out a lot of junk and ends with this error almost immediately…

“file.dvr-ms: Unknown format”

then just returns to the prompt. HELP!!

Mathew's gravatar

Mathew

full house: do you mean this line?

ffmpeg.exe -y -i “showname.dvr-ms” -vcodec copy -acodec copy -f dvd “showname.mpg”

If so, maybe the version of ffmpeg you have doesn’t support dvr-ms?

Malcolm

I know that it’s a long time since you wrote this, but I just stumbled upon it today. I understand what you say, and I specifically want to convert HD .wtv files to another format.

However you describe a 2 stage process - firstly convert to DVR-MS and then convert that to MPEG. But in my experience you cannot right click a HD WTV file and convert to DVR-MS (works ok for ’normal’ WTV files.)

And yet reading your instructions, the convert to DVR-MS does seem to work for your HD files - is this really the case? Thank you

Mathew's gravatar

Mathew

Malcolm: Yes, it works for both SD and HD for me me, BUT something that I have only just discovered is that in Australia (where I am) both SDTV and HDTV is broadcast in MPEG-2, because the specs were set at the same time (back in 2000), whereas the US and UK phased in their approach and went with the superior H.264 for HD.

So (depending on where you are) your SD and HD WTV files are probably in different formats, whereas my SD and HD files are all MPEG-2. This method is about retrieving the core MPEG data in the file, but if the WTV contains H.264 data it would explain why it won’t work for you.

I’ll update this post to say that, but as you said this is getting pretty old, now. I’m sure that others have come up with better ways of doing it. Good luck!

Dave

Thank you so much - I couldn’t find a way past the “non monotonic timestamp” issue.. you saved me a lot of time.

Fred

I realize that this post is old, but ffmpeg can handle .wtv files without converting to .dvr-ms. Simply call:

ffmpeg -i inputfile.wtv -vcodec copy -acodec copy -f dvd outputfile.mpg

Mathew's gravatar

Mathew

in reply to Fred

Thanks Fred; when I first did this there was only rudimentary support, and wouldn’t work for my files. I’ll have to give it another go soon.

al

got this about 25 seconds in DTS 16337792918, next:1633843067 st:1 invalid droping [dvd @ 0000000001FC6640] pts < dts in stream 0 av_interleaved_write_frame(): Invalid argument

newbeginboy

i just find a video tutorial on how to convert wtv to avi, mp4, wmv, mov, mkv, 3gp or even edit wtv files hope it also helps for you at http://www.youtube.com/watch?v=FSVjePYXH-g

Marc

You may wish to update your article. wtv files are now natively supported in ffmpeg. So there’s no need to use the dvr-ms format at all. Just feed the wtv file directly into ffmpeg. HTH.
Mathew's gravatar

Mathew

in reply to Marc

Thanks, I haven’t used my playstation for years so I haven’t thought about this lately. Will update it accordingly.

Torzaisonway

Faasoft Video Converter can do this job for you. It can convert wtv file to mpeg to play wtv file on Windows 7.

Jonathan

What a waste of space and a piece of garbage, this batch file does nothing. ABSOLUTELY NOTHING!!!! NO ERROR, NO MESSAGE, NO ACTION, JUST NOTHING!!!!!!

Why is it so impossible to make a working file out of this bs format that windows insists on forcing on us, yet no one else will support?

Please, for the love of god, idiots, STOP CLOGGING UP THE INTERNET WITH POINTLESS GARBAGE THAT DOESN’T WORK AND JUST WASTES MY TIME