I am writing a ffmpeg h264 decoder for a new processor and have run into a 
problem. The embedded decoder is using video clip that is linked in not read 
from a stream.  (Currently do not have a file system or Ethernet connection) I 
am able to process the image data using h264 decoder (based on tutorial01.c) 
but I only get the last frame. I can see the code processing the frames but it 
finds no images in the initial decode. Below is snapshot of the log message 
that I am seeing (note additional logging added). The image that I am testing 
with is only 4 frames long but I have used an image that is 50 frames only. I 
have verified that I can use ffplay to playback the image successfully, so I 
believe that data I am using is good. Attached is a copy of the code that I am 
using along with video clip source file.

Any pointers would be helpful in solving this problem,

Kent
=================================================================

Running H.264
Initialize AV Packet
Video decoding
Found codec
Alloc context and frame...
Done alloc context.
Log Level = 48
Done alloc frame.
Opening codec.
Opened codec.
Image_buf_read - bin_file_data=2de710 bin_file_data_size=8b1
rbuf = 3fef48, rsize = 1, nrs = 4096
read_index = 2225, nbtyes = 4096, abytes = 2225
Reading frame 0 
Read 2225 bytes
Entered h264: decode_frame: 
h264: decode_frame: Calling decode_nal_units
Enter ff_h264_decode_nal 
ff_h264_decode_nal: decoding esc
Escaping at 10 
Escaping at 15 
Next start at 24 
[h264 @ 0(500438] NAL 7 at 4/2225 length 22

[h264 @ 0500438] sps:0 profile:100/13 poc:0 ref:4 20x15 FRM 8B8 crop:0/0/0/0 
VUI 420 1/50

Enter ff_h264_decode_nal 
startcode, so we must be past the end
no escaped 0
[h264 @ 0Ð500438] NAL 8 at 33/2225 length 5

pps:0 sps:0 CABAC slice_groups:1 ref:3/1 weighted qp:23/26/-2/-2 LPAR   8x8DCT
Enter ff_h264_decode_nal 
startcode, so we must be past the end
no escaped 0
[h264 @ 0Ð500438] NAL 6 at 42/2225 length 685

[h264 @ 0500438] user data:"x264 - core 125 r2208 d9d2288 - H.264/MPEG-4 AVC 
codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: 
cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 
psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x"

Enter ff_h264_decode_nal 
startcode, so we must be past the end
no escaped 0
[h264 @ 0„500438] NAL 5 at 731/2225 length 1403

Processing NAL_SLICE: decode_slice_header
set_dimensions width=320
set_dimensions height=240
Frame number 0
[h264 @ 0¸500438] default_get_buffer called on pic 0À5378d8, 1 buffers used

[h264 @ 0slice:1 F mb:0 I fix IDR pps:0 frame:0 poc:0/0 ref:3/1 qp:28 
loop:1:0:0 weight:0 

Set key_frame.
Done NAL_SLICE
execute_decode_slices
Done execute_decode_slices
Enter ff_h264_decode_nal 
ff_h264_decode_nal: decoding esc
Escaping at 34 
Next start at 46 
[h264 @ 0à500438] NAL 1 at 2139/2225 length 45

Processing NAL_SLICE: decode_slice_header
Frame number 1
[h264 @ 0500438] default_release_buffer called on pic 05378d8, 0 buffers used

[h264 @ 0$500438] default_get_buffer called on pic 0€5378d8, 1 buffers used

[h264 @ 0¸500438] short term list:

[h264 @ 0¸500438] long term list:

[h264 @ 0¸500438] Missing reference picture

ERROR NAL_SLICE: decode_slice_header
[h264 @ 0decode_slice_header error

Enter ff_h264_decode_nal 
startcode, so we must be past the end
no escaped 0
[h264 @ 0NAL 1 at 2190/2225 length 14

Processing NAL_SLICE: decode_slice_header
Frame number 2
[h264 @ 0500438] Frame num gap 2 0

[h264 @ 0˜500438] default_release_buffer called on pic 0
default_get_buffer called on pic 0(5378d8, 1 buffers used

[h264 @ 0500438] no mmco here

[h264 @ 0500438] remove short 1 count 0

[h264 @ 0500438] short term list:

[h264 @ 0500438] 0 fn:1 poc:6 05980e8

[h264 @ 0500438] long term list:

[h264 @ 0È500438] default_get_buffer called on pic 0(537b90, 2 buffers used

[h264 @ 0500438] short term list:

[h264 @ 0500438] 0 fn:1 poc:6 05980e8

[h264 @ 0500438] long term list:

[h264 @ 0500438] slice:1 F mb:0 B fix pps:0 frame:2 poc:4/4 ref:1/1 qp:28 
loop:1:0:0 weight:2 SPAT

Set key_frame.
Done NAL_SLICE
execute_decode_slices
Done execute_decode_slices
Enter ff_h264_decode_nal 
no escaped 0
[h264 @ 0¬500438] NAL 1 at 2209/2225 length 15

Processing NAL_SLICE: decode_slice_header
Frame number 3
[h264 @ 0500438] Frame num gap 3 1

[h264 @ 0˜500438] default_release_buffer called on pic 0
default_get_buffer called on pic 0(537b90, 2 buffers used

[h264 @ 0500438] no mmco here

[h264 @ 0500438] remove short 2 count 1

[h264 @ 0500438] 0 1 005378d8

[h264 @ 0500438] short term list:

[h264 @ 0500438] 0 fn:2 poc:4 0604a08

[h264 @ 0500438] 1 fn:1 poc:6 05980e8

[h264 @ 0500438] long term list:

[h264 @ 0È500438] default_get_buffer called on pic 0(537e48, 3 buffers used

[h264 @ 0¸500438] short term list:

[h264 @ 0¸500438] 0 fn:2 poc:8 0604a08

[h264 @ 0¸500438] 1 fn:1 poc:6 05980e8

[h264 @ 0¸500438] long term list:

[h264 @ 0500438] slice:1 F mb:0 B fix pps:0 frame:3 poc:2/2 ref:1/2 qp:28 
loop:1:0:0 weight:2 SPAT

Set key_frame.
Done NAL_SLICE
execute_decode_slices
Done execute_decode_slices
!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)
Signal interlacing information externally
Derive interlacing flag from used decoding process.
cur->field_poc[0] == cur->field_poc[1]
Most likely progressive
[h264 @ 09500438] no picture
unsigned char bin_file_data[] = {
 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x0d, 0xac, 0xd9, 0x41, 0x41, 0xfb, 
0x01, 0x10, 0x00,
 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03, 0x28, 0xf1, 0x42, 0x99, 0x60, 
0x00, 0x00, 0x00,
 0x01, 0x68, 0xeb, 0xe3, 0xcb, 0x22, 0xc0, 0x00, 0x00, 0x01, 0x06, 0x05, 0xff, 
0xff, 0xaa, 0xdc,
 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7, 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 
0xee, 0xef, 0x78,
 0x32, 0x36, 0x34, 0x20, 0x2d, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x20, 0x31, 0x32, 
0x35, 0x20, 0x72,
 0x32, 0x32, 0x30, 0x38, 0x20, 0x64, 0x39, 0x64, 0x32, 0x32, 0x38, 0x38, 0x20, 
0x2d, 0x20, 0x48,
 0x2e, 0x32, 0x36, 0x34, 0x2f, 0x4d, 0x50, 0x45, 0x47, 0x2d, 0x34, 0x20, 0x41, 
0x56, 0x43, 0x20,
 0x63, 0x6f, 0x64, 0x65, 0x63, 0x20, 0x2d, 0x20, 0x43, 0x6f, 0x70, 0x79, 0x6c, 
0x65, 0x66, 0x74,
 0x20, 0x32, 0x30, 0x30, 0x33, 0x2d, 0x32, 0x30, 0x31, 0x32, 0x20, 0x2d, 0x20, 
0x68, 0x74, 0x74,
 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x76, 0x69, 0x64, 0x65, 0x6f, 
0x6c, 0x61, 0x6e,
 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x78, 0x32, 0x36, 0x34, 0x2e, 0x68, 0x74, 0x6d, 
0x6c, 0x20, 0x2d,
 0x20, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x20, 0x63, 0x61, 0x62, 
0x61, 0x63, 0x3d,
 0x31, 0x20, 0x72, 0x65, 0x66, 0x3d, 0x33, 0x20, 0x64, 0x65, 0x62, 0x6c, 0x6f, 
0x63, 0x6b, 0x3d,
 0x31, 0x3a, 0x30, 0x3a, 0x30, 0x20, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x73, 0x65, 
0x3d, 0x30, 0x78,
 0x33, 0x3a, 0x30, 0x78, 0x31, 0x31, 0x33, 0x20, 0x6d, 0x65, 0x3d, 0x68, 0x65, 
0x78, 0x20, 0x73,
 0x75, 0x62, 0x6d, 0x65, 0x3d, 0x37, 0x20, 0x70, 0x73, 0x79, 0x3d, 0x31, 0x20, 
0x70, 0x73, 0x79,
 0x5f, 0x72, 0x64, 0x3d, 0x31, 0x2e, 0x30, 0x30, 0x3a, 0x30, 0x2e, 0x30, 0x30, 
0x20, 0x6d, 0x69,
 0x78, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x66, 0x3d, 0x31, 0x20, 0x6d, 0x65, 0x5f, 
0x72, 0x61, 0x6e,
 0x67, 0x65, 0x3d, 0x31, 0x36, 0x20, 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x61, 0x5f, 
0x6d, 0x65, 0x3d,
 0x31, 0x20, 0x74, 0x72, 0x65, 0x6c, 0x6c, 0x69, 0x73, 0x3d, 0x31, 0x20, 0x38, 
0x78, 0x38, 0x64,
 0x63, 0x74, 0x3d, 0x31, 0x20, 0x63, 0x71, 0x6d, 0x3d, 0x30, 0x20, 0x64, 0x65, 
0x61, 0x64, 0x7a,
 0x6f, 0x6e, 0x65, 0x3d, 0x32, 0x31, 0x2c, 0x31, 0x31, 0x20, 0x66, 0x61, 0x73, 
0x74, 0x5f, 0x70,
 0x73, 0x6b, 0x69, 0x70, 0x3d, 0x31, 0x20, 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x61, 
0x5f, 0x71, 0x70,
 0x5f, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x3d, 0x2d, 0x32, 0x20, 0x74, 0x68, 
0x72, 0x65, 0x61,
 0x64, 0x73, 0x3d, 0x36, 0x20, 0x6c, 0x6f, 0x6f, 0x6b, 0x61, 0x68, 0x65, 0x61, 
0x64, 0x5f, 0x74,
 0x68, 0x72, 0x65, 0x61, 0x64, 0x73, 0x3d, 0x31, 0x20, 0x73, 0x6c, 0x69, 0x63, 
0x65, 0x64, 0x5f,
 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x73, 0x3d, 0x30, 0x20, 0x6e, 0x72, 0x3d, 
0x30, 0x20, 0x64,
 0x65, 0x63, 0x69, 0x6d, 0x61, 0x74, 0x65, 0x3d, 0x31, 0x20, 0x69, 0x6e, 0x74, 
0x65, 0x72, 0x6c,
 0x61, 0x63, 0x65, 0x64, 0x3d, 0x30, 0x20, 0x62, 0x6c, 0x75, 0x72, 0x61, 0x79, 
0x5f, 0x63, 0x6f,
 0x6d, 0x70, 0x61, 0x74, 0x3d, 0x30, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 
0x61, 0x69, 0x6e,
 0x65, 0x64, 0x5f, 0x69, 0x6e, 0x74, 0x72, 0x61, 0x3d, 0x30, 0x20, 0x62, 0x66, 
0x72, 0x61, 0x6d,
 0x65, 0x73, 0x3d, 0x33, 0x20, 0x62, 0x5f, 0x70, 0x79, 0x72, 0x61, 0x6d, 0x69, 
0x64, 0x3d, 0x32,
 0x20, 0x62, 0x5f, 0x61, 0x64, 0x61, 0x70, 0x74, 0x3d, 0x31, 0x20, 0x62, 0x5f, 
0x62, 0x69, 0x61,
 0x73, 0x3d, 0x30, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x3d, 0x31, 0x20, 
0x77, 0x65, 0x69,
 0x67, 0x68, 0x74, 0x62, 0x3d, 0x31, 0x20, 0x6f, 0x70, 0x65, 0x6e, 0x5f, 0x67, 
0x6f, 0x70, 0x3d,
 0x30, 0x20, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x70, 0x3d, 0x32, 0x20, 0x6b, 
0x65, 0x79, 0x69,
 0x6e, 0x74, 0x3d, 0x32, 0x35, 0x30, 0x20, 0x6b, 0x65, 0x79, 0x69, 0x6e, 0x74, 
0x5f, 0x6d, 0x69,
 0x6e, 0x3d, 0x32, 0x35, 0x20, 0x73, 0x63, 0x65, 0x6e, 0x65, 0x63, 0x75, 0x74, 
0x3d, 0x34, 0x30,
 0x20, 0x69, 0x6e, 0x74, 0x72, 0x61, 0x5f, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 
0x68, 0x3d, 0x30,
 0x20, 0x72, 0x63, 0x5f, 0x6c, 0x6f, 0x6f, 0x6b, 0x61, 0x68, 0x65, 0x61, 0x64, 
0x3d, 0x34, 0x30,
 0x20, 0x72, 0x63, 0x3d, 0x63, 0x72, 0x66, 0x20, 0x6d, 0x62, 0x74, 0x72, 0x65, 
0x65, 0x3d, 0x31,
 0x20, 0x63, 0x72, 0x66, 0x3d, 0x32, 0x33, 0x2e, 0x30, 0x20, 0x71, 0x63, 0x6f, 
0x6d, 0x70, 0x3d,
 0x30, 0x2e, 0x36, 0x30, 0x20, 0x71, 0x70, 0x6d, 0x69, 0x6e, 0x3d, 0x30, 0x20, 
0x71, 0x70, 0x6d,
 0x61, 0x78, 0x3d, 0x36, 0x39, 0x20, 0x71, 0x70, 0x73, 0x74, 0x65, 0x70, 0x3d, 
0x34, 0x20, 0x69,
 0x70, 0x5f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x3d, 0x31, 0x2e, 0x34, 0x30, 0x20, 
0x61, 0x71, 0x3d,
 0x31, 0x3a, 0x31, 0x2e, 0x30, 0x30, 0x00, 0x80, 0x00, 0x00, 0x01, 0x65, 0x88, 
0x84, 0x00, 0x57,
 0xfe, 0x76, 0x50, 0x03, 0x15, 0xbc, 0x0a, 0x6c, 0xbe, 0x24, 0xd0, 0xf9, 0x1a, 
0x32, 0xbe, 0x45,
 0x01, 0xd8, 0x50, 0x63, 0xf5, 0x28, 0x82, 0x6f, 0x00, 0x00, 0x7e, 0x07, 0x6d, 
0xac, 0xac, 0x9b,
 0xe6, 0xcf, 0xf6, 0x34, 0x4b, 0xfe, 0x70, 0x4b, 0x42, 0x87, 0x9b, 0xc6, 0x27, 
0x81, 0x94, 0xe7,
 0x48, 0x96, 0x36, 0xf2, 0x20, 0x56, 0x9a, 0xc0, 0x99, 0x41, 0xce, 0xb8, 0xcc, 
0x91, 0x09, 0xea,
 0x8a, 0xd4, 0x41, 0xbc, 0x2c, 0xf6, 0xe5, 0xcb, 0x71, 0x15, 0x4f, 0x4c, 0xe1, 
0xcc, 0xda, 0x2b,
 0x38, 0x7a, 0xb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0x7d, 0x30, 0xe6, 0xb4, 0x00, 0x28, 0x33, 0x90, 
0x3f, 0x6d, 0xbf,
 0x69, 0x98, 0x6b, 0xcd, 0x88, 0x2e, 0xce, 0x9c, 0x5f, 0x6a, 0x4d, 0xbf, 0xa1, 
0x9a, 0xd5, 0xbe,
 0x43, 0xfe, 0xb5, 0xef, 0xb8, 0xbc, 0xcd, 0xe8, 0xde, 0xcd, 0x7a, 0xf1, 0xe2, 
0x06, 0xe5, 0xa7,
 0x9c, 0x45, 0x9a, 0xbb, 0x1c, 0x01, 0xbd, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9a, 
0x23, 0x6c, 0x45,
 0x7f, 0x00, 0x5d, 0xd6, 0x8e, 0x96, 0x0a, 0x2e, 0x87, 0xa3, 0x7a, 0xd4, 0x2d, 
0xe5, 0xdc, 0xde,
 0xd5, 0xde, 0x7a, 0x5a, 0x9b, 0x40, 0xa1, 0xe6, 0x9c, 0x4c, 0x88, 0xa9, 0x40, 
0x80, 0x00, 0x00,
 0x03, 0x00, 0x01, 0x0d, 0xa3, 0x2f, 0xd0, 0x66, 0x9b, 0x30, 0x00, 0x00, 0x00, 
0x01, 0x41, 0x9e,
 0x42, 0x78, 0x8a, 0xff, 0x1b, 0xb4, 0x6d, 0xd6, 0xa4, 0xdc, 0xd4, 0x2c, 0xb5, 
0x00, 0x00, 0x00,
 0x01, 0x01, 0x9e, 0x61, 0x74, 0x45, 0x7f, 0x1b, 0xe3, 0x8e, 0x7a, 0xf9, 0x5c, 
0xc9, 0xbb, 0x62,
 0x18,};
unsigned int bin_file_data_size = sizeof(bin_file_data);
extern char bin_file_data[];
extern int bin_file_data_size;

static int read_index = 0;

static int image_buf_read(unsigned char *rbuf, unsigned int rsize, unsigned int 
nrs)
{
        int nbytes = rsize * nrs;

        int abytes = bin_file_data_size - read_index;

        int rbytes;

        printf ("Image_buf_read - bin_file_data=%lx bin_file_data_size=%x\n", 
&bin_file_data[0], bin_file_data_size);
        printf ("rbuf = %x, rsize = %d, nrs = %d\n", rbuf, rsize, nrs);
        
        if (nbytes < abytes)
        {
                rbytes = nbytes;
        }
        else
  {
                rbytes = abytes;
        }

        memcpy(rbuf, bin_file_data + read_index, rbytes);

        read_index += rbytes;
        printf ("read_index = %d, nbtyes = %d, abytes = %d\n",read_index, 
nbytes, abytes);

        return rbytes;
}
/*
 * copyright (c) 2001 Fabrice Bellard
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/**
 * @file
 * avcodec API use example.
 *
 * Note that this library only handles codecs (mpeg, mpeg4, etc...),
 * not file formats (avi, vob, etc...). See library 'libavformat' for the
 * format handling
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef HAVE_AV_CONFIG_H
#undef HAVE_AV_CONFIG_H
#endif

#include "avcodec.h"
#include "swscale.h"
#include "avformat.h"
#include "mathematics.h"

#define INBUF_SIZE 4096
#define AUDIO_INBUF_SIZE 20480
#define AUDIO_REFILL_THRESH 4096

#include "image-file.h"

unsigned char rgb_buf [320*240*4];

/*
 * Video decoding example
 */
#if 0
static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, 
unsigned char *new_buf)
{
  int en = 0;
  int j;
  int i;

  for(i=0;i<ysize;i++)
  {
    for (j = 0; j < xsize; j++);
    {
      *(new_buf + (i * wrap) + j) = *(buf + (i * wrap) + j);
    }
  }
}
#endif

static void video_decode_example(const char *outfilename, const char *filename)
{
    AVCodec *codec;
    AVCodecContext *c= NULL;
    int frame, got_picture, len;
    FILE *f;
    AVFrame *picture;

    AVFrame *pFrameRGB;
    int numBytes;
    int rgb_img_size;
    uint8_t *buffer;
    int status;
    int i, j;

    //SwsContext *pSWSCtx;
    struct SwsContext *sws_ctx = NULL;

    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
    AVPacket avpkt;

    printf("Initialize AV Packet\n");
    av_init_packet(&avpkt);

    /* set end of buffer to 0 (this ensures that no overreading happens for 
damaged mpeg streams) */
    memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);

    printf("Video decoding\n");

    /* find the h264 video decoder */
    codec = avcodec_find_decoder(CODEC_ID_H264);
    if (!codec)
    {
      printf("codec not found\n");
      exit(1);
    }
    else
    {
      printf("Found codec\n");
    }

    printf("Alloc context and frame...\n");
    c = avcodec_alloc_context();

    printf(" Done alloc context.\n");
    picture = avcodec_alloc_frame();

    // Allocate an AVFrame structure
    pFrameRGB = avcodec_alloc_frame();
    if(pFrameRGB == NULL)
    {
      printf ("\"pFrameRGB=avcodec_alloc_frame()\" - Failed\n");
      exit (1);
    }

    printf ("Log Level = %d\n", (av_log_get_level()));

    printf(" Done alloc frame.\n");

    if(codec->capabilities&CODEC_CAP_TRUNCATED)
      c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */

    // For some codecs, such as msmpeg4 and mpeg4, width and height
    //   MUST be initialized there because this information is not
    //   available in the bitstream.

    // Turn on all debug/loging flags
    c->debug = 0xffffffff;
    c->debug_mv = 0xffffffff;
    //c->mv_debug = 0xffffffff;

    /* open it */
    printf("Opening codec.\n");

    if (avcodec_open(c, codec) < 0)
    {
      printf("could not open codec\n");
      exit(1);
    } 
    else
    {
      printf("Opened codec.\n");
    }

    frame = 0;
    for(;;)
    {
      avpkt.size = image_buf_read(inbuf, 1, INBUF_SIZE);

      printf("Reading frame %d \n", frame);
      printf("Read %d bytes\n", avpkt.size);

      if (avpkt.size == 0)
      {
        printf ("Frame # = %d\n", frame);
        break;
      }

      /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)
         and this is the only method to use them because you cannot
         know the compressed data size before analysing it.

         BUT some other codecs (msmpeg4, mpeg4) are inherently frame
         based, so you must call them with all the data for one
         frame exactly. You must also initialize 'width' and
         'height' before initializing them. */

      /* NOTE2: some codecs allow the raw parameters (frame size,
         sample rate) to be changed at any frame. We handle this, so
         you should also take care of it */

      /* here, we use a stream based decoder (mpeg1video), so we
         feed decoder and see if it could decode a frame */

      avpkt.data = inbuf;

      while (avpkt.size > 0)
      {
        len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
        if (len < 0)
        {
          printf("Error while decoding frame %d\n", frame);
          exit(1);
        }

        //printf ("c->width = %d, c->height = %d\n", c->width, c->height);
        sws_ctx = sws_getCachedContext( sws_ctx, c->width, c->height, 
c->pix_fmt, c->width, c->height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL );
        if (sws_ctx <= 0)
        {
          printf ("sws_getCachedContext - failed");
          exit (1);
        }

        // Determine required buffer size and allocate buffer
        numBytes=avpicture_get_size(PIX_FMT_RGB24, c->width, c->height);
        printf ("numBytes = %d\n", numBytes);

        // Assign appropriate parts of buffer to image planes in pFrameRGB
        // Note that pFrameRGB is an AVFrame, but AVFrame is a superset
        // of AVPicture
        rgb_img_size = avpicture_fill((AVPicture *)pFrameRGB,(uint8_t *) 
&rgb_buf[0], PIX_FMT_RGB24, 320, 240);
        printf ("rgb_size = %d\n", rgb_img_size);

        if (rgb_img_size == -1)
          exit (1);

        printf ("got_picture = %d\n", got_picture);
        if (got_picture)
        {
          printf("saving frame %3d\n", frame);
          printf ("&picture->data = %x, picture->linesize = %d, c->height =%d, 
&pFrameRGB->data = %x, pFrameRGB->linesize = %d\n",
                  picture->data, picture->linesize, c->height, pFrameRGB->data, 
pFrameRGB->linesize);

          // Convert image from yuv to rgb24
          status = sws_scale(sws_ctx, (uint8_t const * const *)picture->data, 
picture->linesize, 0, c->height, pFrameRGB->data, pFrameRGB->linesize);

          // Move it to the DVI port for display
          //SEP_Display_Image (frame, (unsigned long long *)pFrameRGB->data[0], 
(c->width * c->height), c->width, c->height);

          frame++;
        } // end of if

        avpkt.size -= len;
        avpkt.data += len;
      } // end of while
    }

    printf ("Reading video stream done - Check for last frame\n");

    // some codecs, such as MPEG, transmit the I and P frame with a
    // latency of one frame. You must do the following to have a
    // chance to get the last frame of the video
    avpkt.data = NULL;
    avpkt.size = 0;
    len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
    if (got_picture)
    {
      printf("saving last frame %3d\n", frame);

      //fflush(stdout);

      // the picture is allocated by the decoder. no need to free it

      printf ("frame = %d, &picture->data[0] = %x, picture->linesize[0] = %d, 
c->width = %d, c->height = %d\n",
              frame, (unsigned long long *) &picture->data[0], (c->width * 
c->height), c->width, c->height);

      printf ("picture->data[0] = %x, picture->data[1] = %x, picture->data[2] = 
%x, picture->data[3] = %x\n",
              (unsigned long long *) &picture->data[0], (unsigned long long *) 
&picture->data[1],
              (unsigned long long *) &picture->data[2], (unsigned long long *) 
&picture->data[3]);


      printf ("&picture->data = %x, picture->linesize = %d, c->height =%d, 
&pFrameRGB->data = %x, pFrameRGB->linesize = %d\n",
              picture->data, picture->linesize, c->height, pFrameRGB->data, 
pFrameRGB->linesize);

      // Convert image from yuv to rgb24
      status = sws_scale(sws_ctx, (uint8_t const * const *)picture->data, 
picture->linesize, 0, c->height, pFrameRGB->data, pFrameRGB->linesize);

      // Move it to the DVI port for display
      frame++;
    }

    avcodec_close(c);
    av_free(c);
    av_free(picture);
    av_free(pFrameRGB);

    //printf("\n");
}

int main(int argc, char **argv)
{
    const char *filename;

    printf ("Running H.264\r\n");

    /* must be called before using avcodec lib */
    avcodec_init();

    /* register all the codecs */
    avcodec_register_all();

#if 0
    if (argc <= 1) {
      video_encode_example("/tmp/test.mpg");
      filename = "/tmp/test.mpg";
    } else {
      filename = argv[1];
    }
#endif

    //    audio_decode_example("/tmp/test.sw", filename);
    video_decode_example("/tmp/test%d.pgm", filename);

    return 0;
}
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to