ImageProzessor Compiling make stills2dv for OSX

By January 7, 2016Uncategorized

First of all i have to mention that comping software i am very new to had just compiled ffmpeg and imagic for my Dev MAMP work field. But after got hot with image and video processing software like MLT . I just found the gorgeous branch stills2dv . Zooming probably is not the big thing but how the lib speed and slow up the pans and zooms is the best and most intuitive i have seen. Building the workfile is like writing a Text script how to zoom and Pan . Very simple if you have a bit of feeling for Pans & Zooms .

This stills2dv package have some very sweet Zoom and Pan options for still images but was build for Linux and some outdated lybs and commands made it a bit hard for me compile. for future i will note here what i change to get it work .Last but not least dropped in as i would like huge panorama images and return a video that can be shared on social media platforms like Facebook or Instagram. That as a terminal batch proces without opening any editing software.

Future idea is to create the workfile for pan zoom with a html editor.

First of all watch the video to get a impression what is the still2dv can do

First make sure you have the needed libs Installed

X11 installed

most likely this packages are already on your machine

libc
gcc
make
libjpeg-dev
libpng-dev

 

Some changes for the PATH to work on OSX below my make file with corrected paths. The only change was in the first lines  -lXext and -lX11 made me some trouble till i installed XQuartz .

PREFIX = /usr
CC = gcc
COPTIONS = -Wall -g -O4
CLIBS = -ljpeg -lpng -lm -I/opt/X11/include -L/opt/X11/lib/ -lXext -lX11

all: stills2dv

hash: hash.c stills2dv.h
	$(CC) -o hash $(COPTIONS) hash.c

stills2dv: s2d_main.o s2d_ppm.o s2d_jpg.o s2d_png.o s2d_smoothing.o x_lowlevel.o
	$(CC) -o stills2dv  $(COPTIONS) s2d_smoothing.o s2d_ppm.o s2d_jpg.o s2d_png.o s2d_main.o x_lowlevel.o $(CLIBS)
	echo You may try the command: make example

s2d_main.o: s2d_main.c stills2dv.h
	$(CC) $(COPTIONS) -c s2d_main.c

s2d_jpg.o: s2d_jpg.c stills2dv.h
	$(CC) $(COPTIONS) -c s2d_jpg.c

s2d_png.o: s2d_png.c stills2dv.h
	$(CC) $(COPTIONS) -c s2d_png.c

s2d_ppm.o: s2d_ppm.c stills2dv.h
	$(CC) $(COPTIONS) -c s2d_ppm.c

s2d_smoothing.o: s2d_smoothing.c stills2dv.h
	$(CC) $(COPTIONS) -c s2d_smoothing.c

x_lowlevel.o: x_lowlevel.c
	$(CC) $(COPTIONS) -c x_lowlevel.c

clean:
	rm -f *.o stills2dv hash Example/out.mpg tmp/* out.mpg tmp.mpg ffmpeg2pass*.log *~

clean_temp:
	rm -f *.o tmp/* tmp.mpg ffmpeg2pass*.log

example: stills2dv
	mkdir -p tmp
	rm -f tmp.mpg out.mpg
	./stills2dv -tmpdir tmp -showoutput exampleworkfile.s2d
	ffmpeg -r 30.00 -f image2 -i tmp/%05d.jpg -i example_data_files/09_1_2_3_4.mp3 -vcodec mpeg4 -vb 9000k -ab 128k -aspect 16:9 -pass 1 tmp.avi
	ffmpeg -r 30.00 -f image2 -i tmp/%05d.jpg -i example_data_files/09_1_2_3_4.mp3 -vcodec mpeg4 -vb 9000k -ab 128k -aspect 16:9 -pass 2 out.avi
	rm -f tmp/* tmp.avi
	mplayer out.avi -fs



install: stills2dv
	cp -f stills2dv $(PREFIX)/bin
	chmod 755 $(PREFIX)/bin/stills2dv
	chown root:root $(PREFIX)/bin/stills2dv

To run the Install you need also to adapt the install part since root:root doesn’t exist on osx .The install done manually in the terminal

One more change on s2d_png.c since libpng updated some commands will not work. My s2d_png.c following error found on stackoverflow

Chances are you are compiling IM with png.h from libpng-1.5.x but
* Bugs png_longjmp” only exists inlibpng-1.5.x.
* libpng-1.6.17 already installed

changeds2d_png.c to following . Mostly replaced the old format to the new strukture

png_create_info_struct
/**********************************************************************
 *
 * s2d_png.c
 *
 * Author: Denis-Carl Robidoux
 *
 * Copyrights and license: GPL v3 (see file named gpl-3.0.txt for details
 *
 *  
 *
 ***********************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <png.h>

#include "stills2dv.h"

Image *readpng(char *fn)
{
  unsigned char header[8]={0};
  int x, y, width, height;
  unsigned char *row;

  png_structp png_ptr;
  png_infop info_ptr;

  unsigned char  ** row_pointers;
  unsigned char *data;
  Image *img;
  FILE *in;
  TRACE;
  in = fopen(fn, "rb");
  if (!in)
    {
      fprintf(stderr," File %s could not be opened for reading", fn);
      return NULL;
    }
  if (fread(header, 1, 8, in)!=8)
    {
      fprintf(stderr, "Failed reading header of %s\n", fn);
      fclose(in);
      return NULL;
    }
  if (png_sig_cmp(header, 0, 8))
    {
      fprintf(stderr," File %s is not recognized as a PNG file", fn);
      fclose(in);
    }
     
  png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	
  if (!png_ptr)
    {
      fprintf(stderr," png_create_read_struct failed");
      fclose(in);
      return NULL;
    }

  info_ptr = png_create_info_struct(png_ptr);
  if (!info_ptr)
    {
      fprintf(stderr," png_create_info_struct failed");
    }

  if (setjmp(png_jmpbuf(png_ptr)))
    {
      fprintf(stderr," Error during init_io");
    }
  png_init_io(png_ptr, in);
  png_set_sig_bytes(png_ptr, 8);
  png_read_info(png_ptr, info_ptr);

  
  height = png_get_image_height( png_ptr,  info_ptr);
  width = png_get_image_width( png_ptr,  info_ptr);
  
  png_set_interlace_handling(png_ptr);
  png_read_update_info(png_ptr, info_ptr);
  if (setjmp(png_jmpbuf(png_ptr)))
    {
      fprintf(stderr," Error during read_image");
    }
  if((row_pointers = (unsigned char **) malloc(sizeof(unsigned char *) * height))==NULL)
    {
	fprintf(stderr, "Out of memory allocating rows index for png\n");
	png_destroy_info_struct(png_ptr, &info_ptr);
	//png_destroy_struct(png_ptr);
	return NULL;
    }
  for (y=0; y<height; y++)
    if((row_pointers[y] = (unsigned char *) malloc(  png_get_rowbytes(png_ptr, info_ptr) ))==NULL)
      {
	    fprintf(stderr, "Out of memory allocating rows for png\n");
	    while(y>1)
	  {	   
	    free(row_pointers[--y]);
	  }
	free(row_pointers);
	png_destroy_info_struct(png_ptr, &info_ptr);
	//png_destroy_struct(png_ptr);
	return NULL;
      }
  png_read_image(png_ptr, row_pointers);
  fclose(in);
  if((img=(Image *)malloc(sizeof(Image)))==NULL)
    {
      fprintf(stderr, "Out of memory creating header while opening png\n");
      png_destroy_info_struct(png_ptr, &info_ptr);
      //png_destroy_struct(png_ptr);
      for (y=0; y<height; y++)
	free(row_pointers[y]);
      free(row_pointers);     
      return NULL;
    }
  memset(img, 0, sizeof(Image)); 

  if((img->data=(unsigned char *)malloc(width * height * 3))==NULL)
    {
      fprintf(stderr, "Out of memory for image while opening png\n");
      png_destroy_info_struct(png_ptr, &info_ptr);
      //png_destroy_struct(png_ptr);
      for (y=0; y<height; y++)
	free(row_pointers[y]);
      free(row_pointers);     
      free(img);
      return NULL;      
    }
  if( png_get_color_type(png_ptr, info_ptr)  == PNG_COLOR_TYPE_RGB)
    {
      
      for (y=0;y<height;y++)
	{	  
	  memcpy(&img->data[y*width*3], row_pointers[y], width*3);
	}
    }else if ( png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGBA)
    {
      data=img->data;
      for (y=0;y<height;y++)
	{
	  row=row_pointers[y];
	  for(x=0;x<width;x++)
	    {
	      *(data++)=*(row++);
	      *(data++)=*(row++);
	      *(data++)=*(row++);
	      row++;
	    }
	}
    }else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY)
    {
      data=img->data;
      for (y=0;y<height;y++)
	{
	  row=row_pointers[y];
	  for(x=0;x<width;x++)
	    {
	      *(data++)=*row;
	      *(data++)=*row;
	      *(data++)=*(row++);
	    }
	}
    }else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA)
    {
      data=img->data;
      for (y=0;y<height;y++)
	{
	  row=row_pointers[y];
	  for(x=0;x<width;x++)
	    {
	      *(data++)=*row;
	      *(data++)=*row;
	      *(data++)=*(row++);
	      row++;
	    }
	}
    }else
    {
      fprintf(stderr, "Unsupported PNG format, we do not support indexed color (yet)\n");
      png_destroy_info_struct(png_ptr, &info_ptr);
      //png_destroy_struct(png_ptr);
      for (y=0; y<height; y++)
	free(row_pointers[y]);
      free(row_pointers);     
      free(img->data);
      free(img);
      return NULL;
    }
  img->width=width;
  img->height=height;
  png_destroy_info_struct(png_ptr, &info_ptr);
  //png_destroy_struct(png_ptr);
  for (y=0; y<height; y++)
    free(row_pointers[y]);
  free(row_pointers);     
  img->fn=strdup(fn);
  return img;
}

Now we are at the point that make and sudo make install works without any error.

IMPORTANT

We need XQuartz  works fromOS X 10.6.3 till  El Capitan  , Download and install this part output the images to the window and will get started from the terminal as soon Showoutput get executed.

Run in Terminal

stills2dv -tmpdir tmp -showoutput workfil_pano.s2d

Terminal returns and start prozessing your workfile and place all images in the tmp folder. My  workfil_pano is a simple pan from left to right

resolution 1200×830

fps 25

type jpg

img Kaiserpano.jpg zoom FITHEIGHT startpoint LEFT endpoint RIGHT duration 29.00Creating framCreating fCreaCreating frame #00024 at x= 244.22 y= 165.00 and zoom 4.06

After all Zoom Pan prozessed the tmp is full of single images now combine them with ffmpeg to get the final movie

ffmpeg -r 25.00 -f image2 -i tmp/%05d.jpg -i myaudiofile.mp3 -target pal-dvd -s 1920x1080 -vb 9000k outvid.mpg

I hope i dont forget anything , its already some days ago

Leave a Reply

avatar
  Subscribe  
Notify of