From: Rij van C <cvrij@cs.vu.nl>
Newsgroups: comp.os.linux.announce
Subject: mpeg_sync 0.1
Date: 30 Jul 1994 02:05:49 +0300
Approved: linux-announce@tc.cornell.edu (Lars Wirzenius)
Message-ID: <31c20d$nf9@kruuna.Helsinki.FI>

Below is a patch I made for mpeg_play 2.0 (the berkeley mpeg_player)
to add soundeffects to an mpeg_sequence. This patch allows you to 
start (among other things) programs like tracker at a certain 
point in the animation, thereby providing sound-effects or 
sound-tracks with a sound-less mpeg. 
As long as you don't claim to have written it yourself, 
you can do with it whatever you like.

-- introduction and diff ---------

Extract from the ANNOUNCE file from the MPEG_PLAY-2.0 package:
-------- cut -------
The Berkeley Plateau Research Group is happy to announce the
release of Version 2.0 of its software-only MPEG decoder.
The player is available via anonymous ftp from toe.cs.berkeley.edu
(128.32.149.117) in /pub/multimedia/mpeg/mpeg-2.0.tar.Z.

                  MPEG Video Software Decoder
                  (Version 2.0; Jan 27, 1993)

-------- cut --------
Below are the diffs with the original files; once applied, 2 new 
options are available. the '-fadeout n' option is not fully 
implemented, but if anyone should feel like making it work
better, I will encourage this. Now the specified image will just 
remain on-screen, just to prevent the sudden disappearance of 
the picture.
The more important option is the '-sync' option.
This option may be used in 2 ways: 
-sync:20 'scream 20 &'
will execute the scream command just before frame 20 is displayed,
with the argument 20. as a result of the added '&' mpeg_play will continue
directly after starting the process. MIND THE QUOTES!
The second possible way to use th option is without the colon:
-sync <syncfile>
where syncfile is the name of a file containing (multiple) lines in the
following format:
<frame_nr> <action>
where <frame_nr> is the number of the frame before which the action must be 
performed; anything after the space following the number will be executed
as-if it were typed to the shell. No quotes are necesary.

Although the variable names I used all use the sound prefix, there is 
no reason why you wouldn't be able to start anything else you'd like,
like another mpeg_play, a jpeg-viewer, etc. (As i've done)

-- start of diffs ----------

diff mpeg_play-2.0/gdith.c mpeg_diff/gdith.c
24a25
> #include <unistd.h>
540a542
>   char *cmdptr;
544c546
<     fprintf (stderr, "%d\r", totNumFrames);
---
>       fprintf (stderr, "%d%s", totNumFrames, "\r");
545a548,563
>   if (soundsync >=0) {  			/* waiting for sync ? */
>     if (soundsync <= totNumFrames) {		/* action due ? */
>       system(soundcommand);			/* execute it */
>       if (!syncfd ||				/* are we reading from file ? */
>           !fgets(soundcommand, 80, syncfd) || 		/* more sync-lines? */
>           !sscanf(soundcommand,"%d",&soundsync) ) {	/* valid line? */
>         soundsync= -1;
>         if (syncfd) fclose(syncfd);		/* close file if used */
>         if (!quietFlag) fprintf(stderr,"All syncs processed.\n");
>       } else {					/* edit out frame number */
>         for (cmdptr= soundcommand; cmdptr[0]!=' '; cmdptr++) cmdptr[0]= ' '; 
>         if (!quietFlag)
>           fprintf(stderr,"Next sync @ %01d= %s\n",soundsync, soundcommand); 
>       }
>     } else if (!quietFlag) printf("sync-%01d\n",soundsync-totNumFrames); 
>   }
597a616,618
>     if ( fadeout && fadeout==totNumFrames ) {
>       while (1) ;		/* unimplemented, just sit there and wait */
>     }
diff mpeg_play-2.0/main.c mpeg_diff/main.c
64a65,72
> /* soundsync flag  & buffer */
> int soundsync = -1;
> char soundcommand[80]= "";
> FILE *syncfd= 0;
> 
> /* fadeout flag */
> int fadeout = 0;
> 
221c229
<   char *name;
---
>   char *name, *cmdptr;
318a327,356
>     else if (strncmp(argv[mark], "-sync", strlen("-sync")) == 0) {
>       if (strlen(argv[mark])== strlen("-sync")) {
>         syncfd= fopen(argv[++mark],"r");
>         if (!syncfd) fprintf(stderr,"Syncfile %s not found\n", argv[mark]);
>         else {
>           if (!fgets(soundcommand, 80, syncfd) ||
>               !sscanf(soundcommand,"%d",&soundsync) ) {
>             soundsync= -1;
>             fprintf(stderr,"No sync-commands in %s!\n",argv[mark]);
>             fclose(syncfd);
>           } else {
>             for (cmdptr= soundcommand; cmdptr[0]!=' '; cmdptr++) cmdptr[0]= ' ';
>             if (!quietFlag) 
>                fprintf(stderr,"1st sync @ %01d= %s\n",soundsync, soundcommand);
>           }
>         } 
>         mark++;
>       } else {
>         sscanf(argv[mark++], "-sync:%d",&soundsync);
>         strcpy(soundcommand, argv[mark++]);
>         if (!quietFlag) 
>           printf("Delay: %01d, command: %s\n",soundsync, soundcommand); 
>       }
>       argc-= 2;
>     }
>     else if (strcmp(argv[mark], "-fadeout") == 0) {
>       fadeout= atoi(argv[++mark]);
>       mark++;
>       argc-= 2;
>     }
533a572,573
>     fprintf(stderr, "          [-fadeout n]\n");
>     fprintf(stderr, "          [-sync[:n] {file|command}]\n");
diff mpeg_play-2.0/video.h mpeg_diff/video.h
254a255,262
> /* soundsync flag & buffer */
> extern int soundsync;
> extern char soundcommand[80];
> extern FILE *syncfd;
> 
> /* fadeout flag */
> extern int fadeout;
> 

--
Send submissions for comp.os.linux.announce to: linux-announce@tc.cornell.edu
PLEASE remember Keywords: and a short description of the software.
