Feb 15

Building ffmpeg to support Windows Media files

Tag: GeneralRichard @ 1:07 am

Update: 8/11/06
Multimedia Mike msged me to say:

“I just wanted to point out that it may be helpful to amend that post to note that the current SVN copy of FFmpeg contains a native VC-1 decoder; no more painful hack to get the slooooow reference decoder working”

So hop on over to his site for more information :)

This post is for uber geeks, so move on if that’s not you :)

While using Gallery 2.1 for my photo gallery I finally got around to start uploading movie files as well as pictures. Being lazy, and wanting a small, compatible file type that most of my family could play, I opted to use Windows Movie Maker to output .wmv files. They come out pretty small, with great quality, and anyone on Windows (and some Mac/Linux users) can play them.

Well, lo and behold, the Gallery uses the ffmpeg module for generating thumbnails of the video files, and the current ffmpeg builds/CVS can’t handle later versions of Windows Media encoded (wmv3/wmv8/wmv9) video. Luckily, I was able to find a hack for it that got me going, and I’m re-posting it here for posterity (and when I lose my binaries and need to build them again).

(Caveat: my web host allows compilation from source; yours may not, and you may be out of luck if so. Unfortunately the binary I built is for x86_64 and probably not useful to many so I am not going to post it here.)


Hooking Up The SMPTE VC-1 Decoder In FFmpeg

Filed under:
Open Source Multimedia — Multimedia Mike @ 5:22 pm

Some people have asked me for my code to make the SMPTE VC-1 reference decoder work with FFmpeg,
slow though it may be. I suppose I could make a patch. But the official
version of FFmpeg is whatever happens to be in CVS at the current
moment. So any patch I could produce would work for maybe a day. So get
ready to do a little editing on your local FFmpeg CVS tree. The steps:

  1. procure the VC1_reference_decoder_release6.zip file from the main site and unzip the tree somewhere
  2. have a copy of FFmpeg’s CVS tree handy; the rest of these instructions will assume that you are sitting in the root of the FFmpeg tree
  3. create a directory called libavcodec/libvc1
  4. copy all of the *.c and *.h files from VC1_reference_decoder_release6/decoder/ into libavcodec/libvc1/
  5. copy all of the *.c and *.h files from VC1_reference_decoder_release6/shared/ into libavcodec/libvc1/
  6. place the libvc1-makefile.txt into libavcodec/libvc1/Makefile
  7. change directory into libavcodec/libvc1 and type ‘make’
  8. change directory back to the FFmpeg root
  9. place the smpte-vc1.c file into libavcodec/
  10. edit
    libavcodec/vc9.c, go the very end of the file, and add #if 0/#endif
    around the wmv3_decoder AVCodec structure; this will keep it from
    conflicting with the new SMPTE WMV3 decoder
  11. edit libavcodec/Makefile and add smpte-vc1.o to the end of the OBJS list
  12. edit the top-level Makefile and add “-L./libavcodec/libvc1 -lvc1″ (without the quotes) to FFLIBS
  13. run ‘./configure’ at the top level if you have not already done so for this tree
  14. run ‘make’ at the top level

Now, there’s also a magic step 12.5 that I had to do, which was edit the libavcodec/allcodecs.c and uncomment the section about wmv3. If you don’t, the wmv3 support won’t get compiled and this will all be for naught!

Big thanks to merbanan on #ffmpeg (irc.freenode.net) for assistance with getting this going!

I’ve also linked the reference decoder zip file locally if you can’t find it anymore…

Technorati Tags: , ,

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon] Sphere: Related Content

48 Responses to “Building ffmpeg to support Windows Media files”

  1. scott free says:

    Note for anyone who may have tripped on it:

    11. edit the top-level Makefile and add “-L./libavcodec/libvc1 -lvc1″ (without the quotes) to FFLIBS

    This is a bit fuzzy — here’s what it should look like:

    FFLIBS = -L./libavformat -lavformat$(BUILDSUF) -L./libavcodec -lavcodec$(BUILDSUF) -L./libavutil -lavutil$(BUILDSUF) -L./libavcodec/libvc1 -lvc1$(BUILDSUF)

  2. Multimedia Mike says:

    Hi, I wrote the original post. Thanks for keeping me honest. The problem is that between then and now, the FFmpeg team disabled the original, highly experimental native WMV3 decoder. I have updated my post to reflect this.

  3. stalkerg says:

    Hello!
    I am build mplayer this codec. Hm… for normal perfomance need -O2 or -O3(and some flags) in Makefile. Hm… Many clips play good but big move print error:

    WMV3 init
    VC-1: Initializing with 6 bytes of extradata
    8F 1C 1A 01 40 2F
    FATAL ERROR:
    FATAL ERROR: Image too big for all levels
    vc1DEC_DecoderRequirements() failed
    Could not open codec.
    VDecoder init failed :(

  4. stalkerg says:

    Error profile(2) in struct:
    { /* Reserved Profile */
    { 0, 0, 0, 0, vc1_MVRange64_32 },
    },

    null struckt… hm…

  5. Anonymous says:

    To build this with mplayer, after configure is done edit config.mak

    AV_DEP = libavcodec/libavcodec.a libavcodec/libvc1/libvc1.a libavformat/libavformat.a libavutil/libavutil.a libavcodec/libpostproc/libpostproc.a
    AV_LIB = libavcodec/libavcodec.a libavcodec/libvc1/libvc1.a libavformat/libavformat.a libavutil/libavutil.a libavcodec/libpostproc/libpostproc.a

    then edit ~/.mplayer/codecs.conf

    videocodec ffwmv3
    info “FFmpeg M$ WMV3/WMV9″
    ## status crashing
    status working
    fourcc WMV3,wmv3
    driver ffmpeg
    dll wmv3
    out YV12,I420,IYUV

  6. Anonymous says:

    Hi, I made it through most of the compiling, but came across a snag that I cannot get past.
    I added all of the appropriate hacks and edits, but when I recompile ffmpeg, I get the following:

    make[1]: Leaving directory `/dir/ffmpeg/libavformat’
    gcc -Wl,–warn-common -rdynamic -g -o ffmpeg_g ffmpeg.o cmdutils.o -L./libavformat -lavformat -L./libavcodec -lavcodec -L./libavutil -lavutil -L./libavcodec/libvc1 -lvc1 -lm -lfaad -lfaac -lmp3lame -lz
    /usr/bin/ld: cannot find -lvc1
    collect2: ld returned 1 exit status

    Can anyone help out with why the library would not be found?

    Thanks for any help!

  7. hongg says:

    I’m getting an undefined reference to fseeko in qt-faststart.c when I try and do my final make.

    I’m not a c programmer. Can anyone help?

  8. hongg says:

    Anonymous,

    Did you do what Scott Free said regarding editing the top level makefile?

  9. Anonymous says:

    I did I followed the instructions word for word (this is great tutorialy by the way… thanks). And I am still getting the error.

    Here is more info from above

    make -C libavutil all
    make[1]: Entering directory `/home/user/src/ffmpeg/libavutil’
    make[1]: Nothing to be done for `all’.
    make[1]: Leaving directory `/home/user/src/ffmpeg/libavutil’
    make -C libavcodec all
    make[1]: Entering directory `/home/user/src/ffmpeg/libavcodec’
    make[1]: Nothing to be done for `all’.
    make[1]: Leaving directory `/home/user/src/ffmpeg/libavcodec’
    make -C libavformat all
    make[1]: Entering directory `/home/user/src/ffmpeg/libavformat’
    make[1]: Nothing to be done for `all’.
    make[1]: Leaving directory `/home/user/src/ffmpeg/libavformat’
    gcc -Wl,–warn-common -rdynamic -g -o ffmpeg_g ffmpeg.o cmdutils.o -L./libavformat -lavformat -L./libavcodec -lavcodec -L./libavutil -lavutil -L./libavcodec/libvc1 -lvc1 -lm -lfaad -lfaac -lmp3lame -lz
    /usr/bin/ld: cannot find -lvc1
    collect2: ld returned 1 exit status
    make: *** [ffmpeg_g] Error 1

    It’s so frustrating because I know I am so close, and I just can’t figure out this last part does any one know where -/lvc1 is supposed to be located?

  10. hongg says:

    I kind of got this working, but ffmpeg is trying to use wmv2 instead of wmv3 on wmv3 files (ie. version 9 files). Any suggestions?

  11. hongg says:

    ok, update: this works for wmv version 9 files. Version 8 files, I’m not having success with, but I believe ffmpeg is using the native codecs and not the one introduced here.

  12. Anonymous says:

    Hey hongg,

    On step 6 do you create a directory called Makefile, or do you add the text from the libvc1-makefile.txt into in the file to the makefile that is already located in that directory.

    Thanks!

  13. Richard says:

    It means copy that file to a file named Makefile in the specified directory :)

  14. Chris says:

    Can you make your binary available for public download? (even if it is outdated!)
    *I can provide you with a mirror*

  15. Andy says:

    As of the 27th march 2006 - ffmpeg doesnt seem to support wmv3 at all - therefore the following steps :

    # edit
    libavcodec/vc9.c, go the very end of the file, and add #if 0/#endif
    around the wmv3_decoder AVCodec structure; this will keep it from
    conflicting with the new SMPTE WMV3 decoder
    # edit libavcodec/Makefile and add smpte-vc1.o to the end of the OBJS list
    # edit the top-level Makefile and add “-L./libavcodec/libvc1 -lvc1″ (without the quotes) to FFLIBS
    # run ‘./configure’ at the top level if you have not already done so for this tree
    # run ‘make’ at the top level

    wont even work with the latest cvs release of ffmpeg.

    This is the error you will receive after following the steps to the exact.

    -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -c -o allcodecs.o allcodecs.c
    allcodecs.c: In function `avcodec_register_all’:
    allcodecs.c:94: error: `wmv3_decoder’ undeclared (first use in this function)
    allcodecs.c:94: error: (Each undeclared identifier is reported only once
    allcodecs.c:94: error: for each function it appears in.)
    make[1]: *** [allcodecs.o] Error 1

    anyone have any ideas how i can implement it?

  16. Multimedia Mike says:

    Andy: Read the step 12.5 in the original post (the original point of the post).

  17. Sadek says:

    hi,
    I ve read the instructions I ve done as follewed and i got proper msgs. Everthing builded nice, no errors durning ‘make’, i have also added wmv to formats with
    “./ffmpeg -formats | grep wmv3″ (D V wmv3 poped up). But even every step of installation seemed to be done well i get same msg durning convertion wmv to any other format…(unsupported codec (id=74) for input stream #0.1). Any ideas?

  18. Sadek says:

    Sorry for spam, i just wanted to add screenshot of an error: http://www.patrz.pl/error.jpg

  19. mike says:

    Hi,
    I’m new to ffmpeg, I want to know can I use ffmpeg to build software like goldzsoft? avi mpeg splitter joiner

  20. Luc says:

    I got the thing to work on a Linux RedHat 9 box, however when I convert WM3 to any other format it scrolls the “decoding frame x” (where x is current frame) for every frame, and it’s a bit annoying. Is there any way to disable that?

  21. Luc says:

    Another question. For some reason adding “-title” paramater and supplying title does absolutely nothing no matter what format I create. Anyone know why this may be?

    Thanks,
    Luc L.

  22. Chris says:

    Anyone want to send me a rpm of this thing working? I am in the process of moving so i don’t have the time to do it yet. Anyone want to email the rpm to chris@active9.com, please.

  23. Multimedia Mike says:

    Luc: 1st answer: Yes, you can disable the “decoding frame x” message. Just open the smpte-vc1.c file, search for that string, and comment out that line.

    2nd (non-)answer: I don’t know. The -title sort of depends on what format you are converting to.

  24. NitricJerkSud says:

    Hi there.

    I’m trying to compile this on OS X — I think I’ve followed the directions properly, but I’m getting linking errors at the end…

    ld: Undefined symbols:
    _vc1DECBIT_InitialiseBitstream
    _vc1DEC_DecodeFrame
    _vc1DEC_DecodeSequence
    _vc1DEC_DecoderInitialise
    _vc1DEC_DecoderRequirements
    /usr/bin/libtool: internal link edit command failed
    make[1]: *** [libavcodec.dylib] Error 1
    make: *** [lib] Error 2

    Any idea as to where I should look?

    -NJS

  25. Multimedia Mike says:

    NitricJerkSud: Try following the instructions, starting at step 1. You obviously did not build the VC-1 library, or are not linking it to the rest of the project.

  26. Jayme says:

    I’m having problems compiling wmv2 files
    following error:
    “J-type picture is not supported”
    How can I force versions

  27. Jayme says:

    Ok previous post I posted a “smaller then sign”, seems like a bug in this comment system ( not escaping special HTML chars )
    so to complete my post:
    How can I force versions “smaller then sign” 3 to decode with this codec?

  28. NitricJerkSud says:

    MultimediaMike:

    I managed to get it working, but had to add a -L../libavcodec/libvc1 to the ‘extra-ldflags’ parameter, and -lvc1 to the ‘extra-libs’ parameter.

    ffmpeg compiled cleanly… But now I have an ffmpeg that doesn’t support WMA2. Am I missing something? Is this part of the standard? Or can I only convert movies with WMV3, and another, supported audio format?

    -NJS.

  29. Timo Lindfors says:

    Interesting article but did you notice that the reference decoder software you mirrored now costs $400 according to http://www.smpte.org/smpte_store/test_materials/?

    http://www.smpte.org/smpte_store/test_materials/VC-1_Reference_License.pdf seems to forbid distribution of source code :(

  30. bv says:

    “and anyone on Windows (and some Mac/Linux users) can play them.”

    Or you could just used avi or mpeg or whatever, wich ALL Max/Linux users can play ;)

  31. Brcha says:

    Hi,

    If you wish, you can download Gentoo ebuild from here:

    http://brcha.free.fr/files/ebuilds/ffmpeg/ffmpeg-0.4.9_p20060302-r1.ebuild

    “and anyone on Windows (and some Mac/Linux users) can play them.”

    or can be able to transcode it using ffmpeg2theora to a normal format (Ogg/Theora) that anybody can use!

  32. FrobCs says:

    Works like a charm, but one problem though.
    I wanted to use ffmpeg with wmv3 support ffmpeg-php.

    After following the steps and compiling ffmpeg with –enable-shared, ffmpeg-php bails out with the following message

    PHP Warning: Unknown(): Unable to load dynamic library
    ‘/usr/local/lib/php/extensions/no-debug-non-zts-20020429/ffmpeg.so’ -
    /usr/local/lib/libavcodec.so.51: undefined symbol:
    vc1DECBIT_InitialiseBitstream in Unknown on line 0

    I am not sure if this is entirely related to ffmpeg-php..
    If so, i apologise for putting this up on the wrong forum.

    I have tried googling for the same but my efforts so far have taken me nowhere.

    Any pointers/suggestions welcome.

    Thanks.

  33. Chris says:

    FrobCs all you gotta do is instead of the ffmpeg-php library use the system command.

    system(”ffmpeg arguments here”);

    works like a charm.

  34. Anonymous says:

    Can you upload a file “ffmpeg.exe”?

  35. FrobCs says:

    Thanks Chris,

    Invoking ffmpeg externally always worked like a charm. I just wanted to use ffmpeg-php library.

    However, i have droppped the idea of ffmpeg-php for now.

  36. foo says:

    Hi!

    Thanks for an excellent tutorial!

    This worked like a charm, except that the converted movie did not contain any sound (the original video did).

    Is this a known problem?

    This is the command line I’m using:

    ffmpeg-wmv9 -i “$1″ -ab 56 -ar 22050 -b 500 -r 15 -s 320×240 “$2″

    Where $1 is the input and $2 is the output file.

    Any hints appreciated!

    Cheers

  37. dude says:

    Hi, i want to know if it is possible to encode to the wmv9 format with this hack? Or is it only for decoding? Did anyone know how to encode to wmv9 with ffmpeg on a linux machine?

    Thanks

  38. SteamyMobile says:

    I put all this together into a handy tar file, ready to compile, with the modified FFMPEG source and the VC-1 source all included:

    http://steamymobile.com/downloads

    I even put up ready-compiled Linux binaries.

    Getting all this stuff to work is not completely trivial, so this may be an easier way.

  39. ozy says:

    I have managed to integrate vc1 with ffmpeg but when i try to use the codec i get the following message

    WMV3 init
    VC-1: Initializing with 0 bytes of extradata

    FATAL ERROR:
    FATAL ERROR: DecoderRequirements: Unable to read PROFILE bits
    vc1DEC_DecoderRequirements() failed
    could not open codec

    Any Ideas ?
    Oz

  40. Wolf says:

    I got this error every time:

    ~/ffmpeg/framegrabber/ffmpeg$ ./ffmpeg -i sss.wmv
    FFmpeg version HEAD, Copyright (c) 2000-2004 Fabrice Bellard
    configuration:
    libavutil version: 49.0.0
    libavcodec version: 51.9.0
    libavformat version: 50.4.0
    built on Jul 19 2006 15:57:10, gcc: 4.0.3 (Ubuntu 4.0.3-1ubuntu5)
    WMV3 init
    VC-1: Initializing with 4 bytes of extradata
    4E 41 1A 01
    FATAL ERROR: Assert 0 == (Height & 3) failed at line 397 file vc1tools.c

  41. Emmanuel says:

    I did any step by step and everything works fine, but when I try to run ffmpg to decode a WMV3 to FLV i get the following message:

    Unsoported codec (id=74) for input stream #0.1

    What I did wrong? or What I need to do?

  42. mysnopy’s 个人blog » Blog Archive » ffmpeg编译 says:
  43. Hits says:

    Hello,
    i am new in this field. and i would like to do convert video files to flash.

    I already download this .zip flie but i cant’ get how it will configure in my server.

    Any one can give me the idea.

    Thanks

  44. hits says:

    Hello,

    i am new in video streaming. i want to convert all video file into flash.
    I already download .zip file from here but i can’t get how to install it in my server.

    Plz anyone can help me how can i install or configure.

    Thanks

  45. YuChao says:

    Hi,
    The latest version of FFMpeg dose not have the libavcodec/vc9.c file and the main Makefile format is also differet.

    Do you kindly guide me how to proceed the process to latest one? or you can provide some reference website?
    Thank you!

  46. compn says:

    the latest ffmpeg now has native wmv3 support, SO ALL THOSE USING GOOGLE TO FIND THIS PAGE, THIS PAGE IS OUTDATED!

    just compile ffmpeg svn to get wmv3 support.

  47. Breaking Eggs And Making Omelettes » Blog Archive » Hooking Up The SMPTE VC-1 Decoder In FFmpeg says:

    [...] to experiment with the reference decoder, this should work for you. Update, Feb-16-2006: Thanks to Richard Goodwin for pointing out step 12.5: edit libavcodec/allcodecs and remove the comment blocks around [...]

  48. sangati shinde says:

    Hi,
    this is very use full for me. but I am not able to configure with the ffmpeg will you b plz. give me a full configured zip file or send me a detail mail for configutation.

    configured file is most wellcome, because I try lot to configure.

    thank’s in Advanced.

Leave a Reply