Hi,
I am trying for the start to write a simple demultiplexer with libav*
But unfortunately my app crashes when I call av_write_frame()
Below is a reduced version (error handling etc. stripped) of my code so far.
"ff" is the namespace into wich I include the libav* headers.
Does anybody have a clue what I am doing wrong?
=======================
/* open input file */
ff::AVFormatContext *avfCtx;
ff::av_open_input_file(&avfCtx, filename.toLocal8Bit(), NULL, 0, NULL)
ff::av_find_stream_info(avfCtx)
//... let the user choose...
/* create output contexts and files */
QHash<uint, ff::AVFormatContext*> outputs;
/*create outputs for every stream the user wants to demux like the following: */
for (i=0;....)
{
QString filename = makeFilename(....);
ff::AVOutputFormat *of = ff::guess_format(NULL, filename.toLocal8Bit(),
NULL);
ff::AVFormatContext *fc = ff::avformat_alloc_context();
fc->oformat = of;
strncpy(fc->filename, filename.toLocal8Bit(), 1024);
fc->filename[1023] = '\0';
ff::AVStream *ostream = ff::av_new_stream(fc, 0);
//take over various values from the input stream
//then...
ff::av_set_parameters(fc, NULL);
ff::url_fopen(&fc->pb, fc->filename, URL_WRONLY);
outputs.insert(i, fc);
}//end for i
/* copy frames */
for (;;)
{
ff::AVPacket pkt;
if (ff::av_read_frame(avfCtx, &pkt) != 0)
break;
qDebug() << "packet for stream"<< pkt.stream_index;
ff::AVFormatContext *ofc = outputs.value(pkt.stream_index, NULL);
if (ofc != NULL) {
pkt.stream_index = 0;
if (av_write_frame(ofc, &pkt) < 0) // <------ crashes here
{
//error handling
break;
}
qDebug() << "OK";
}
ff::av_free_packet(&pkt);
}
=======================
gdb output:
Program received signal SIGFPE, Arithmetic exception.
[Switching to Thread 0x7f7ddaf026f0 (LWP 21960)]
0x00007f7ddaa41afa in compute_pkt_fields2 (st=0x69d5c0, pkt=0x7fffe2f397b0)
at libavformat/utils.c:88
88 f->val += num / den;
Current language: auto; currently c
(gdb) bt
#0 0x00007f7ddaa41afa in compute_pkt_fields2 (st=0x69d5c0, pkt=0x7fffe2f397b0)
at libavformat/utils.c:88
#1 0x00007f7ddaa41ef2 in av_write_frame (s=0x846530, pkt=0x0)
at libavformat/utils.c:2636
...
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user