added missing include.
[swftools.git] / avi2swf / avi2swf.cc
index c530cbb..e980747 100644 (file)
 
 #include "../config.h"
 
-#ifdef HAVE_SIGNAL_H
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#include <signal.h>
-#define DO_SIGNALS
-#endif
-#endif
-
-extern "C" {
 #include "../lib/args.h"
-}
 #include "v2swf.h"
+#ifdef WIN32
+#include "videoreader_vfw.hh"
+#else
 #include "videoreader_avifile.hh"
+#endif
 
 static char * filename = 0;
 static char * outputfilename = "output.swf";
@@ -156,8 +150,8 @@ void args_callback_usage(char *name)
     printf("-o , --output filename         Specify output filename\n");
     printf("-A , --adjust seconds          Audio adjust: Shift sound -seconds to the future or +seconds into the past.\n");
     printf("-n , --num frames              Number of frames to encode\n");
-    printf("-m , --mp3-bitrate <rate> (kbps)    Set the mp3 bitrate to encode audio with\n");
-    printf("-r , --mp3-samplerate <rate> (Hz)    Set the mp3 samplerate to encode audio with (default: 11025)\n");
+    printf("-m , --mp3-bitrate <kbps>      Set the mp3 bitrate to encode audio with\n");
+    printf("-r , --mp3-samplerate <hz>     Set the mp3 samplerate to encode audio with (default: 11025)\n");
     printf("-d , --scale <val>             Scale down to factor <val>. (in %, e.g. 100 = original size)\n");
     printf("-p , --flip                    Turn movie upside down\n");
     printf("-q , --quality <val>           Set the quality to <val>. (0-100, 0=worst, 100=best, default:80)\n");
@@ -188,9 +182,6 @@ static char*itoa(int a)
     return toabuf;
 }
 
-static int shutdown_avi2swf = 0;
-static int frameno = 0;
-
 #ifdef DO_SIGNALS
 pthread_t main_thread;
 static void sigterm(int sig)
@@ -223,8 +214,10 @@ int main (int argc,char ** argv)
 #endif
 
     processargs(argc, argv);
-    if(!filename)
+    if(!filename) {
+       fprintf(stderr, "You must supply a filename");
        exit(0);
+    }
     if(keyframe_interval<0) {
        if(flashversion>=6)
            keyframe_interval=200;
@@ -238,18 +231,22 @@ int main (int argc,char ** argv)
        fprintf(stderr, "Couldn't open %s\n", outputfilename);
        exit(1);
     }
-
+    
+#ifdef WIN32
+    ret = videoreader_vfw_open(&video, filename);
+#else
     ret = videoreader_avifile_open(&video, filename);
+#endif
 
-    if(!ret) {
-       printf("Error opening %s\n", filename);
+    if(ret<0) {
+       fprintf(stderr, "Error opening %s\n", filename);
        exit(1);
     }
 
     if(verbose) {
        printf("| video framerate: %f\n", video.fps);
        printf("| video size: %dx%d\n", video.width, video.height);
-       printf("| audio rate: %d\n", video.rate);
+       printf("| audio rate: %d\n", video.samplerate);
        printf("| audio channels: %d\n", video.channels);
     }
 
@@ -269,12 +266,16 @@ int main (int argc,char ** argv)
     v2swf_setparameter(&v2swf, "keyframe_interval", itoa(keyframe_interval));
     if(expensive)
        v2swf_setparameter(&v2swf, "motioncompensation", "1");
+    if(flip)
+       video.setparameter(&video, "flip", "1");
+    if(verbose)
+       video.setparameter(&video, "verbose", "1");
 
     if(!verbose)
        printf("\n");
 
     if(audio_adjust>0) {
-       int num = ((int)(audio_adjust*video.rate))*video.channels*2;
+       int num = ((int)(audio_adjust*video.samplerate))*video.channels*2;
        void*buf = malloc(num);
        video.getsamples(&video, buf, num);
        free(buf);
@@ -293,9 +294,9 @@ int main (int argc,char ** argv)
        void*buf = malloc(video.width*video.height*4);
        for(t=0;t<skip;t++) {
            video.getimage(&video, buf);
-           video.getsamples(&video, buf, (int)((video.rate/video.fps)*video.channels*2));
+           video.getsamples(&video, buf, (int)((video.samplerate/video.fps)*video.channels*2));
            if(!verbose) {
-               printf("\rSkipping frame %d", frameno);fflush(stdout);
+               printf("\rSkipping frame %d", video.frame);fflush(stdout);
            }
        }
        free(buf);
@@ -308,7 +309,7 @@ int main (int argc,char ** argv)
        if(!l)
            break;
        if(!verbose) {
-           printf("\rConverting frame %d", frameno);fflush(stdout);
+           printf("\rConverting frame %d", video.frame);fflush(stdout);
        }
     }
     if(!verbose)