home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk1.iso / altsrc / articles / 10660 < prev    next >
Text File  |  1994-06-19  |  5KB  |  126 lines

  1. Newsgroups: alt.binaries.pictures.utilities,alt.sources
  2. Path: wupost!crcnis1.unl.edu!news.mid.net!newsfeed.ksu.ksu.edu!moe.ksu.ksu.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!gatech!newsfeed.pitt.edu!uunet!nntp.cadence.com!cds9172.Cadence.COM!daled
  3. From: daled@cds9172.Cadence.COM (Dale DePriest)
  4. Subject: source code for mpg_cat
  5. Message-ID: <CrCJF3.5ML@Cadence.COM>
  6. Sender: news@Cadence.COM
  7. Nntp-Posting-Host: cds9172.cadence.com
  8. Organization: Cadence Design System, Inc.
  9. Date: Mon, 13 Jun 1994 17:33:02 GMT
  10. Lines: 112
  11. Xref: wupost alt.binaries.pictures.utilities:18111 alt.sources:10660
  12.  
  13. As a thank you to all of the free software posts, here is one.
  14. There have been several requests to be able to display multiple mpeg files so I whipped this little utility together.
  15.  
  16. Documentation.
  17.  
  18. This is a simple filter that will permit concatenating several mpg files together for viewing.  You simply list the ones you want on the command line. It turns out that the mpeg_play command released by berkeley will accept input form standard in so the output of this utility can be piped directly in.  If your viewer won't work that way then you will need to send the output of mpg_cat to a file and then read it in separately.  It works by stripping the trailer information from the files so that the viewer 
  19.  
  20. will continue to read the file.  It then adds a trailer at the end of the last file.
  21.  
  22. This program may be useful for adding a trailer to a file that is missing one.  It could also be used to view a file that had a missing header so long as another file listed earlier had one that matched the width and height of the desired file.
  23.  
  24. There is very simple minded support for standard in as well so you could feed
  25. this program from yet another filter.
  26.  
  27. Limitations:
  28.  
  29. Some mpg files have information ahead of the header line.  This program will not work with these files except for the first one.  It could be modified easily to remove this extra stuff but then it would require a header line for every file.  Perhaps I could add this if needed, or since you have the source you can fix it yourself.  This program will remove any extra data after the trailer data.
  30.  
  31. This program is smart enough to reject files that have different widths from the first file since these don't merge very well.  It does not check the height of the file but could be modified to do so, of course.  If the height of a file in the list is less than the first file then everything will probably be ok but if it is taller then you will have trouble.
  32.  
  33. There is no warranty, of course.  Enjoy.
  34.  
  35. ----Cut here for source-----------
  36. /*
  37.  mpeg_cat.c
  38.  
  39. This program behaves like a cat commmand and concatenates input files
  40. together.  It removes the mpg trailer on all but the last entry.  Output
  41. goes to standard out.  Try mpg_cat *.mpg | mpeg_play.
  42. It will ignore mpg files that have a different width than the original file
  43. since the berkely viewer doesn't permit changing the width of the picture in the middle of viewing it.
  44.  
  45. by Dale DePriest.
  46. */
  47.  
  48. #include <stdio.h>
  49.  
  50. main( argc, argv )  
  51. int argc;
  52. char **argv;    
  53. {
  54.     register int c;
  55.     int i;
  56.     int width = 0;
  57.     FILE *fp;
  58.     for( i = 1; i < argc; i++ )
  59.       {
  60.     if ( ( fp = fopen( argv[i], "r" ) ) == NULL )  {
  61.         fprintf( stderr, "can't open: %s,\n", argv[i] );
  62.         continue;
  63.         }
  64.  
  65.       top:
  66.     /* Look for header and trailer sequences. Use header to check
  67.      * for movie width and strip trailer from input file.
  68.      */
  69.     while ( ( c = getc( fp ) ) != EOF )  {
  70.       putchar (c);
  71.       if ( c != 0x00 )
  72.         continue;
  73.       if ( ( c = getc( fp ) ) != 0x00 ) {
  74.         putchar (c); 
  75.         continue;
  76.        }
  77.       while ((c = getc( fp )) == 0x00) putchar (c);
  78.       if ( c != 0x01 ) {
  79.         putchar (0x00) ; putchar (c);
  80.         continue;
  81.       }
  82.       /* 0xb3 starts the header sequence. width follows */
  83.       c = getc (fp);
  84.       if ( c == 0xb3 ) {
  85.         if ((c = getc (fp)) != width & width !=0 ) {
  86.           fprintf ( stderr, "ignoring %s, width %d\n", argv[i], c * 16 );
  87.           fclose (fp);
  88.           break;
  89.         }
  90.         else {
  91.           width = c;
  92.           putchar (0x00); putchar (0x01);
  93.           putchar (0xb3); putchar (c);
  94.           continue;
  95.         }
  96.       }
  97.       /* check for trailer sequence */
  98.       if ( c != 0xb7 ) {
  99.         putchar (0x00); putchar (0x01); putchar (c);
  100.       }
  101.       /* success - found trailer */
  102.       else if ( argc != 0 ) fclose (fp);
  103.  
  104.     }
  105.       }
  106.     /* also accept input from standard in */
  107.     if (argc == 1) {
  108.       argc = 0;
  109.       fp=stdin;
  110.       goto top;
  111.     }
  112.     /* add a new trailer after last input file */
  113.     putchar( 0x00 );
  114.     putchar( 0x00 );
  115.     putchar( 0x01 );
  116.     putchar( 0xb7 );
  117.     return 0;
  118.   }
  119.  
  120. /*
  121. -- 
  122.     _      _     Dale DePriest          San Jose, California
  123.    /`) _  //     daled@Cadence.COM        voice: (408) 428-5249
  124.  o/_/ (_(_X_(`                     fax: (408) 943-0402
  125. */
  126.