POV-Ray : Newsgroups : povray.advanced-users : movie within : Re: movie within Server Time
28 Jul 2024 20:25:46 EDT (-0400)
  Re: movie within  
From: Dan P
Date: 27 Jan 2004 18:37:05
Message: <4016f621$1@news.povray.org>
"Marvin Taylor" <pov### [at] maltasoftcom> wrote in message
news:4016ef9f$1@news.povray.org...
> Dan P wrote:
<clip>
> This requires your frame rate to exactly match that of the movie you are
> including.  A more consistent approach would be to interpolate based on
> 'clock' rather than 'frame_number'.

A thing to consider when merging two movies with different frame rates is
whether the playback will be noticably inconsistent if the frame rate of the
embedded movie and the framerate of the containing movie are different. You
may have to "average" frames together in order to get a smoother
presentation. If the framerates don't share a common divisor, you'll find it
more challenging to average them together, but it's possible (that's how
they manage to show 24fps movies on 60fps television screen).

Averaging frames together also happens to be the way to do motion blur. The
following C program is a program I built to do just that with PPM files
(that povray can output):

The usage is simple:
blur x y x2 y2 file1.ppm, file2.ppm, file3.ppm, ...
x y x2 y2 grabs that rectangle out of the PPM file so that you can cut out
parts of an image.
It will average as many frames together as you provide on the command line.
I use pnmtopng to process the PPM's later to import into Flash.
Viva la Open Source, baby!


#include <stdio.h>
#include <stdlib.h>


unsigned *buffer = NULL;
char *page = NULL;
unsigned units = 0;
int frames = 0;
int width;
int height;
unsigned x;
unsigned y;
unsigned x2;
unsigned y2;
unsigned w;
unsigned h;



void load (char *path);
void readToken (FILE *stream, char *buf);
void blur();



int main (int argc, char **argv)
{
 int i = 1;

 x = atoi(argv[i++]);
 y = atoi(argv[i++]);
 x2 = atoi(argv[i++]);
 y2 = atoi(argv[i++]);

 w = x2 - x;
 h = y2 - y;

 while (argv[i] != NULL)
 {
  load(argv[i]);
  ++i;
  ++frames;
 }

 blur();

 free((void *) buffer);
 free((void *) page);

 return 0;
}



void blur()
{
 unsigned i;
 unsigned xn;
 unsigned yn;
 unsigned r;
 unsigned g;
 unsigned b;

 fprintf (stderr, "Blurring %u frames together.\n", frames);

 printf ("P6\n%d %d\n255\n", w, h);
 fprintf (stderr, "Building a %d by %d file.\n", w, h);

 for (yn = y ; yn < y2 ; yn++)
 {
  for (xn = x ; xn < x2 ; xn++)
  {
   i = (yn * (width * 3)) + (xn * 3);

   putchar (buffer[i++] / frames);
   putchar (buffer[i++] / frames);
   putchar (buffer[i] / frames);
  }
 }

 fflush(0);
}



void load (char *path)
{
 FILE *stream;
 char s_version[1024];
 char s_width[1024];
 char s_height[1024];
 char s_depth[1024];
 unsigned size;
 unsigned i;
 int c;


 if ((stream = fopen(path, "rb")) != NULL)
 {
  readToken(stream, s_version);
  readToken(stream, s_width);
  readToken(stream, s_height);
  readToken(stream, s_depth);

  width = atoi(s_width);
  height = atoi(s_height);

  if (buffer == NULL)
  {
   units = width * height * 3;
   buffer = (unsigned *) malloc(units * sizeof(int));
   page = (char *) malloc(units);

   fprintf (stderr,
     "Memory: %u for a %d x %d file.\n",
     units, width, height);

   for (i = 0 ; i < units ; i++)
   {
    buffer[i] = 0;
    page[i] = 0;
   }
  }

  i = 0;

  while ((c = fgetc(stream)) != EOF)
  {
   buffer[i++] += c;
  }

  fclose(stream);
 }
 else
 {
  fprintf (stderr, "  FAILED to read %s\n", path);
 }
}



void readToken (FILE *stream, char *buf)
{
 int c;
 c = fgetc(stream);

 while (c != EOF)
 {
  *(buf++) = c;

  c = fgetc(stream);

  if (isspace(c))
  {
   *buf = '\0';
   return;
  }
 }
}


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.