Commits

zeroth  committed 19252bb

Added seeking, but discovered desync issue. Working on solving it...

  • Participants
  • Parent commits 91ba9c5
  • Branches tylerthemovie

Comments (0)

Files changed (5)

File movie_test.py

 
 print "Please give an (absolute)filename of a movie file you'd like to play: ",
 #filename = raw_input()
-filename="/home/tyler/War3.avi"
+filename="/home/tyler/dhs1.avi"
 #initialization. It could also have a surface as a second argument, and every 
 # frame will be blitted to that surface. It is the programmer's responsibility
 # to be on time for rendering that surface.
                 # the features.
 time.sleep(2)  #sleep for ten seconds to let one see the video play, and hear 
                 # the audio
-print "Paused:",m.paused
-print "Playing:",m.playing
-print "Movie:",m
-print "Y Top:",m.ytop
-print "X Left:",m.xleft
-time.sleep(2)
+##print "Paused:",m.paused
+##print "Playing:",m.playing
+##print "Movie:",m
+##print "Y Top:",m.ytop
+##print "X Left:",m.xleft
+time.sleep(30)
+print "Testing seek..."
+m.easy_seek(second=10, minute=5, reverse=0)
+time.sleep(5)
+
 print "Altering xleft and ytop..."
 m.xleft += 10
 m.ytop  +=10

File src/_gmovie.c

             actual_delay = 0.010;
         }
         GRABGIL
-        movie->timing = (actual_delay*1000.0)+0.5;
+        PySys_WriteStdout("Actual Delay: %f\ndelay: %f\ndiff: %f\n", actual_delay, delay, diff);
+        movie->timing = (actual_delay*1000.0)+1;
         RELEASEGIL
     }
     GRABGIL
 /* seek in the stream */
 void stream_seek(PyMovie *movie, int64_t pos, int rel)
 {
-    DECLAREGIL
-    GRABGIL
-    Py_INCREF( movie);
-    RELEASEGIL
+    //DECLAREGIL
+    //GRABGIL
+    //Py_INCREF( movie);
+    //RELEASEGIL
     if (!movie->seek_req)
     {
         movie->seek_pos = pos;
 
         movie->seek_req = 1;
     }
-    GRABGIL
-    Py_DECREF( movie);
-    RELEASEGIL
+    //GRABGIL
+    //Py_DECREF( movie);
+    //RELEASEGIL
 }
 
 /* pause or resume the video */
             int64_t seek_target= movie->seek_pos;
 			int aud_stream_index=-1;
 			int vid_stream_index=-1;
-			int64_t vid_seek_target=0;
-			int64_t aud_seek_target=0;
-            if (movie->video_stream >= 0)
+			int64_t vid_seek_target=seek_target;
+			int64_t aud_seek_target=seek_target;
+            if (movie->video_stream >= 0){
                 vid_stream_index= movie->video_stream;
-
-			if (movie->audio_stream >=0)
+            }
+			else if (movie->audio_stream >=0){
 				aud_stream_index = movie->audio_stream;
-
+			}
             if(vid_stream_index>=0)
                 vid_seek_target= av_rescale_q(seek_target, AV_TIME_BASE_Q, ic->streams[vid_stream_index]->time_base);
 
             if(aud_stream_index>=0)
 				aud_seek_target= av_rescale_q(seek_target, AV_TIME_BASE_Q, ic->streams[vid_stream_index]->time_base);
-
+			
 			if(vid_stream_index>=0)
 			{
             	ret = av_seek_frame(movie->ic, vid_stream_index, vid_seek_target, movie->seek_flags|AVSEEK_FLAG_ANY);
 	            {
 	                PyErr_Format(PyExc_IOError, "%s: error while seeking", movie->ic->filename);
 	            }
-	            else
-	            {
-	                if (movie->video_stream >= 0)
-	                {
-	                    packet_queue_flush(&movie->videoq);
-	                    packet_queue_put(&movie->videoq, &flush_pkt);
-	                }
-	            }
 			}
-			if(aud_stream_index>=0)
+			else if(aud_stream_index>=0)
 			{
 				ret = av_seek_frame(movie->ic, aud_stream_index, aud_seek_target, movie->seek_flags|AVSEEK_FLAG_ANY);
 	            if (ret < 0)
 	            {
 	                PyErr_Format(PyExc_IOError, "%s: error while seeking", movie->ic->filename);
 	            }
-	            else
-	            {
-	                if (movie->audio_stream >= 0)
-	                {
-	                    packet_queue_flush(&movie->audioq);
-	                    packet_queue_put(&movie->audioq, &flush_pkt);
-	                }
-	            }
 			}
-
+			if (movie->video_stream >= 0)
+            {
+                packet_queue_flush(&movie->videoq);
+                packet_queue_put(&movie->videoq, &flush_pkt);
+            }
+            if (movie->audio_stream >= 0)
+            {
+                packet_queue_flush(&movie->audioq);
+                packet_queue_put(&movie->audioq, &flush_pkt);
+            }
+     
             movie->seek_req = 0;
         }
         /* if the queue are full, no need to read more */

File src/_gmovie.h

 #define BPP 1
 
 //enables profiling info to be gathered
-#define PROFILE 1
+//#define PROFILE 1
 
 #ifdef PROFILE
 #include <math.h>

File src/gmovie.c

 
 }
 
-PyObject* _movie_seek (PyMovie *movie, PyObject* args)
+PyObject* _movie_easy_seek (PyMovie *movie, PyObject* args, PyObject *kwds)
 {
-	int64_t pos;
-	return (PyObject *) movie;
+	int64_t pos=0;
+	int hour=0;
+	int minute=0;
+	int second=0;
+	int reverse=0;
+	char *keywords[4] = {"second", "minute", "hour", "reverse"};
+	if(!PyArg_ParseTupleAndKeywords(args, kwds, "|iiii", keywords, &second, &minute, &hour, &reverse))
+	{
+		Py_RETURN_NONE;
+	}
+	if(second)
+	{
+		pos+=(int64_t)second;
+	}
+	if(minute)
+	{
+		pos+=60*(int64_t)minute;
+	}
+	if(hour)
+	{
+		pos+=3600*(int64_t)hour;
+	}
+	if(reverse)
+	{
+		reverse=-1;
+	}
+	else
+	{
+		reverse=1;
+	}
+	pos *= AV_TIME_BASE;
+	stream_seek(movie, pos, reverse);
+	Py_RETURN_NONE;
 }
+
 PyObject* _movie_get_paused (PyMovie *movie, void *closure)
 {
     return PyBool_FromLong((long)movie->paused);
 }
 
 static PyMethodDef _movie_methods[] = {
-                                          { "play",   (PyCFunction) _movie_play,   METH_VARARGS, DOC_GMOVIEMOVIEPLAY},
-                                          { "stop",   (PyCFunction) _movie_stop,   METH_NOARGS,  DOC_GMOVIEMOVIESTOP},
-                                          { "pause",  (PyCFunction) _movie_pause,  METH_NOARGS,  DOC_GMOVIEMOVIEPAUSE},
-                                          { "rewind", (PyCFunction) _movie_rewind, METH_VARARGS, DOC_GMOVIEMOVIEREWIND},
-                                          { "resize", (PyCFunction) _movie_resize, METH_VARARGS, DOC_GMOVIEMOVIERESIZE},
+                                          { "play",      (PyCFunction) _movie_play,      METH_VARARGS,               DOC_GMOVIEMOVIEPLAY},
+                                          { "stop",      (PyCFunction) _movie_stop,      METH_NOARGS,                DOC_GMOVIEMOVIESTOP},
+                                          { "pause",     (PyCFunction) _movie_pause,     METH_NOARGS,                DOC_GMOVIEMOVIEPAUSE},
+                                          { "rewind",    (PyCFunction) _movie_rewind,    METH_VARARGS,               DOC_GMOVIEMOVIEREWIND},
+                                          { "resize",    (PyCFunction) _movie_resize,    METH_VARARGS,               DOC_GMOVIEMOVIERESIZE},
+                                          { "easy_seek", (PyCFunction) _movie_easy_seek, METH_VARARGS|METH_KEYWORDS, NULL},
                                           { NULL,     NULL,                        0,            NULL }
                                       };
 

File src/gmovie.h

 PyObject* _movie_rewind       (PyMovie *movie, PyObject* args);
 PyObject* _movie_resize       (PyMovie *movie, PyObject* args);
 PyObject* _movie_seek         (PyMovie *movie, PyObject* args);
+PyObject* _movie_easy_seek    (PyMovie *movie, PyObject* args, PyObject *kwds);
 
 /* Getters/setters */
 PyObject* _movie_get_paused  (PyMovie *movie, void *closure);