While examples for writing an encoded video stream into a file
container are relatively abundant, I'm having trouble transmitting my
MPEG4 encoded streams into VLC for viewing. libav isn't giving me any
errors for the code I'm running, and using a packet filter, I can tell
both that my test app is sending UDP packets, and that VLC is
receiving them, but they aren't being processed correctly (nothing is
being displayed). I suspect that there's something wrong with the way
I'm initializing my libav structures, or how I'm sending them to
unicast target, but having gone through all the samples I could find,
and going through the libav headers, I've run out of options to try.

My platform is the iPhone, so I've tried to strip all the objective C
from my snippets to avoid confusion. Here's my initialization:
-----------------------------
// error handling STREAM_PROTOCOL == "rtp"

// initialize AVFormatContext

formatContext->oformat = av_guess_format(STREAM_PROTOCOL, NULL, NULL);

snprintf(formatContext->filename, sizeof(formatContext->filename),
"%s://%s:%d", STREAM_PROTOCOL, IP_ADDRESS, PORT_NUM);

if(url_fopen(&formatContext->pb, formatContext->filename, URL_WRONLY) < 0){
                // error handling
}

// initialize stream, codecs, etc. here

av_write_header(formatContext);
-----------------------------

I'm particularly unsure about when it would be proper to call av_write_header.

Here's how I send my frames:
-----------------------------
if(encodedSize > 0){
                AVPacket pkt;
                av_init_packet(&pkt);
                        
                AVCodecContext *streamCodec = stream->codec;
                if(streamCodec->coded_frame->pts != AV_NOPTS_VALUE)
                        pkt.pts = av_rescale_q(streamCodec->coded_frame->pts,
streamCodec->time_base, stream->time_base);
                if(streamCodec->coded_frame->key_frame)
                        pkt.flags |= PKT_FLAG_KEY;
                pkt.stream_index = stream->index;
                pkt.data = encodedFrame;
                pkt.size = encodedSize;
                
                int result = av_interleaved_write_frame(formatContext, &pkt);
                if(result < 0){
                        // error handling
                }
}

-----------------------------

encodedFrame is a buffer containing the output of
avcodec_encode_video. Am I skipping some essential procedure in the
above snippets?
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to