I am trying to use libavformat to mux audio and video sources:
int mux_files (char *outname, char **inname, int len, char *format) {
int i;
AVFormatContext **pFormatCtx;
AVOutputFormat *fmt;
AVFormatContext *oc;
AVStream *audio_st, *video_st;
AVPacket packet;
double audio_pts, video_pts;
int audio,video;
int read_bytes=0;
unsigned int audio_bytes=0;
unsigned int video_bytes=0;
if (format) {
fmt = guess_format(format, NULL, NULL);
} else {
fmt = guess_format(NULL, outname, NULL);
}
if (!fmt) {
fprintf(stderr, "Could not find suitable output format\n");
return -1;
}
oc = av_alloc_format_context();
if (!oc) {
fprintf(stderr, "couldn't allocate memory for output format\n");
return -1;
}
oc->oformat = fmt;
snprintf(oc->filename, sizeof(oc->filename), "%s", outname);
//fprintf (stderr,"list len: %d\n",len);
pFormatCtx = (AVFormatContext **) malloc (sizeof(AVFormatContext *) *
len);
for (i =1; i < len; i++) {
if(av_open_input_file(&pFormatCtx[i], inname[i], NULL, 0,
NULL)!=0)
return -1;
if(av_find_stream_info(pFormatCtx[i])<0)
return -1; // Couldn't find stream information
dump_format(pFormatCtx[i], i, inname[i], 0);
if(pFormatCtx[i]->streams[0]->codec->codec_type==CODEC_TYPE_VIDEO)
{
video_st = av_new_stream(oc,0);
if (!video_st) {
fprintf(stderr, "Could not alloc stream\n");
return -1;
}
video = i;
memcpy(video_st->codec,
pFormatCtx[i]->streams[0]->codec,
sizeof(AVCodecContext));
} else if
(pFormatCtx[i]->streams[0]->codec->codec_type==CODEC_TYPE_AUDIO) {
audio_st = av_new_stream(oc,1);
if (!audio_st) {
fprintf(stderr, "Could not alloc stream\n");
return -1;
}
audio=i;
memcpy(audio_st->codec,
pFormatCtx[i]->streams[0]->codec,
sizeof(AVCodecContext));
}
}
if (av_set_parameters(oc, NULL) < 0) {
fprintf(stderr, "Invalid output format parameters\n");
return -1;
}
dump_format(oc, 0, outname, 1);
// works so far
av_write_header(oc);
SEGFAULT here...Is there something that doesn't appear to be done
right, or is something missing?
Thanks,
-V
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user