Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6704 Discussions

mpeg4 decoder, problems with large avis

persorner2
Beginner
431 Views
[sectionBodyText]I have a problem with using multiple mpeg4 encoded videostream avis. [/sectionBodyText]
[sectionBodyText]Decoding the first 2 gigabytes of my recordings work fine, but about 2.1 gigs (suspiciously close to 2^31) in to the recording
getFrame from the decoder starts returning UMC_ERR_SYNC and UMC_WRN_INVALID_STREAM alternatingly. [/sectionBodyText]
[sectionBodyText]My video contains 3 videostreams (DX50) and no sound. If I decode just one of the video streams, I have no problems. [/sectionBodyText]
[sectionBodyText]If I ignore the errors, I will get a messed up video that looks like it contains some video data from the beginning of the recording instead. [/sectionBodyText]
[sectionBodyText]It also seems to be from a different video stream than expected (i.e stuff from stream 2 can be found in stream 1). 
To me it looks like some kind of overflow error. [/sectionBodyText]
[sectionBodyText]My videos are recorded with a mpeg4 encoder board and muxed into one avi using directshow. [/sectionBodyText]
[sectionBodyText]I can play them in VLC or Media Player classic without problems.[/sectionBodyText]
[sectionBodyText]Here's some code that should reproduce the error:[/sectionBodyText]
[cpp][/cpp]
[cpp]int decodeAVI(char * filename, char * smafilename, int maxFrames)
{

  UMC::Status sts, sSts;
  UMC::FIOReader Reader;
  UMC::AVISplitter Splitter;
  UMC::SplitterInfo *StreamInfo;
  UMC::MPEG4VideoDecoder Decoder[3]; // one per stream
 
  UMC::MediaData in[3]; // one per stream
  UMC::VideoData out[3]; // one per stream

  // Initialize data reader component

  UMC::FileReaderParams FileParams;
  FileParams.m_portion_size = 0;
  vm_string_strcpy(FileParams.m_file_name, filename);
  sts = Reader.Init(&FileParams);

  if (sts != UMC::UMC_OK) {
    printf("Reader Init error ");
    return 1;
  }

  // Initialize splitter component

  UMC::SplitterParams SplParams;

  SplParams.m_lFlags = UMC::VIDEO_SPLITTER; // extract only video
  SplParams.m_pDataReader = &Reader;

  sts = Splitter.Init(SplParams);

  if (sts != UMC::UMC_OK) {

    printf("Splitter Init error ");
    return 1;

  }

  sts = Splitter.Run();

  if (sts != UMC::UMC_OK) {

    printf("Splitter Run error ");
    return 1;

  }

  // Get stream info

  sts = Splitter.GetInfo(&StreamInfo);

  if (sts != UMC::UMC_OK) {

    printf("Splitter GetInfo error ");
    return 1;

  }
  else
  {
    printf("Found %d TrackstStream Length: %.4fsn",StreamInfo->m_nOfTracks,StreamInfo->m_dDuration);
  }

  // find all MPEG4 video-tracks

  std::vector videoTracks;

  for (Ipp32u videoTrack = 0; videoTrack < StreamInfo->m_nOfTracks; videoTrack++) {
    if (videoTracks.size()==3)
      break;
    if (StreamInfo->m_ppTrackInfo[videoTrack]->m_Type == UMC::TRACK_MPEG4V)
      videoTracks.push_back(videoTrack);

  }
  if (videoTracks.size() == 0) 
  {
    printf("AVI does not contain MPEG-4 video ");
    return 1;
  }
  
  UMC::VideoStreamInfo videoTrackInfo[3];
  UMC::VideoDecoderParams VDecParams[3];
  
  for (Ipp32u track=0;trackm_ppTrackInfo[videoTracks[track]]->m_pStreamInfo);

    // Initialize video decoder component

    VDecParams[track].info = videoTrackInfo[track];
    VDecParams[track].lFlags = UMC::FLAG_VDEC_REORDER;
    VDecParams[track].numThreads = 1;
    VDecParams[track].m_pData = StreamInfo->m_ppTrackInfo[videoTracks[track]]->m_pDecSpecInfo;
    sts = Decoder[track].Init(&VDecParams[track]);

    if (sts != UMC::UMC_OK) {

      printf("Decoder Init error ");
      return 1;
    }

    if (videoTrackInfo[track].color_format != UMC::YV12) 
    { 
      printf("Expected YV12 Format");
    }

    // allocate memory for video data
    out[track].Init(videoTrackInfo[track].clip_info.width,videoTrackInfo[track].clip_info.height,videoTrackInfo[track].color_format);
    out[track].SetColorFormat(videoTrackInfo[track].color_format);
    out[track].Alloc();
    printf("Track Size: %dx%dn",videoTrackInfo[track].clip_info.width,videoTrackInfo[track].clip_info.height);

  }

  int nframes = 0;
  printf("Decoding Streamn");[/cpp]
[cpp][/cpp]
[cpp]  for (Ipp32u track=0;track
[cpp]  {[/cpp]
[cpp]      while (UMC::UMC_ERR_NOT_ENOUGH_DATA == (sts = Splitter.GetNextData(&in[track], videoTracks[track]))) // wait until data is decoded
        vm_time_sleep(5);

      if (sts != UMC::UMC_OK && sts != UMC::UMC_ERR_END_OF_STREAM) 
      {

        printf("Splitter error (%d), frame %d ", sts, nframes);
        break;

      }

      sSts = sts;
      sts = Decoder[track].GetFrame(sSts == UMC::UMC_OK ? &in[track] : NULL, &out[track]);[/cpp]
[cpp]       ///////////////////[/cpp]
[cpp]       /// returns UMC_ERR_SYNC around 2 gigs into the recording[/cpp]
[cpp]   

      if (sts != UMC::UMC_OK && sts != UMC::UMC_ERR_NOT_ENOUGH_DATA)       
      {

        printf("Track %d, Dec Err (%d), Frame %d ", track, sts, nframes);
        return 1;
   
      }
   
    } // all tracks decoded

    if (sts == UMC::UMC_OK) 
    {
      if (nframes%100==0)
        printf("frame %4dn", nframes);

    }
                     
    if (sSts == UMC::UMC_ERR_END_OF_STREAM)  
      break;

  }
 
  printf("processed %d framesn", nframes);

  return 0;

}[/cpp]
0 Kudos
7 Replies
persorner2
Beginner
431 Views
Sorry about the formatting..I'm using: w_ipp-samples_p_5.3.095
0 Kudos
Vladimir_Dudnik
Employee
431 Views
Did you try this file with simple_player application?
Vladimir

0 Kudos
Vladimir_Dudnik
Employee
431 Views
Our expert recommend to replace UMC::FIOReader with UMC::FileReader which use vm_file wrappers to support files with more than 2 Gb lenght
Vladimir

0 Kudos
persorner2
Beginner
431 Views
Quoting - vdudnik
Our expert recommend to replace UMC::FIOReader with UMC::FileReader which use vm_file wrappers to support files with more than 2 Gb lenght
Vladimir

Now it works great!

Thanks a lot Vladimir!
By the way, is there any documentation for FileReader or FIOReader? I had no idea this could be the problem.

0 Kudos
Vladimir_Dudnik
Employee
431 Views
Yes, UMC components should be documented in UMC manual, please check folder 'doc' in audio-video-codecs sample.
Regards,
Vladimir

0 Kudos
persorner2
Beginner
431 Views

Thanks,

I have read the manual, I couldn't find any mention about the differences between FIOReader and FileReader though, only the baseclass datareader is documented there as far as I can tell.

0 Kudos
Vladimir_Dudnik
Employee
431 Views
Thanks for your points. That mean we have to improve documentation in future versions.
Vladimir

0 Kudos
Reply