Hi
After a lot of time and work, finally I've a solution for output MPEG2-TS
in rtp.
So Thank you Luca for your help.
The way it works is: (the way described by Luca)
1. Prepare the MPEG-TS AVFormatcontext with all streams and other things
to do
2. Instead of call url_open_file() you make the following:
ByteIOContext *ioctx;
if (res = url_open_dyn_buf(&ioctx))
{
return -1;
}
ts_context->pb = ioctx;
ts_context is the MPEG-TS (oformat) with video + audio Streams
3. Prepare a context for the rtp-Output
Code:
AVFormatContext *rtpcontext = av_alloc_format_context();
if (!rtpcontext) return -1;
rtpcontext->oformat = guess_format("rtp",0,0);
AVStream *fakevideo = 0;
fakevideo = av_new_stream(rtpcontext,0); //Videostream as fakeinput
MPEG-TS
if (!fakevideo) return -1;
avcodec_get_context_defaults(fakevideo->codec);
fakevideo->codec->codec_id = CODEC_ID_MPEG2TS;
rtpcontext->audio_codec_id = CODEC_ID_NONE;
rtpcontext->video_codec_id = CODEC_ID_MPEG2TS;
res = av_set_parameters(rtpcontext,0);
//the real output destination
res = url_fopen(&rtpcontext->pb,"rtp://1.1.1.1:8000", URL_WRONLY);
3. OK to initialize outputs call av_write_header() for both contexts
4. for every packet I do (video only, but audio is the same):
av_init_packet(&avpkt); // ts-packet
av_init_packet(&tspkt); // rtp-packet
outframe->interlaced_frame = 1; //if wanted and in video parameters defined
outframe->top_field_first = 1;
enc_size = avcodec_encode_video(videocodectx, videobuf ,videobuf_size,
outframe); // encode videoframe
if (enc_size > 0)
{
if (videocodectx->coded_frame->key_frame)
{
avpkt.flags |= PKT_FLAG_KEY;
}
avpkt.size= enc_size;
avpkt.pts = av_rescale_q(videocodectx->coded_frame->pts,
videocodectx->time_base, videostm->time_base);
avpkt.stream_index= videostm->index;
avpkt.data= videobuf;
// write into the dyn_buf (ts-context)
ret = av_interleaved_write_frame(ts-context, &avpkt);
//close the buffer to read the bytes
len = url_close_dyn_buf(ioctx, &destbuff);
//prepare the packet for rtp
tspkt.size = len;
tspkt.data = destbuff;
//write to output , not sure if _interleaved_ is the right call
av_interleaved_write_frame(rtpcontext, &tspkt);
av_free(destbuff);
//open new buffer for the next frame
if (res = url_open_dyn_buf(&ioctx))
{
return -1;
}
For me it works and I can play it with vlc and also my program for
validating ts doesn't throw errors.
Steffen
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user