[MPlayer-dev-eng] MPEG-PES detection problem

nsabbi@libero.it nsabbi at libero.it
Sat Sep 28 17:00:20 CEST 2002


Hi, 
 
I'm trying to generate an MPEG-PES out of a transport stream 
stripping the transport headers (including the eventual adaption 
field) and the first sequence of ES bytes preceding the very first  
PES header (TS_HAS_PSI field in the header); 
I hoped this process would  output a valid MPEG-PES with audio and 
video PES interleaved, but mplayer always sees it as an MPEG-ES with 
only video. 
 
The code is the following. Can anyone help  me please? 
Thanks! 
 
 
#include <stdio.h> 
#include <stdlib.h> 
 
 
#define TS_SIGNATURE 0x47 
#define TS_PAYLOAD_HAS_PES 0x40 
#define TS_HAS_ADAPTION_FIELD   0x20 
#define TS_HAS_PAYLOAD 0x10 
 
typedef  unsigned char uint8_t; 
 
int main(int argc, char *argv[]) 
{ 
	int f = fileno(stdin), y = 0; 
	unsigned char buffer[188]; 
	int ok = 0, pid, count, has_new_pes, chr; 
 
	while(! feof(stdin)) 
	{ 
		read(f, buffer, 188); 
		 
		    count = 4; 
		 
		    if (!(buffer[3] & TS_HAS_PAYLOAD)) // packet 
without payload? 
		    { 
			fprintf(stderr, "! TS_HAS_PAYLOAD, SKIP\n"); 
			continue; 
		    } 
			 
		    has_new_pes = buffer[1] & TS_PAYLOAD_HAS_PES;	 
		    if(! has_new_pes) 
		    { 
		    	if(y == 0) 
		    	{	 
				//DUMPED ES 
		    		continue; 
		    	} 
		    } 
		    else 
		    { 
		    	y = 1; 
		    } 
		    	 
		    chr = 0; 
		     
		 
		    if (buffer[3] & TS_HAS_ADAPTION_FIELD)  
		    { 
 
			fprintf(stderr, "ADAPTION, DISCARD %d 
BYTES\n", chr); 
 
			count += chr; 
		    } 
 
		write(fileno(stdout), &buffer[count], 188-count); 
	} 
} 
	 
	 
 
 
 
 




More information about the MPlayer-dev-eng mailing list