asftopipe: extract audio and video from WMA, WMV and ASF files

What is asftopipe?

asftopipe is a simple, open-source Windows utility that extracts audio and video streams from Windows Media ASF files, such as .WMV and .WMA files. Video streams are extracted as a continuous stream of PPM-format images. Audio streams are extracted as raw PCM samples. Both can then be written to named pipes, avoiding the need for gigantic files on disk. Key details such as the audio sample rate, video frame rate, audio sample size and number of audio channels are also available.

What's new in version 1.01?

Version 1.01 corrects a bug that caused the program to crash if the -cf option was not given. Thanks to ernes for the bug report.

Also, version 1.01 correctly displays the "Ready" line in the case when only audio is requested and the -i and -if options are absent.

Why is asftopipe useful?

Many open source tools exist to encode audio in video in a variety of formats. Unfortunately, these tools currently can't handle the latest Windows Media formats as input. This makes converting Windows Media 9 files to FLV (Flash Video) and other formats a pain.

asftopipe uses the Microsoft Windows Media API to read the file, so it supports all current types of ASF (WMA and WMV) files. For instance, asftopipe has no trouble reding a video created by Windows Movie Maker.

asftopipe also has convenient features that make implementation of progress displays and termination of a cancelled file conversion easier to accomplish without advanced win32 programming.

Will it be ported to Linux/MacOS X/etc.?

No, it doesn't make sense because asftopipe's purpose is to read from video files using the Windows Media APIs, which don't exist on those operating systems. This is a short, sweet, simple utility, not an independent reimplementation of the Windows Media codecs. If you want to read the latest Windows Media formats on a non-Microsoft OS, I suggest you start contributing code to the ffmpeg project, which already directly supports some older Windows Media formats.

How would I use asftopipe?

First, launch asftopipe to write the audio and video data to named pipes. You pick the names - make sure they are unique so they don't conflict with other instances of the program. Then, launch ffmpeg (or lame, or possibly mencoder...) to read from those pipes. ffmpeg and friends don't need any special changes to support named pipes - any Windows program can access an existing named pipe without special code.

Consider the following example:

To convert wmv (from Windows Movie Maker, for example) to flv (Flash Video) with ffmpeg:

1. Start asftopipe at one cmd prompt (this is all one command line):

asftopipe mymovie.wmv -i -ap \\.\pipe\audiopipe_xxxxx -vp \\.\pipe\videopipe_xxxxx -ac 1

2. Note the fps: setting printed by asftopipe as a result of the -i (info) option. Practical conversion scripts and applications will read this output from an infofile created by using -if instead of -i, and set the -r option of ffmpeg to match.

3. Wait for Ready to appear (in a script or application, wait for the infofile to appear, and make sure it ends with the word Ready on a single line).

4. At a separate cmd prompt (again, all one line):

5. ffmpeg.exe -r 30 -f image2pipe -vcodec ppm -i \\.\pipe\videopipe_xxxxx -f s16le -ar 22050 -ac 1 -i \\.\pipe\audiopipe_xxxxx -ab 56 -b 500 -f flv -vcodec flv test.flv

For complete documentation, just read the output of asftopipe -h | more at the cmd.exe prompt.

Where do I download asftopipe?

Click here to download This zipfile contains both asftopipe.exe and the complete Visual C++ 2003 project to recreate it.

You will need to install the Windows Media Format SDK if you wish to recompile asftopipe.exe from source! You can download the Windows Media Format 9.5 SDK here on Microsoft's site.

Great! But where do I get ffmpeg for Windows?

For legal reasons, ffmpeg binaries for Windows can be tough to find. However, Soenke Rohde's excellent HOWTO covers how to compile it yourself using the freely available mingw compiler system for Windows.