From: Stanley T. <sea...@ho...> - 2006-04-07 01:11:52
|
Hi, I'm doing something similar to an earlier post on Oct 2005 except I want to extract frames from an avi file whose video data is encoded in dv format. I've been following the sample code in that post and some code samples on the internet for avilib. My ultimate goal is to get the frames from the avi file into Matlab in the same way that the tool dvdec does. When I run my code, the program seg faults when running dv_decode_full_frame - am I missing something obvious? Thanks for your help! Stan #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; 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"); } 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 $ _________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ |