By Date: <-- -->
By Thread: <-- -->

how to demux a TS file



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Francesco Dalla Torre wrote:
> Hi Brice,
> 
> I need to dump datas associated to a particular PID.
> 
> So first I need to demux the TS file to pick up datas associated to a
> particular ID and then put this information in an another output file
> 
> For example, i want to dump the PAT table (PID=0x00).
> I suppose I can do that if I had a DVB-S or DVB-T or DVB-C receiver. I want
> to know if I can do that also if my source is a normal file (I suppose it's
> possible..)
> 
> The solution may be to "say" (changing the code) to the dvb-core.ko driver
> that my source is not a frontend but a normal file...
> 
> Anyway, thank for your help!
> 
> Francesco
> 
> On 3/1/06, DUBOST Brice <dubost (at) crans.ens-cachan.fr> wrote:
>> Francesco Dalla Torre wrote:
>>> Hello to all,
>>>
>>> I know it may seem a silly question but i tried out for a week and i
>> don't
>>> achieve anything.
>>>
>>> So, my problem is: how can i demux a file MPEG-2 Transport Stream?. I
>> mean:
>>> i compiled and installed the dvb-core driver but there is not any
>>> application that can use a source file instead of a typical frontend
>> source.
>>> Have i to create a "virtual frontend" that simulates a standard
>> frontend? Is
>>> there a simpler way?
>>>
>>> Any help would be really appreciate!!
>>>
>>> Thank you,
>>>
>>> bye
>>>
>>> Francesco

Hello
I give you a very littel program who can do that.
You must edit the source in order to choose the pids you wants (I
haven't took the time to make this as an argument)

Regards

- --
Brice

Join us now and share the software;
You'll be free, hackers, you'll be free.
[Richard STALLMAN, free software song]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (GNU/Linux)

iD8DBQFEBYlDIn6OIr0VbMQRAqc/AJ92O4at62Wcwdk7jYfWbei8w4F3KACfTzJV
CuxyyTopoYXwH1/I+wiArwA=
=HnNk
-----END PGP SIGNATURE-----
/* A simple filter to extract multiple streams from a
   multiplexed TS.
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>



int main(int argc, char **argv)
{
  int pid,n;
  int filters[8192];
  unsigned int i=0;
  unsigned int j=0;
  unsigned int k=0;
  unsigned int l=0;
  //  char buf[188];
  unsigned char buf[188];
  unsigned char my_cc[8192];
  int errors=0;
  int nb_bytes=0;
  char *entree_filename = NULL;
  char *sortie_filename = NULL;
  FILE *sortie,*entree;
  int c,option_index=0;

  char eitbuf[4096];

  const char short_options[] = "e:s:";
  const struct option long_options[] = 
    {
      {"entree", required_argument, NULL, 'e'},
      {"sortie", required_argument, NULL, 's'},
      {0, 0, 0, 0}
    };


  while (1)
    {
      c = getopt_long (argc, argv, short_options,
                       long_options, &option_index);
      if (c == -1)
        {
          break;
        }
      switch (c)
        {
        case 'e':
	  entree_filename = malloc (strlen (optarg) + 1);
	  strncpy (entree_filename, optarg, strlen (optarg) + 1);
          break;
        case 's':
	  sortie_filename = malloc (strlen (optarg) + 1);
	  strncpy (sortie_filename, optarg, strlen (optarg) + 1);
          break;
	case 'h':
	  break;
	}
    }
  if (optind < argc)
    {
      fprintf(stderr,"Too few arguments\n Usage : extract_pid -e file_in -s file_out");
      exit(1);
    }


  if (!entree_filename || !sortie_filename)
    {
      fprintf(stderr,"You must specify filenames\n");
      exit(2);
    }


  entree=fopen(entree_filename, "r");
  if (!entree)
    {
      fprintf (stderr,
	       "%s: %s\n",
	       entree_filename, strerror (errno));
      exit(3);
    }
  sortie=fopen(sortie_filename, "w");
  if (!entree)
    {
      fprintf (stderr,
	       "%s: %s\n",
	       sortie_filename, strerror (errno));
      exit(3);
    }


  for (i=0;i<8192;i++) { filters[i]=0; my_cc[i]=0xff;}


  n=fread(buf,1,188,entree);
  i=0;
  while (n==188&&i<2000000)
    {
      if (buf[0]!=0x47)
	{
	  // TO DO: Re-sync.
	  fprintf(stderr,"FATAL ERROR IN STREAM AT PACKET %d\n",i);
	  //      exit;
	}
      pid=(((buf[1] & 0x1f) << 8) | buf[2]);
      if (my_cc[pid]==0xff)
	my_cc[pid]=buf[3]&0x0f;


      //MOdifiy Here to choos your pids
      if((pid==0)||(pid==18))
	{
	  fwrite(buf,1,188,sortie);
	  j++;
	}

      filters[pid]++;
    
      n=fread(buf,1,188,entree);
      i++;
    }
  fclose(sortie);
  fprintf(stderr,"Read %d packets, wrote %d.\n",i,j);
  fprintf(stderr,"%d incontinuity errors.\n",errors);

  return(0);
}




--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request (at) redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list