|
From: Brent C. <bca...@sg...> - 2006-04-07 16:30:42
|
On Thu, 6 Apr 2006, Stanley Tuna wrote:
> When I run my code, the program seg faults when running dv_decode_full_frame -
> am I missing something obvious?
>
> #include "transcode-0.6.14/avilib/avilib.h"
> #include <libdv/dv.h>
>
> #define READ_SIZE 120000
>
> int main(void)
> {
> int width,height;
> long frames,framesize;
> avi_t *avifile;
> char *compressor;
> unsigned char *framebuffer;
>
> int keyframe;
>
> dv_decoder_t *dvdecoder;
> unsigned char *pixels[3];
> int pitches[3];
>
> /* open the avi file and the decoder */
> avifile=AVI_open_input_file(
> "/home/tuna/f15_pavl_150_r1/te/f15_pavl_150_r1_te_beg.avi"
> ,1);
> if(!avifile)
> {
> printf("Error: Could not open avi file\n");
> }
> dvdecoder=dv_decoder_new(TRUE, FALSE, FALSE);
> if(!dvdecoder)
> {
> printf("Error: Could not initialize dv decoder\n");
> }
> framebuffer=malloc(READ_SIZE);
> pixels[0]=malloc(dvdecoder->width*dvdecoder->height*3);
> pitches[0]=dvdecoder->width*3;
I think these two lines might be where you're going wrong.
The decoder hasn't been initialized to the point of knowing the
format of the input, and thus the width and height are not
valid values.
Check out the playdv.c file in the libdv source, at or near
line 355. You'll see that they pull in an NTSC sized frame of
data (120000 bytes), and run dv_parse_header() on it. After
that has finished, *then* the width and height of the decoder
structure are known (and the size of the input frames, which
would be 144000 bytes for PAL).
>
> AVI_info(avifile);
> frames=AVI_video_frames(avifile);
> width=AVI_video_width(avifile);
> height=AVI_video_height(avifile);
> compressor=AVI_video_compressor(avifile);
> framesize=AVI_frame_size(avifile,0);
>
> /* start reading and decoding frames */
> AVI_seek_start(avifile);
> if(AVI_read_frame(avifile,framebuffer,&keyframe)<0)
> {
> printf("Error: Could not read frame from avi file\n");
> }
>
> if(dv_parse_header(dvdecoder,framebuffer)<0)
> {
> printf("Error: Failed to parse header\n");
> }
In your provided program, you should be able to just move the
malloc() of "pixels" after your call to dv_parse_header(),
and all would be well.
> printf("Decoding...\n");
> dv_decode_full_frame(dvdecoder,framebuffer,e_dv_color_rgb,pixels,pitches);
>
> AVI_close(avifile);
>
> return 0;
> }
>
> tuna@ocean /home/tuna/src $ gcc readavi.c -L/home/tuna/src/transcode-0.6.14/
> -lavi -ldv
> tuna@ocean /home/tuna/src $ ./a.out
> [avilib] V: 29.970 fps, codec=dvsd, frames=1821, width=720, height=480
> [avilib] A: 32000 Hz, format=0x01, bits=16, channels=2, bitrate=1024 kbps,
> [avilib] 1821 chunks, 7777432 bytes, CBR
> Decoding...
> Segmentation fault
> tuna@ocean /home/tuna/src $
--
Brent Casavant All music is folk music. I ain't
bca...@sg... never heard a horse sing a song.
Silicon Graphics, Inc. -- Louis Armstrong
|