2012年4月10日 星期二

S3C6410 MFC H.264 mp4 player

S3C6410 can do hardware video decode including H.264.
There's an example code from Samsung shows how to hardware decode H.264 raw data, but in the real world application this is not so useful.
Decode & Playing H.264 mp4 file is more reality. So I would like to share the implementation.

I use ffmpeg library to decode mp4 mux in order to get H.264 raw data and then send it to S3C6410 MFC to decode and finally play on the LCD panel.

Requirement
ffmpeg-0.6.1
Samsung FIMV_MFC_V1.0

Source code
https://docs.google.com/open?id=0Bx901QMLr9WlTTR1a0ZKaXVobW8

The most important part is to handle data from

  av_read_frame(formatContext, &pkt);

if you pass pkt.data to decode you got fail to decode. Another filter is required.

  typedef struct H264BSFContext {
    uint8_t  length_size;
    uint8_t  first_idr;
    uint8_t *sps_pps_data;
    uint32_t size;
  } H264BSFContext;

  AVBitStreamFilterContext *filterContext = (AVBitStreamFilterContext *)malloc(sizeof(AVBitStreamFilterContext));
  filterContext->priv_data = (H264BSFContext *)malloc(sizeof(H264BSFContext));
  memset(filterContext->priv_data, 0, sizeof(H264BSFContext));
  filterContext->filter = &h264_mp4toannexb_bsf;
  filterContext->parser = 0;
  filterContext->next = 0;
...
  r = av_read_frame(formatContext, &pkt);
...
    unsigned char *lp = 0;
    int len = 0;
    filterContext->filter->filter(filterContext, codecContext, NULL, &lp, &len, pkt.data, pkt.size, (pkt.flags | PKT_FLAG_KEY)); -->> filter here

    decode_mfc(lp, len);