Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:15:39+00:00 2026-05-24T16:15:39+00:00

I’m trying to parse H.264 frames from a .mov file. I think I’ve come

  • 0

I’m trying to parse H.264 frames from a .mov file. I think I’ve come to the conclusion that mov.c from AVFormat-part of FFMPEG is the way to go. But mov.c is ~2600 lines of next to uncommented code. I’m looking for examples of usage of FFMPEG, especially parsing the structure of any file type. doesn’t matter if it is MPEG4 or Quicktime Movie since they are quite similar in structure.

if there are no existing examples (I can’t find any) maybe someone has used it and can give me a couple of lines of code, or explain how to get started?

What I’m trying to do:
i use AVCaptureSession to capture samples from the video camera, these samples are then encoded in H264 and written to file with the help of AVAssetsWriter, AVAssetsWriterInput and AVAssetsWriterInputPixelBufferAdaptor. The reason for which is that I can’t access the hardware H264 encoding directly since apple won’t allow this. What I now need to do (I think not sure) is parse out:

The “mdat“-atom (Movie data, there might be more than one i think) from the .mov file.
then the “vide“-atom and then within the vide-atom (Video data sample, there might be more than one). I think there will be several atoms which i belive is the frames. these will be of type “avc1” (that’s the type for H264). Please correct me in this because i’m quite sure that i havn’t gotten all of this correctly yet.

my question then is, how will i go about parsing out the single frames. I’ve been reading the documentation and looked at iFrameExtractor (which is not very helpful since it decodes the frames). I think I’ve understood it correctly when I’m supposed to use mov.c from FFMPEG-AVFormat but I’m not sure.

Edit:
I’m now trying like this:

  1. I run the slightly reduced init function i iFrameExtractor which finds the videostream in the .mov-file.

  2. I get the data for the frame like this:

    AVPacket packet;
    av_read_frame(pFormatCtx, &packet);
    NSData *frame;
    if(packet.stream_index == videoStream){
        frame = [NSData dataWithBytes:packet.data length:packet.size];
    }
    videoStream++;
    av_free_packet(&packet);
    return frame;
    

i then pass it to a subclass of NSOperation where it is retained in wait for upload.
but i receive a EXC_BAD_ACC, am I doing something wrong when copying the data from the frame? any ideas. i get the EXC_… when I try to set the class variable NSData* frame using its (nonatomic,retain)-property. (it says EXC_BAD_ACC on the synthesize row)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:15:40+00:00Added an answer on May 24, 2026 at 4:15 pm

    i use the following to parse each frame from the mov file.

    -(NSData *)nextFrame {
        AVPacket packet;
        NSData *frame = nil;
    
        while(!frame && av_read_frame(pFormatCtx, &packet)>=0) {
    
            if(packet.stream_index == streamNo) {
                frame = [[[NSData alloc] initWithBytes:packet.data length:packet.size] autorelease];
            }
            av_free_packet(&packet);
        }
        return frame;
    }
    

    although watch out since av_read_frame does not verify the frames, that is done in the decoding step. this means that the “frames” returned might contain extra information which are not part of the actual frame.

    to init the AVFormatContext *pFormatCtx and AVCodecContext *pCodecCtx I use this code (which I believe is derived from Martin Böhme’s example code):

        AVCodec *pCodec;
    
        // Register all formats and codecs
        av_register_all();
    
        // Open video file
        if(avformat_open_input(&pFormatCtx, [moviePath cStringUsingEncoding:NSASCIIStringEncoding], NULL, NULL)!=0)
            goto initError; // Couldn't open file
    
        // Retrieve stream information
        if(avformat_find_stream_info(pFormatCtx,NULL)<0)
            goto initError; // Couldn't find stream information
    
        // Find the video stream
        streamNo = -1;
        for(int i=0; i<pFormatCtx->nb_streams; i++){
            if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
            {
                streamNo = i;
                break;
            }
        }
        if(streamNo == -1)
            goto initError; // Didn't find a video stream
    
        // Get a pointer to the codec context for the video stream
        pCodecCtx=pFormatCtx->streams[streamNo]->codec;
    
        // Find the decoder for the video stream
        pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
        if(pCodec==NULL)
            goto initError; // Codec not found
    
        // Open codec
        if(avcodec_open2(pCodecCtx, pCodec, NULL)<0)
            goto initError; // Could not open codec
    
        return self;
    
    initError:
        NSLog(@"initError in VideoFrameExtractor");
        [self release];
        return nil;
    

    hope this helps someone in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.