Example #1
0
int main(int argc, char **argv)
{
	av_log_set_flags(AV_LOG_SKIP_REPEATED);
	av_register_all();
	avformat_network_init();

	const char *filename = argv[1];
	demuxer dmux;
	dmux.open_input(filename);
	frame_loop(dmux);
	return 0;
}
Example #2
0
/**
 * entry point
 */
int main (int argc, char *argv[]) {

   uint16_t width, height, fps = 25, bit_depth = 8;
   uint32_t audio_buffer_size, pixel_buffer_size;
   char * audio_path;
   char * output_dir = "";

   size_t audio_frames, video_frames;

   SNDFILE *audio_file;
   SF_INFO info;

   if(argc<5) {
      printf("Usage: %s <audio file> <width> <height> <fps> [<ouput dir>]\n", argv[0]);
      return (ERROR);
   }

   audio_path = argv[1];

   if(argc>=6) {
      output_dir = argv[5];
      size_t len = strlen(output_dir);
      while(output_dir[len - 1] == '/' && --len) {
         output_dir[len] = '\0';
      }
      if(access(output_dir, W_OK) != 0) {
         printf("output_dir '%s' is not accessible\n", output_dir);
         return (ERROR);
      }
   }
   if(argc>=4) {
      fps = atoi(argv[4]);
   }

   width  = atoi(argv[2]);
   height = atoi(argv[3]);

   if(width<MINWIDTH || width>MAXWIDTH || height<MINHEIGHT || height>MAXHEIGHT) {
      printf("width must be beetween %d and %d, height between %d %d\n", MINWIDTH, MAXWIDTH, MINHEIGHT, MAXHEIGHT );
      return (ERROR);
   }

   if(fps<MINFPS || fps>MAXFPS) {
      printf("frames per second must be between %d and %d\n", MINFPS, MAXFPS );
      return (ERROR);
   }

   memset (&info, 0, sizeof (info)) ;

   // open soundfile
   audio_file = sf_open(audio_path, SFM_READ, &info);
   if (audio_file == NULL) {
       printf ("failed to open file '%s' : \n%s\n", audio_path, sf_strerror (NULL));
       return (ERROR) ;
   }

   if(info.channels<1) {
      puts("no audio channels.");
      return (ERROR);
   }

   // allocate buffer
   audio_frames = floor(info.samplerate / fps);
   audio_buffer_size = info.channels * audio_frames;
   pixel_buffer_size = width * height * BYTES_PER_PIXEL;

   if (audio_buffer_size > pixel_buffer_size) {
      printf(
         "audiobuffer (%d) greater than pixel buffer (%d). can't handle this atm.\n",
         audio_buffer_size,
         pixel_buffer_size
      );
      printf("samplerate: %d, channels: %d\n", info.samplerate, info.channels);
      return (ERROR);
   }

   //printf("row_pointers: %lu \npixelbuffer: %lu pixelrow: %lu pixel: %lu\n", sizeof(row_pointers) / sizeof(row_pointers[0]), sizeof(pixelbuffer), sizeof(pixelbuffer[0]), sizeof(pixelbuffer[0][0]));
   //output_rows(width, height, row_pointers);

   video_frames = ceil(fps * info.frames / (int) info.samplerate);
   //printf("video_frames: %u, audioframes: %u, samplerate: %u\n", v_frames, info.frames, (int) info.samplerate);

   if(video_frames < 1) {
      puts("not enough samples for a video frame");
      return(ERROR);
   }

   s_dimension dimension = {width, height, audio_frames, (short)info.channels, bit_depth};

   for(size_t frame=0; frame<video_frames; frame++) {
      frame_loop(frame, output_dir, audio_file, dimension);
   }

   sf_close (audio_file);
   return(0);

}