Stephen, sorry to bother you again. I've looked over your instructions and snippets in the "Output mpeg-ts to rtp" thread from last year. After making the necessary changes to my setup and sending, and I'm getting a memory error when I attempt to write my second packet. I've written more details below, in the packet sending section to highlight where my problem happens.
Notes: Init code (I've stripped out error codes and objective c code): ------------------------------------------------------------------------------------ // context for the actual stream, this is step 1&2 actualContext = avformat_alloc_context(); url_open_dyn_buf(&ioContext) actualContext->pb = ioContext; actualContext->oformat = av_guess_format("mpegts", NULL, NULL); actualStream = av_new_stream(actualContext, 0); // encoder, part of step 1 codec = avcodec_find_encoder(CODEC_ID_MPEG4); codecContext = actualStream->codec; codecContext->bit_rate = 400000; codecContext->width = CIF_WIDTH; codecContext->height = CIF_HEIGHT; codecContext->time_base = (AVRational){1,FRAME_RATE}; codecContext->gop_size = 10; codecContext->max_b_frames = 1; codecContext->pix_fmt = PIX_FMT_YUV420P; avcodec_open(codecContext, codec); // rtp out, step 3 rtpContext = avformat_alloc_context(); rtpContext->oformat = av_guess_format("rtp", NULL, NULL); snprintf(rtpContext->filename, sizeof(rtpContext->filename), "%s://%s:%d", "rtp", IP_ADDRESS, PORT_NUM); tsrtpStream = av_new_stream(rtpContext, 0); avcodec_get_context_defaults(tsrtpStream->codec); tsrtpStream->codec->codec_id = CODEC_ID_MPEG2TS; rtpContext->audio_codec_id = CODEC_ID_NONE; rtpContext->video_codec_id = CODEC_ID_MPEG2TS; av_set_parameters(rtpContext,NULL); url_fopen(&rtpContext->pb, rtpContext->filename, URL_WRONLY); // write header, step 4 av_write_header(rtpContext); av_write_header(actualContext); ------------------------------------------ Here's my packet code: ------------------------------------------ // step 5 AVPacket actualPkt; AVPacket tsrtpPkt; av_init_packet(&actualPkt); av_init_packet(&tsrtpPkt); AVCodecContext *streamCodec = actualStream->codec; if(streamCodec->coded_frame->pts != AV_NOPTS_VALUE) actualPkt.pts = av_rescale_q(streamCodec->coded_frame->pts, streamCodec->time_base, actualStream->time_base); if(streamCodec->coded_frame->key_frame) actualPkt.flags |= PKT_FLAG_KEY; actualPkt.stream_index = actualStream->index; actualPkt.data = encodedFrame; actualPkt.size = encodedSize; // <---- This is where I get an error. This line works the first time it is called, // <---- and one packet is successfully written into the buffer. It fails for my next attempt // <---- to write a frame. Error is EXC_BAD_ACCESS, which is usually the result of trying // <---- to write into deallocated memory. result = av_interleaved_write_frame(actualContext, &actualPkt); if(result < 0){ // error handling } // <---- Could this be the what's wrong? After url_close_dyn_buf, do I have to reinitialize // <---- ioContext again? If this is the case, how can I reinitialize ioContext safely? NSInteger tsSize = url_close_dyn_buf(ioContext, &tsBuffer); tsrtpPkt.size = tsSize; tsrtpPkt.data = tsBuffer; result = av_interleaved_write_frame(rtpContext, &tsrtpPkt); if(result < 0){ // error handling } ------------------------------------------ _______________________________________________ libav-user mailing list libav-user@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/libav-user