Note that there are some explanatory texts on larger screens.

plurals
  1. POLibAV Mpeg_TS stream doesn't appear to contain I frames
    primarykey
    data
    text
    <p>I'm trying to take a YUV 420 stream, convert it to MPEG2 and send it via UDP as a transmport stream.</p> <p>The conversion appears to work correctly, by saving the output I can create a playable MPEG. When viewing the transmitted packets in wireshark I am able to see the Program Association, and Program Map tables (they appear correct) and the b-frames and p-frames. I'm unable to see any I-frames but can see MPEG sequence header packets.</p> <p>Using VLC I am unable to view the stream (UDP://239.192.1.114:6677)</p> <p>Below is a code snippet showing the conversion and the transmission of video packets.</p> <p>Any ideas on why I can't see the I-frames would be greatly appreciated.</p> <pre><code>bool MPEGTransmitter::InitMPEG(int width, int height) { /* find the mpeg2 video encoder */ codec = avcodec_find_encoder(CODEC_ID_MPEG2VIDEO); if (!codec) { //debugCb("Codec Not Found"); //fprintf(stderr, "codec not found\n"); return false; } codecCtxt = avcodec_alloc_context3(codec); picture= avcodec_alloc_frame(); /* put sample parameters */ codecCtxt-&gt;bit_rate = 0; /* resolution */ codecCtxt-&gt;width = width; codecCtxt-&gt;height = height; /* frames per second */ AVRational avr; avr.den = 25; avr.num = 1; codecCtxt-&gt;time_base= avr; codecCtxt-&gt;gop_size = 5; /* emit one intra frame every 5 frames */ codecCtxt-&gt;max_b_frames=2; codecCtxt-&gt;pix_fmt = PIX_FMT_YUV420P; // 4:2:0 used for MPEG /* open it */ if (avcodec_open2(codecCtxt, codec,NULL) &lt; 0) { //debugCb("Could not open video codec"); //fprintf(stderr, "could not open codec\n"); return false; } /* alloc image and output buffer */ outbuf_size = 100000; outbuf = (uint8_t*)malloc(outbuf_size); size = codecCtxt-&gt;width * codecCtxt-&gt;height; picture_buf = (uint8_t*)malloc((size * 3)/2); /* size for YUV 420 */ picture-&gt;data[0] = picture_buf; picture-&gt;data[1] = picture-&gt;data[0] + size; picture-&gt;data[2] = picture-&gt;data[1] + size/4; picture-&gt;linesize[0] = codecCtxt-&gt;width; picture-&gt;linesize[1] = codecCtxt-&gt;width /2 ; picture-&gt;linesize[2] = codecCtxt-&gt;width /2; SaveToFile(outfileName); //MpegInitialised = true; std::stringstream ssLog; ssLog &lt;&lt; "MPEG initialised with Height "&lt;&lt; height &lt;&lt; " Width " &lt;&lt; width &lt;&lt; endl; WriteLogMsg(ssLog.str()); return true; } void MPEGTransmitter::WriteFrame(unsigned char* Yarray, unsigned char* cbArray, unsigned char* crArray) { /* prepare the image */ /* Y */ int idx=0; for(int y=0;y&lt;codecCtxt-&gt;height;y++) { for(int x=0;x&lt;codecCtxt-&gt;width;x++) { picture-&gt;data[0][y * picture-&gt;linesize[0] + x] = Yarray[idx++]; } } /* Cb and Cr */ for(int y=0;y &lt; codecCtxt-&gt;height/2 ;y++) { for(int x=0;x&lt; codecCtxt-&gt;width/2 ;x++) { picture-&gt;data[1][y * codecCtxt-&gt;width/2 + x] = (cbArray[(y*codecCtxt-&gt;width)+x] + cbArray[(y*codecCtxt-&gt;width)+ x+1])/2; picture-&gt;data[2][y * codecCtxt-&gt;width/2 + x] = (crArray[(y*codecCtxt-&gt;width)+x] + crArray[(y*codecCtxt-&gt;width)+ x+1])/2; } } /* encode the image */ out_size = avcodec_encode_video(codecCtxt, outbuf, outbuf_size, picture); /* send the image */ WriteMpegTS(outbuf, out_size,0x1F); /* save the image */ if( fVideoOut ) { fwrite(outbuf, 1, out_size, fVideoOut); } } void MPEGTransmitter::WriteMpegTS(uint8_t* pPayloadPkt, int iPktSize, unsigned int iPidLower) { int dataCounter = 0; bool firstPacket=true; while(dataCounter &lt; iPktSize) { // TS Packets are 188 bytes long, 4 byte header followed by payload char* pTSPkt = new char[188]; pTSPkt[0] = 0x47; // Sync byte if(firstPacket) { pTSPkt[1] = 0x40; // start of payload flag set + high bytes of payload id firstPacket=false; } else { pTSPkt[1] = 0; // start of payload flag not set + high bytes of payload id } pTSPkt[2] = iPidLower; // low bytes of payload id pTSPkt[3] = 0x10 | getContinuityCounter(iPidLower); //returns the cont. counter for the specified pkt type // Fill the rest of the packet with data, or padding if no more data to add for(int i= 4; i&lt; 188; i++) { if(dataCounter &lt;iPktSize) { pTSPkt[i] = pPayloadPkt[dataCounter++]; } else { pTSPkt[i] = 0xFF; } } // Send the packet over multicast/rtp unsigned int pktSize = 188; sktMpeg-&gt;SendMsg(pTSPkt, pktSize); // calls the sendMsg function of the socket class } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload