Hello all, 

I can create a Transport Stream (ts) with 188 byte packet size with
libavformat. This works fine. But I can not create an m2ts (MPEG 2 Transport
Stream-File) for bluray or such media. I looked into the mpegts.h and
mpegts.c - file (under /libavformat) and see, that the 192byte Paket Size
exists as an macro. But it seems that libavformat only support m2ts-reading.
So my question is now, exists an hint to create a m2ts-Stream? 

Or alternatively: 

I can not find any information of how building an m2ts-Stream. OK I know
that m2ts is only a 188byte ts-packet plus 4 byte Timecode. BUT How is the
TimeCode build??? And how is the TimeCode saved??? Do I have to append it at
the end of an "normal" ts packet? 

Could anyone give me some hints? 
Steffen Ebersbach wrote:
> 
> 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
> 
> 

I am trying to do more or less the same without success.
In ffserver I am trying to send a mpegts file video over RTP transport MT2P,
thats is only mpegts packets without demux them, in one raw stream.
We have follow the way you have do it and adapt the cmd_setup and cmd_play
to work with the STB client I have to use, that only understand MP2T.
Sending data we are quite loose.
Could you please help us?? 

the point 4. Do you use it in http_prepare_data??

-- 
View this message in context: 
http://libav-users.943685.n4.nabble.com/Output-mpeg-ts-to-rtp-tp2234066p3263338.html
Sent from the libav-users mailing list archive at Nabble.com.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to