Converting .wtv to .mpg in Windows 7

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:

  • Slow: I find that fast-forwarding or using the “scene search” functionality lags much more than when watching .mpg files.
  • Not pretty: To my eye, .wtv files are blockier (on the PS3) than the .mpgs I create.
  • Bigger: 3.5 hours of HD Sunday Night Football creates a .wtv file of around 20GB. After converting to .mpg the file is about 18GB. This is trivial with the cost of storage at the moment, but it’s interesting nonetheless.

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:

  • Create a temporary .dvr-ms file from the .wtv file (using the core WTVConverter program provided by Windows 7)
  • Create a .mpg file from the .dvr-ms file (using ffmpeg)
  • Delete the .dvr-ms file
  • Move the .mpg file to a different directory

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).

29 thoughts on “Converting .wtv to .mpg in Windows 7

  1. 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

  2. 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.

  3. Pingback: Window 7 Tech | Converting .wtv to .mpg in Windows 7 | i reckon

  4. 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

  5. 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

  6. 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!

  7. 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

  8. Pingback: .Wtv to Wmv With Embedded Subtitles

  9. 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?

  10. 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!!

  11. 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

  12. rename wtv based on metadata. this powershell script should fill the gap.

    /code

    ## metaname.ps1 ##
    # get the Toub.MediaCenter.Dvrms.dll from the dvrms toolkit site and save in in c:\
    # if you save it somewhere else, change the path below
    [void][System.Reflection.Assembly]::LoadFile(“C:\Toub.MediaCenter.Dvrms.dll”)

    # set the vars below to fit your situation
    $source=”e:\recorded tv”
    $target=”e:\recorded tv”

    # this loop gets the Title, Subtitle, and Description from each wtv file and renames it
    foreach ($file in gci “$source\*.wtv”) {
    $wtv = New-Object Toub.Mediacenter.Dvrms.Metadata.DvrmsMetadataEditor($file)
    $attrlist = $wtv.GetAttributes()

    # you can add or remove other metadata as you see fit
    $t = $attrlist[“Title”].value -replace(“:”,”-“)
    $s = $attrlist[“WM/SubTitle”].value -replace(“:”,”-“)
    $d = $attrlist[“WM/SubTitleDescription”].value -replace(“:”,”-“)

    # the multiple moves below handle cases of duplicates and long descriptions, only one will actually work.
    move “$file” “$target\$t-$s-$d.wtv”
    move “$file” “$target\$t-$s-$d-2.wtv”
    move “$file” “$target\$t-$s-$d-3.wtv”
    move “$file” “$target\$t-$s.wtv”
    move “$file” “$target\$t-$s-2.wtv”
    move “$file” “$target\$t-$s-3.wtv”
    }

    /code

  13. 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”

  14. 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.

  15. 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.)

  16. 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

  17. 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.

  18. 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?

  19. 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.

  20. 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?

Leave a Reply