Skip to content

CrystalHD support now merged in FFmpeg and MPlayer

I’m pleased to finally be able to announce that my CrystalHD support patches have been accepted into FFmpeg and MPlayer – if you grab the latest source from each of the projects, you’ll be good to go. As before, you’ll need the latest driver and userspace library from Jarod Wilson’s git tree. The driver that’s included in the Linux kernel’s staging directory, and the library on Broadcom’s website are both too old.

In terms of features, the merged code doesn’t differ a great deal from my original announcement – there’s now support for interlaced VC1 and MPEG4 Part 2, but interlaced H.264 remains problematic. I’ve got patches in my github tree that get very close to full support, but there’s still a corner case which can cause one type of file to play back incorrectly.

I have to say, I’ve learnt far more about interlaced encoding than I ever wanted to know, working on this project. I think it’s safe to say that I’ve spent at least 70% of my time working on it, and it’s still not perfect. With progressive content, it’s simple – you have a compressed frame going in one end, and an uncompressed one coming out the other end – there’s really no ambiguity (modulo the hardware’s odd treatment of packed b-frames where it will output the packed frame twice and you have to skip one of them).

But with interlaced content, on this hardware, you have to deal with multiple variations of input and output packing; check out wikipedia if you want a quick introduction to interlacing. When compressed video is packed into a container (like AVI or matroska), it is typically split up into packets, and those packets will correspond to compressed frames or fields, and this where the fun begins. With progressive content, a packet is obviously one frame, but with interlaced content, it could be one field or two fields – sometimes the container or video format will enforce that it is one or the other, and sometimes both are valid. On the output side, the hardware, in its infinite wisdom, will sometimes output individual fields or a full frame of two fields, without much rhyme or reason. And naturally, with h.264, all four combinations are possible. That’s bad enough; to add insult to injury, the flags that the hardware is supposed to set to identify the fields/frames is bogus – meaning that it’s simply not possible to distinguish three out of the four cases until it’s too late. With a little help from FFmpeg, I was able to identify one of those three formats, but for the last two, I had to use a method that relies on peeking ahead at the next frame/field – which is great when it works, but sometimes the hardware hasn’t decoded the next frame/field sufficiently to answer the question, and then I just have to guess.

It should come as no surprise that all the other projects that support CrystalHD have punted on interlaced support :-)

As for the future, I still need to get the improved interlaced support merged, and then I have to start looking at how to support the older 70012 hardware. This chip is very sensitive to the rate that frames are submitted to, and retrieved from, it; the code today will work enough that you should see frames most of the time, but the hardware will do odd things and drop frames or stall, so the experience isn’t good at all. I can at least take comfort from the fact that Broadcom’s gstreamer plugin and XBMC have both got it working.

Onward and upward, etc!

{ 19 } Comments

  1. Maic Striepe | 26th March 2011 at 02:37 | Permalink

    Hello Philip,

    thanx again for your great effort to get this working. Meanwhile I was able to get mplayer compiled with your crystalhd support. I’ve still a few questions:

    a.) crystalhd support was not autodetected on compile time, I had to enable it via configure –enable-crystalhd. Is this normal?

    b.) mplayer uses crystalhd only if I enforce it via vc=ffodivxcrystalhd, ffh264crystalhd in config. Is this the intendet behavior? If yes, I have to alter my codec.conf to remove other codecs so that crystalhd is used if its working for the selected format.

    c.) While h264 contend is working great now beside of one green pixel in the upper left corner of each video, DivX5 ist unfortunalty not (tested with 3 different videos):

    Sample output:

    [lavf] stream 0: video (mpeg4), -vid 0

    Selected video codec: [ffodivxcrystalhd] vfm: ffmpeg (FFmpeg MPEG-4,DIVX-4/5 (CrystalHD))

    [mpeg4_crystalhd @ 0x8a89640]CrystalHD: Filling pipeline.

    VO: [xv] 1280×720 => 1280×720 Planar YV12
    DtsFetchOutInterruptible: Failed:a-0.016 0/ 0 161% 33% 6.0% 40 0
    DtsProcOutput: No Active Channels

    [mpeg4_crystalhd @ 0x8a89640]CrystalHD: ProcOutput failed 10
    [mpeg4_crystalhd @ 0x8a89640]CrystalHD: No frames ready. Returning

    Any ideas? Thanx in advantage.
    If you need the full mplayer output I could mail it to you.

    My card is a bcm70015. DivX is working in xbmc without a problem.

    Thanx again for your great work!

  2. Philip Langdale | 26th March 2011 at 09:03 | Permalink

    Hi Maic,

    a) No, it’s not normal – auto-detect should work if your libcrystalhd is installed correctly. Can you send me the config.log from when you try to use autodetect?

    b) This is correct (same as vdpau). And remember to add a trailing comma so that autodetect still works if the file doesn’t match any of the crystalhd decoders

    c) Strange. Can you send me a sample of one of the files and the full output?

    Thanks.

  3. metapy | 30th March 2011 at 15:00 | Permalink

    Instructions:
    Download mplayer http://www.mplayerhq.hu/design7/dload.html
    svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer

    This will download mplayer from svn. The build process of mplayer will also download ffmpeg from git, so no need to download separately.

    cd mplayer
    ./configure
    make
    sudo make install

    Once mplayer is installed you also need to configure the mplayer conf file.

    nano ~/.mplayer/config

    # Write your default config options here!
    vc=ffmpeg12crystalhd,ffodivxcrystalhd,ffh264crystalhd,ffvc1crystalhd,

    This will tell mplayer to use the crystalhd codecs.

  4. DaveC | 8th April 2011 at 12:56 | Permalink

    Hi Philip,
    I am trying to use the Crystal HD decoder on Mac OS X. So far I have compiled and installed the Crystal HD library, Driver and Mplayer with crystal HD support. However mplayer crashes upon “initilizatizing” the crystal hd decoder with the following error:

    dave:[~/src/temp/mplayer-crystalhd/]$ ./mplayer /Users/dave/Desktop/serenity_hd_dvd-trailer/Serenity\ -\ HD\ DVD\ Trailer.mp4
    MPlayer UNKNOWN-4.2.1 (C) 2000-2011 MPlayer Team
    Can’t init Apple Remote.

    Playing /Users/dave/Desktop/serenity_hd_dvd-trailer/Serenity – HD DVD Trailer.mp4.
    Cache fill: 0.00% (0 bytes)

    libavformat file format detected.
    [lavf] stream 0: video (h264), -vid 0
    [lavf] stream 1: audio (aac), -aid 0, -alang und
    VIDEO: [H264] 1280×720 24bpp 23.976 fps 4674.1 kbps (570.6 kbyte/s)
    Clip info:
    major_brand: isom
    minor_version: 1
    compatible_brands: isomavc1
    creation_time: 2007-05-30 05:20:31
    artist: Universal Pictures
    title: Serenity – HD DVD Trailer
    date: 2005
    Load subtitles in /Users/dave/Desktop/serenity_hd_dvd-trailer/
    Opening video filter: [ilpack=1]
    Opening video filter: [hqdn3d]
    Opening video filter: [pp=hb:c/vb:c/dr/al:f/lb]
    ==========================================================================
    Forced video codec: ffmpeg12crystalhd
    Forced video codec: ffodivxcrystalhd
    Forced video codec: ffh264crystalhd
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Running DIL (3.20.0) Version
    DtsDeviceOpen: Opening HW in mode 0
    IOCTL Command Failed -1 cmd c0106201 sts 0
    DtsGetHwType: Ioctl failed: -1
    Get Hardware Type Failed
    IOCTL Command Failed -1 cmd c0106210 sts 0
    DtsAllocIoctlData Error
    DtsDeviceClose: Close Handle Failed with error 9
    Unable to detach from Dil shared memory …
    DtsDelDilShMem:Unable get shmid …

    MPlayer interrupted by signal 11 in module: init_video_codec
    - MPlayer crashed by bad usage of CPU/FPU/RAM.
    Recompile MPlayer with –enable-debug and make a ‘gdb’ backtrace and
    disassembly. Details in DOCS/HTML/en/bugreports_what.html#bugreports_crash.
    - MPlayer crashed. This shouldn’t happen.
    It can be a bug in the MPlayer code _or_ in your drivers _or_ in your
    gcc version. If you think it’s MPlayer’s fault, please read
    DOCS/HTML/en/bugreports.html and follow the instructions there. We can’t and
    won’t help unless you provide this information when reporting a possible bug.
    dave:[~/src/temp/mplayer-crystalhd/]$

  5. Philip Langdale | 8th April 2011 at 15:45 | Permalink

    I’m impressed that it can actually compile without changes :-)

    The error indicates that basic setup of the hardware is failing, and then it’s possibly crashing trying to clean up on the way out. Does the hellobcm test work?

  6. DaveC | 8th April 2011 at 15:54 | Permalink

    Unfortunately the hellobcm test also fails in exactly the same manner:
    I guess its probably a driver issue then?
    Also I had to add “-D__LINUX_USER” to CFLAGS inorder to get mplayer to detect and compile properly.

    Output:
    starting up
    Running DIL (3.20.0) Version
    DtsDeviceOpen: Opening HW in mode 0
    IOCTL Command Failed -1 cmd c0106201 sts 0
    pHWInfo->PciDevId = 65535
    DtsGetHwType: Ioctl failed: -1
    Get Hardware Type Failed
    IOCTL Command Failed -1 cmd c0106210 sts 0
    DtsAllocIoctlData Error
    DtsDeviceClose: Close Handle Failed with error 9
    Unable to detach from Dil shared memory …
    DtsDelDilShMem:Unable get shmid …
    crap, DtsDeviceOpen failed
    Failed to open device
    Segmentation fault

  7. Philip Langdale | 8th April 2011 at 15:58 | Permalink

    Well, you’re now beyond my ability to help. Going to need to ask Scott DaVilla for help. Perhaps check the xbmc forums – it’s the app that’s had crystalhd support the longest, and has mac users.

  8. DaveC | 8th April 2011 at 16:18 | Permalink

    I will reach out to Scott on the XBMC forums.
    You work on getting Crystal HD support into mplayer and ffmpeg are very much appreciated.
    Thank You!

  9. buyoung | 14th April 2011 at 07:45 | Permalink

    Thanks for the great work ,

    I add below command in config file ,
    vc=ffmpeg12crystalhd,ffodivxcrystalhd,ffh264crystalhd,ffvc1crystalhd,

    but I got below error message :

    Forced video codec: ffmpeg12crystalhd
    Forced video codec: ffodivxcrystalhd
    Forced video codec: ffh264crystalhd
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Cannot find codec ‘h264_crystalhd’ in libavcodec…
    VDecoder init failed :(
    Forced video codec: ffvc1crystalhd
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)

    Any idea how to fix ?

  10. Sergio | 19th April 2011 at 09:01 | Permalink

    Hi Philip,
    I merged the latest git from ffmpeg with my git and compiled and everything went well. However, I want to also include the additional enhancements that you have made. Can you provide a patch to be applied to the main ffmpeg with all the new items?
    Thanks,
    Sergio

  11. Philip Langdale | 19th April 2011 at 09:03 | Permalink

    Sergio, CrystalHD support is already merged into ffmpeg (real ffmpeg, not libav – they still haven’t merged it – unclear if they ever will) and mplayer. I maintain my pending patches in my github tree, but right now the only outstanding change is downscaling support, and I need to change how that is exposed before I can merge it to main.

  12. Philip Langdale | 19th April 2011 at 09:05 | Permalink

    Buyoung, Your mplayer/ffmpeg isn’t built with crystalhd support. There’s two most likely reasons why this is:

    1) You don’t have the latest mplayer/ffmpeg code
    2) You haven’t installed the latest libcrystalhd properly

  13. Sergio | 19th April 2011 at 09:12 | Permalink

    Philip,
    I think I got the correct branch. There is a libavcodec/crystalhd.c file that is being compiled now. I could not find a flag to enable or disable it on ./configure –help of ffmpeg. It appears to be auto configured. I would love to be able to use the downscaling myself. If it is working, I can use it as is. Can you point me to the right patches/checkins to apply?
    Also, how can I tell ffmpeg to use the crystalhd decoder instead of the new multi-threaded h264 decoder?
    Thanks,
    Sergio

  14. Philip Langdale | 23rd April 2011 at 16:33 | Permalink

    TO use the decoder, you have to use the -vc option to mplayer or -vcodec to ffmpeg.

    The ffmpeg names are _crystalhd. eg: h264_crystalhd

    The mplayer names are crystalhd eg: ffh264crystalhd (see codecs.conf)

    To use the downscaling, you need mplayer and ffmpeg from my github tree or apply the patches I sent to the ffmpeg or mplayer mailing lists.

  15. E.F | 2nd June 2011 at 11:42 | Permalink

    I got Jarod’s latest code and mplayer svn from yesterday. But I ‘ve problems to get crystalhd working. The module seems to load fine, and also the firmware is installed in /lib/firmware:

    Loading crystalhd v3.10.0
    crystalhd 0000:02:00.0: Starting Device:0×1615
    crystalhd 0000:02:00.0: PCI INT A -> GSI 18 (level, low) -> IRQ 18
    crystalhd 0000:02:00.0: irq 43 for MSI/MSI-X
    crystalhd 0000:02:00.0: setting latency timer to 64

    -rw-r–r– 1 root root 2786404 2. Jun 21:48 /lib/firmware/bcm70012fw.bin
    -rw-r–r– 1 root root 864276 2. Jun 21:48 /lib/firmware/bcm70015fw.bin

    but even if forcing mplayer to use the crystalhd-codecs it will not work:

    libavformat file format detected.
    [matroska,webm @ 0x345f9c0] Estimating duration from bitrate, this may be inaccurate
    [lavf] stream 0: video (h264), -vid 0
    [lavf] stream 1: audio (ac3), -aid 0, -alang ger
    VIDEO: [H264] 592×352 0bpp 25.000 fps 0.0 kbps ( 0.0 kbyte/s)
    Clip info:
    title: Avidemux
    Load subtitles in Media/_DOWNLOADS_/
    ==========================================================================
    Forced video codec: ffmpeg12crystalhd
    Forced video codec: ffodivxcrystalhd
    Forced video codec: ffh264crystalhd
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Running DIL (3.22.0) Version
    DtsDeviceOpen: Opening HW in mode 0
    DtsDeviceOpen: Create File Failed
    Could not open codec.
    VDecoder init failed :(
    Forced video codec: ffvc1crystalhd
    Cannot find codec matching selected -vo and video format 0×34363248.

    hellobcm reports:

    starting up
    Running DIL (3.22.0) Version
    DtsDeviceOpen: Opening HW in mode 0
    Scaling command param 0×0,ctx_scal:0×0
    try calls done
    Unable to open input file
    DtsAllocIoctlData Error

    Any suggestions? I would be glad if you can have a look in this.

  16. Philip Langdale | 2nd June 2011 at 12:51 | Permalink

    Do you have a /dev/crystalhd and do you have rw permissions on it?

  17. E.F | 2nd June 2011 at 13:03 | Permalink

    yea ef # ls -alh /dev/crystalhd
    crw-rw—- 1 root root 251, 0 2. Jun 21:42 /dev/crystalhd

    root has rw permissions. Do i have to add my users to a special group?

  18. Philip Langdale | 2nd June 2011 at 13:06 | Permalink

    The user running mplayer needs to have permissions. You should chmod /dev/crystalhd to 666.

  19. E.F | 2nd June 2011 at 14:09 | Permalink

    Many thanks! After changing the permissions, crystalHD-support worked flawlessly in mplayer!

Post a Comment

Your email is never published nor shared. Required fields are marked *