-
Notifications
You must be signed in to change notification settings - Fork 41
Description
Hi,
thank you for the great effort to create this library. I am trying to use it in my own project, however, I am getting garbled output in the mpeg-ts with AVC.
I have tried the following versions (2013/07/13)
libmpegts-master
libmpegts-obe-master
libmpegts-20130401-STABLE
I have used the following compilers:
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9), Target: x86_64-linux-gnu
gcc version 4.7.3 (rev1, Built by MinGW-builds project), Target: i686-w64-mingw32
gcc version 4.7.3 (rev1, Built by MinGW-builds project), Target: x86_64-w64-mingw32
The generated MPEG-TS is fine, e.g. tsreport (of tstools) as well as code.google.com/p/tsdemuxer can handle it without complaints. However, the demuxed set of NAL units is garbled. When I do a binary diff with the original bytestream, I can observe that there are a couple of bytes missing and some are inserted. The extracted h264 bitstream is also shorter than the original.
As I am using 32bit and 64 bit compilers on both Win and Linux and the problem persists, this seems to be a problem of compiling the libmpegts objects. Can you give me any hints on why this is happening and how to avoid it?
Here's the code for initialization of libmpegts
ts_program_t tsprog = {0};
tsprog.num_streams = 1;
tsprog.pcr_pid = 110;
tsprog.pmt_pid = 120;
tsprog.program_num = 1;
tsprog.sdt.provider_name = provider_name;
tsprog.sdt.service_name = service_name;
tsprog.sdt.service_type = 0x19;
tsprog.streams = (ts_stream_t_) calloc( tsprog.num_streams, sizeof(_tsprog.streams) );
if( !tsprog.streams ) {
fprintf( stderr, "malloc failed\n" );
return 1;
}
tsprog.streams[0].pid = 130;
tsprog.streams[0].stream_format = LIBMPEGTS_VIDEO_AVC;
tsprog.streams[0].hdmv_video_format = LIBMPEGTS_HDMV_1080P;
tsprog.streams[0].hdmv_frame_rate = 25;
tsprog.streams[0].hdmv_aspect_ratio = LIBMPEGTS_HDMV_AR_16_9;
tsprog.streams[0].stream_id = 224;
ts_main_t tsmain = {0};
tsmain.muxrate = 200000000;
tsmain.num_programs = 1;
tsmain.pat_period = 50;
tsmain.pcr_period = 40;
tsmain.programs = &tsprog;
tsmain.sdt_period = 1000;
tsmain.ts_id = 1;
tsmain.ts_type = TS_TYPE_GENERIC;
tswriter = ts_create_writer();
int tsts_ret = ts_setup_transport_stream(tswriter,&tsmain);
if(tsts_ret < 0)
return 0;
int tsvideo_ret = ts_setup_mpegvideo_stream(tswriter,130,30,AVC_MAIN,0,0,0);
if (tsvideo_ret < 0)
return 0;
...
When a NAL unit is ready, the following code is executed
ts_frame_t coded_frames[1];
coded_frames[0].cpb_final_arrival_time = cbp_fat;
coded_frames[0].cpb_initial_arrival_time = cbp_iat;
coded_frames[0].pts = pts;
coded_frames[0].dts = dts;
coded_frames[0].frame_type = type;
coded_frames[0].data = data;
coded_frames[0].size = data_len;
coded_frames[0].pid = 130;
uint8_t *output;
int len;
int64_t *pcrlist;
int ret = ts_write_frames(tswriter,&coded_frames[0],1,&output,&len,&pcrlist);
if(len) write...