/* A simple filter (stdin -> stdout) to extract a single stream from a multiplexed TS. Specify the PID on the command-line */ #include #include int main(int argc, char **argv) { int pid, pid1, pid2, n; unsigned char buf[188]; pid1=atoi(argv[1]); if ( argc >2 ) pid2=atoi(argv[2]); else pid2 = -1; fprintf(stderr,"filtering PIDS : %d %d\n",pid1,pid2); for (;;) { n=fread(buf,1,188,stdin); if (n==188) { pid = (((buf[1] & 0x1f) << 8) | buf[2]); if (pid1==pid || pid2==pid ) fwrite(buf,1,188,stdout); } } }