[MPlayer-users] How to pause mencoder
Geoffrey Espin
espin at idiom.com
Tue Dec 23 23:17:55 CET 2003
> Actually not. You can't pause mencoder.
Here's a patch that adds a bunch of hacks with the _potential_ of
including pause (just add into mencoder.c look for "check keyboard
input"). Pause would be great if recording of live-TV and want to
skip adverts by hand. Adding a 'q' command was vital for restarting
mencoder quickly, the kill took a long time from Perl.
* mencoder checks input: q-quit, i<n> switch video input (0-3)
* hacked libavcodec/i386/cputest.c to identify correctly as Nehemiah (693).
* added sub.txt support (real-time subtitles for use with mencoder)
* get_time_pos: prints "ANS_TIME=" the number of seconds in the current file
* get_url: prints "ANS_URL=" the url of the current file
You could use lsdiff/filterdiff to extact just patches of interest.
MPlayer-1.0pre3/
Makefile
debian/changelog
debian/control
debian/rules
find_sub.c
input/input.c
input/input.h
libavcodec/i386/cputest.c
libmpdemux/demux_avi.c
libmpdemux/demuxer.c
libmpdemux/demuxer.h
libmpdemux/tvi_v4l.c
mencoder.c <<--- filterdiff -i "*mencoder.c" MPlayer-1.0pre3.patch
mplayer.c
subreader.c
subreader.h
Geoff
--
Geoffrey Espin
espin at idiom.com
-------------- next part --------------
diff -Naur MPlayer-1.0pre3.ORIG/Makefile MPlayer-1.0pre3/Makefile
--- MPlayer-1.0pre3.ORIG/Makefile 2003-12-08 13:33:31.000000000 -0800
+++ MPlayer-1.0pre3/Makefile 2003-12-09 13:41:15.000000000 -0800
@@ -289,6 +289,7 @@
endif
@if test ! -d $(CONFDIR) ; then mkdir -p $(CONFDIR) ; fi
@if test -f $(CONFDIR)/codecs.conf ; then mv -f $(CONFDIR)/codecs.conf $(CONFDIR)/codecs.conf.old ; fi
+ cp etc/codecs.conf etc/input.conf etc/menu.conf $(CONFDIR)
ifeq ($(DVDKIT_SHARED),yes)
ifeq ($(DVDKIT2),yes)
if test ! -d $(LIBDIR) ; then mkdir -p $(LIBDIR) ; fi
diff -Naur MPlayer-1.0pre3.ORIG/debian/changelog MPlayer-1.0pre3/debian/changelog
--- MPlayer-1.0pre3.ORIG/debian/changelog 2003-02-15 07:07:09.000000000 -0800
+++ MPlayer-1.0pre3/debian/changelog 2003-12-09 15:08:30.000000000 -0800
@@ -1,3 +1,45 @@
+mplayer (1.0pre3-gk-1) unstable; urgency=low
+
+ * re-patched pre3.
+
+ -- Geoffrey Espin <espin at idiom.com> Tue, 9 Dec 2003 15:07:38 -0800
+
+mplayer (1.0pre2-gk-7) unstable; urgency=low
+
+ * mencoder checks input: q-quit, i<n> switch video input (0-3)
+
+ -- Geoffrey Espin <espin at idiom.com> Sat, 22 Nov 2003 14:24:38 -0800
+
+mplayer (1.0pre2-gk-6) unstable; urgency=low
+
+ * hacked libavcodec/i386/cputest.c to identify correctly as Nehemiah (693).
+ * (really just fixed/synched up gk-#'s and doc.)
+
+ -- Geoffrey Espin <espin at idiom.com> Tue, 21 Oct 2003 17:58:41 -0700
+
+mplayer (1.0pre2-gk-2) unstable; urgency=low
+
+ * fixed SIGBUS in mmaptxt subtitles
+
+ -- Geoffrey Espin <espin at idiom.com> Sun, 12 Oct 2003 06:48:20 -0700
+
+mplayer (1.0pre2-gk-1) unstable; urgency=low
+
+ * updated to 1.0pre2
+ * added sub.txt support
+
+ -- Geoffrey Espin <espin at idiom.com> Sat, 11 Oct 2003 13:05:58 -0700
+
+mplayer (0.91-gk-3) unstable; urgency=low
+
+ * gatekeeper-ized
+ * NBK (Noel Burton-Krahn <noel at burton-krahn.com>) Jun 11, 2003:
+ * added two new commands:
+ * get_time_pos: prints "ANS_TIME=" the number of seconds in the current file
+ * get_url: prints "ANS_URL=" the url of the current file
+
+ -- Geoffrey Espin <espin at idiom.com> Tue, 7 Oct 2003 16:51:31 -0700
+
mplayer (0.90cvs) unstable; urgency=low
* this is a placeholder message
diff -Naur MPlayer-1.0pre3.ORIG/debian/control MPlayer-1.0pre3/debian/control
--- MPlayer-1.0pre3.ORIG/debian/control 2002-12-07 13:36:25.000000000 -0800
+++ MPlayer-1.0pre3/debian/control 2003-12-09 13:41:15.000000000 -0800
@@ -1,7 +1,7 @@
Source: mplayer
Section: misc
Priority: optional
-Maintainer: Dariush Pietrzak <eyck at ghost.anime.pl>
+Maintainer: Geoffrey Espin <espin at idiom.com>
Standards-Version: 3.2.1
Build-Depends: libglib-dev, libgtk-dev, xlibs-dev, libpng-dev, zlib1g-dev, debhelper (>= 2)
diff -Naur MPlayer-1.0pre3.ORIG/debian/rules MPlayer-1.0pre3/debian/rules
--- MPlayer-1.0pre3.ORIG/debian/rules 2003-11-07 01:57:06.000000000 -0800
+++ MPlayer-1.0pre3/debian/rules 2003-12-09 13:41:15.000000000 -0800
@@ -16,7 +16,9 @@
dh_testdir
# Add here commands to configure the package.
$(checkdir)
- ./configure --prefix=/usr --confdir=/etc/mplayer --enable-runtime-cpudetection --enable-gui $(DEB_BUILD_OPTIONS)
+ ./configure --prefix=/usr --confdir=/etc/mplayer --enable-gui --enable-tv-v4l --enable-win32 $(DEB_BUILD_OPTIONS)
+# --enable-runtime-cpudetection
+
touch configure-stamp
diff -Naur MPlayer-1.0pre3.ORIG/find_sub.c MPlayer-1.0pre3/find_sub.c
--- MPlayer-1.0pre3.ORIG/find_sub.c 2003-04-24 01:20:10.000000000 -0700
+++ MPlayer-1.0pre3/find_sub.c 2003-12-09 13:41:15.000000000 -0800
@@ -50,6 +50,22 @@
sub_delay = subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps) - pts;
}
+// NBK ESPIN - catch occasional SIGBUS in mmap'd file
+#include <signal.h>
+#include <setjmp.h>
+
+static sigjmp_buf jmpbuf;
+static volatile sig_atomic_t canjump = 0;
+
+static void mmaptxt_handler (int sig){
+ if (!canjump) {
+ signal (sig, SIG_DFL);
+ raise (sig);
+ }
+ canjump = 0;
+ siglongjmp (jmpbuf, 1);
+}
+
void find_sub(sub_data* subd,int key){
subtitle *subs;
int i,j;
@@ -57,6 +73,44 @@
if ( !subd || subd->sub_num == 0) return;
subs = subd->subtitles;
+ if( subd->format == SUB_MMAPTXT ) { // NBK - dynamic mmap'ed subtitles
+ int ch;
+ int k;
+ static __sighandler_t oldsig;
+
+ oldsig = signal (SIGBUS, mmaptxt_handler);
+ if (sigsetjmp (jmpbuf, 1)) {
+ signal (SIGBUS, oldsig);
+ return;
+ }
+ canjump = 1;
+
+ i = 0; // position in mmap
+ j = 0; // line #
+ k = 0; // position within particular line
+
+ vo_sub = subs;
+ while (isprint (ch = vo_sub->text[SUB_MAX_TEXT-1][i++]) || ch == '\n') {
+ if (ch == '\n') {
+ ch = 0;
+ vo_sub->text[j][k++] = ch; // null eol
+ k = 0;
+ if (++j >= (SUB_MAX_TEXT-1)-1)
+ break;
+ }
+ else
+ vo_sub->text[j][k++] = ch;
+ }
+ if (k > 0) {
+ vo_sub->text[j][k] = 0;
+ j++;
+ }
+ vo_sub->lines = j;
+ vo_osd_changed(OSDTYPE_SUBTITLE);
+ signal (SIGBUS, oldsig);
+ return;
+ }
+
if(vo_sub){
if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
} else {
diff -Naur MPlayer-1.0pre3.ORIG/input/input.c MPlayer-1.0pre3/input/input.c
--- MPlayer-1.0pre3.ORIG/input/input.c 2003-11-30 08:36:07.000000000 -0800
+++ MPlayer-1.0pre3/input/input.c 2003-12-09 13:41:15.000000000 -0800
@@ -104,6 +104,8 @@
{ MP_CMD_LOADFILE, "loadfile", 1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },
{ MP_CMD_LOADLIST, "loadlist", 1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },
{ MP_CMD_VF_CHANGE_RECTANGLE, "change_rectangle", 2, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}}}},
+ { MP_CMD_GET_TIME_POS, "get_time_pos", 0, { {-1,{0}} } },
+ { MP_CMD_GET_URL, "get_url", 0, { {-1,{0}} } },
#ifdef HAVE_NEW_GUI
{ MP_CMD_GUI_LOADFILE, "gui_loadfile", 0, { {-1,{0}} } },
diff -Naur MPlayer-1.0pre3.ORIG/input/input.h MPlayer-1.0pre3/input/input.h
--- MPlayer-1.0pre3.ORIG/input/input.h 2003-11-30 08:36:07.000000000 -0800
+++ MPlayer-1.0pre3/input/input.h 2003-12-09 13:41:15.000000000 -0800
@@ -54,6 +54,10 @@
#define MP_CMD_SUB_FORCED_ONLY 50
#define MP_CMD_VO_ONTOP 51
+// NBK - Jun 11, 2003 - print the current url/time
+#define MP_CMD_GET_TIME_POS 101
+#define MP_CMD_GET_URL 102
+
#define MP_CMD_GUI_EVENTS 5000
#define MP_CMD_GUI_LOADFILE 5001
#define MP_CMD_GUI_LOADSUBTITLE 5002
diff -Naur MPlayer-1.0pre3.ORIG/libavcodec/i386/cputest.c MPlayer-1.0pre3/libavcodec/i386/cputest.c
--- MPlayer-1.0pre3.ORIG/libavcodec/i386/cputest.c 2003-12-09 01:36:19.000000000 -0800
+++ MPlayer-1.0pre3/libavcodec/i386/cputest.c 2003-12-09 13:41:15.000000000 -0800
@@ -85,6 +85,7 @@
if ((unsigned)eax < 0x80000001)
goto inteltest;
cpuid(0x80000001, eax, ebx, ecx, edx);
+ edx = 0x1380b035; /* *** XXX ESPIN: broken C3-2 CPUID 693 XXX *** */
rval = 0;
if( edx & ( 1 << 31) )
rval |= MM_3DNOW;
diff -Naur MPlayer-1.0pre3.ORIG/libmpdemux/demux_avi.c MPlayer-1.0pre3/libmpdemux/demux_avi.c
--- MPlayer-1.0pre3.ORIG/libmpdemux/demux_avi.c 2003-10-22 12:01:37.000000000 -0700
+++ MPlayer-1.0pre3/libmpdemux/demux_avi.c 2003-12-09 13:41:15.000000000 -0800
@@ -850,6 +850,12 @@
if (sh_video->video.dwLength<=1) return DEMUXER_CTRL_GUESS;
return DEMUXER_CTRL_OK;
+
+ // NBK - Jun 11, 2003 - print the current url/time
+ case DEMUXER_CTRL_GET_TIME_POS:
+ *((double*)arg)=(double)priv->video_pack_no/sh_video->fps;
+ return DEMUXER_CTRL_OK;
+
default:
return DEMUXER_CTRL_NOTIMPL;
}
diff -Naur MPlayer-1.0pre3.ORIG/libmpdemux/demuxer.c MPlayer-1.0pre3/libmpdemux/demuxer.c
--- MPlayer-1.0pre3.ORIG/libmpdemux/demuxer.c 2003-12-08 11:33:38.000000000 -0800
+++ MPlayer-1.0pre3/libmpdemux/demuxer.c 2003-12-09 13:41:15.000000000 -0800
@@ -1631,3 +1631,22 @@
return ans;
}
+// NBK - Jun 11, 2003 - print the current url/time
+double demuxer_get_time_pos(demuxer_t *demuxer){
+ double ans;
+
+ if (demux_control(demuxer, DEMUXER_CTRL_GET_TIME_POS, &ans)<=0) {
+ ans=0;
+ }
+ return ans;
+}
+
+// NBK - Jun 11, 2003 - print the current url/time
+char *demuxer_get_url(demuxer_t *demuxer){
+ char *ans;
+
+ if (demux_control(demuxer, DEMUXER_CTRL_GET_URL, &ans)<=0) {
+ ans = (demuxer && demuxer->stream) ? demuxer->stream->url : 0;
+ }
+ return ans;
+}
diff -Naur MPlayer-1.0pre3.ORIG/libmpdemux/demuxer.h MPlayer-1.0pre3/libmpdemux/demuxer.h
--- MPlayer-1.0pre3.ORIG/libmpdemux/demuxer.h 2003-12-08 11:33:38.000000000 -0800
+++ MPlayer-1.0pre3/libmpdemux/demuxer.h 2003-12-09 13:41:15.000000000 -0800
@@ -72,6 +72,10 @@
#define DEMUXER_CTRL_GET_TIME_LENGTH 10
#define DEMUXER_CTRL_GET_PERCENT_POS 11
+// NBK - Jun 11, 2003 - print the current url/time
+#define DEMUXER_CTRL_GET_TIME_POS 12
+#define DEMUXER_CTRL_GET_URL 13
+
// Holds one packet/frame/whatever
typedef struct demux_packet_st {
int len;
@@ -281,4 +285,8 @@
extern unsigned long demuxer_get_time_length(demuxer_t *demuxer);
extern int demuxer_get_percent_pos(demuxer_t *demuxer);
+// NBK - Jun 11, 2003 - print the current url/time
+extern double demuxer_get_time_pos(demuxer_t *demuxer);
+extern char* demuxer_get_url(demuxer_t *demuxer);
+
extern int demuxer_type_by_filename(char* filename);
diff -Naur MPlayer-1.0pre3.ORIG/libmpdemux/tvi_v4l.c MPlayer-1.0pre3/libmpdemux/tvi_v4l.c
--- MPlayer-1.0pre3.ORIG/libmpdemux/tvi_v4l.c 2003-09-01 05:10:29.000000000 -0700
+++ MPlayer-1.0pre3/libmpdemux/tvi_v4l.c 2003-12-09 13:41:15.000000000 -0800
@@ -50,6 +50,8 @@
#include "audio_in.h"
+int global_input = 0; // XXX ESPIN
+
static tvi_info_t info = {
"Video 4 Linux input",
"v4l",
@@ -1614,6 +1616,15 @@
}
else
{
+ static int input = -1; // XXX ESPIN
+ if (input != global_input) {
+ fprintf (stderr, "I %d->%d\n", input, global_input);
+ input = global_input;
+ if ((input >= 0 || input <= 4) &&
+ ioctl(priv->video_fd, VIDIOCSCHAN, &priv->channels[input])) {
+ mp_msg(MSGT_TV, MSGL_ERR, "\nioctl set chan %d failed: %s\n", input, strerror(errno));
+ }
+ }
if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[frame]) == -1)
{
mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno));
diff -Naur MPlayer-1.0pre3.ORIG/mencoder.c MPlayer-1.0pre3/mencoder.c
--- MPlayer-1.0pre3.ORIG/mencoder.c 2003-12-08 13:33:31.000000000 -0800
+++ MPlayer-1.0pre3/mencoder.c 2003-12-09 13:41:15.000000000 -0800
@@ -1433,6 +1433,50 @@
mencoder_exit(1, NULL);
}
+ { // NBK - Nov 20, 2003 - check keyboard input
+ extern int tv_input (int); // libmpdemux/tv.c
+ extern int tv_param_input;
+ fd_set rfds;
+ struct timeval tv = {0, 0};
+ char buf [100];
+ char *p;
+ int n = -1;
+ int input = 0;
+
+ FD_ZERO(&rfds);
+ FD_SET(0, &rfds);
+
+ if (select(1, &rfds, 0, 0, &tv) > 0 && FD_ISSET(0, &rfds)) {
+ n = read (0, buf, sizeof(buf));
+ if ((p = index (buf, '\n')) > 0)
+ *p = '\0';
+
+ fprintf (stderr, "\n");
+ printf ("\n");
+
+ switch (buf[0]) {
+ case 'q':
+ case 'Q':
+ fprintf (stderr, "quit\n");
+ exit_sighandler(0); // sets at_eof
+ break;
+
+ case 'i':
+ case 'I':
+ {
+ extern int global_input; // ESPIN tv input select in libmpdemux/tvi_v4l.c
+ sscanf(&buf[1], "%d", &global_input);
+ break;
+ }
+
+ default:
+ fprintf (stderr, "unknown command <%s>\n", buf);
+ break;
+ }
+ }
+ }
+
+
} // while(!at_eof)
#ifdef HAVE_MP3LAME
diff -Naur MPlayer-1.0pre3.ORIG/mplayer.c MPlayer-1.0pre3/mplayer.c
--- MPlayer-1.0pre3.ORIG/mplayer.c 2003-12-08 13:33:31.000000000 -0800
+++ MPlayer-1.0pre3/mplayer.c 2003-12-09 13:41:15.000000000 -0800
@@ -3122,6 +3122,14 @@
mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer));
} break;
+ // NBK - Jun 11, 2003 - print the current url/time
+ case MP_CMD_GET_TIME_POS : {
+ mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_TIME=%lg\n", demuxer_get_time_pos(demuxer));
+ } break;
+ case MP_CMD_GET_URL : {
+ mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_URL=%s\n", demuxer_get_url(demuxer));
+ } break;
+
#ifdef USE_DVDNAV
case MP_CMD_DVDNAV_EVENT: {
dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
@@ -3371,6 +3379,44 @@
if(rel_seek_secs || abs_seek_pos){
current_module="seek";
+
+ // NBK - June 16, 2003 - rewind to end of previous file
+
+ // debug
+ //fprintf(stderr, "NBK: seek_prev abs_seek_pos=%d rel_seek_secs=%lg\n",
+ // abs_seek_pos, rel_seek_secs);
+
+
+ // NBK: seek to rel_seek_secs before end
+ if( abs_seek_pos == 4 ) {
+ unsigned long l;
+ demux_control(demuxer, DEMUXER_CTRL_GET_TIME_LENGTH, &l);
+ rel_seek_secs = l - rel_seek_secs;
+ if( rel_seek_secs < 0 ) rel_seek_secs = 0;
+ }
+
+ if( (abs_seek_pos == 0) && (rel_seek_secs < 0) && demuxer->seekable ) {
+ double tpos = 0;
+ int res;
+ res = demux_control(demuxer, DEMUXER_CTRL_GET_TIME_POS, &tpos);
+
+ // debug
+ //fprintf(stderr, "NBK: seek_prev rel_seek_secs=%lg res=%d tpos=%g\n",
+ // (double)rel_seek_secs, res, tpos);
+
+ if( (res > 0) && (tpos < -((double)rel_seek_secs)) && (tpos<2) ) {
+ abs_seek_pos=4;
+ rel_seek_secs=-rel_seek_secs;
+ eof = PT_PREV_ENTRY;
+ play_tree_step = -1;
+
+ // debug
+ //fprintf(stderr, "NBK: seek_prev pt_prev\n", i);
+
+ goto goto_next_file;
+ }
+ }
+
if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
// success:
/* FIXME there should be real seeking for vobsub */
diff -Naur MPlayer-1.0pre3.ORIG/subreader.c MPlayer-1.0pre3/subreader.c
--- MPlayer-1.0pre3.ORIG/subreader.c 2003-11-18 17:41:27.000000000 -0800
+++ MPlayer-1.0pre3/subreader.c 2003-12-09 13:41:15.000000000 -0800
@@ -12,6 +12,7 @@
#include <string.h>
#include <ctype.h>
+#include <sys/mman.h> // NBK - sub mmaptxt
#include <sys/types.h>
#include <dirent.h>
@@ -1200,6 +1201,45 @@
fd=fopen (filename, "r"); if (!fd) return NULL;
sub_format=sub_autodetect (fd, &uses_time);
+
+ do { // NBK - mmap dynamic subtitle text; filename ends with ".txt"
+ char *p;
+ if( !fd || sub_format != SUB_INVALID ) break;
+ p = strrchr(filename, '.');
+ if( !p || strcasecmp(p, ".txt") ) break;
+ first = (subtitle*)calloc(sizeof(*first), 1);
+ if(!first)
+ return NULL;
+ p = calloc((SUB_MAX_TEXT-1), (80 * 2)); // 2x for overlong line
+ if(!p) {
+ free (first);
+ return NULL;
+ }
+ first->lines = 0;
+ for (i = 0; i < (SUB_MAX_TEXT-1)-1; i++)
+ first->text[i] = p + i * (80 * 2);
+
+ if ((int)(first->text[SUB_MAX_TEXT-1] = mmap(0, getpagesize(), PROT_READ, MAP_SHARED, fileno(fd), 0)) == -1) {
+ free (first);
+ free (p);
+ fprintf (stderr, "mmap of <%s> failed!\n", filename);
+ return NULL;
+ }
+
+ fclose(fd);
+ return_sub = first;
+
+ subt_data = (sub_data *)malloc(sizeof(sub_data));
+ subt_data->filename = filename;
+ subt_data->format = SUB_MMAPTXT;
+ subt_data->sub_uses_time = uses_time;
+ //subt_data->sub_num = sub_num;
+ subt_data->sub_num = 1;
+ subt_data->sub_errs = sub_errs;
+ subt_data->subtitles = return_sub;
+ return subt_data;
+ } while(0);
+
mpsub_multiplier = (uses_time ? 100.0 : 1.0);
if (sub_format==SUB_INVALID) {mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n");return NULL;}
srp=sr+sub_format;
diff -Naur MPlayer-1.0pre3.ORIG/subreader.h MPlayer-1.0pre3/subreader.h
--- MPlayer-1.0pre3.ORIG/subreader.h 2003-09-21 06:20:00.000000000 -0700
+++ MPlayer-1.0pre3/subreader.h 2003-12-09 13:41:15.000000000 -0800
@@ -20,6 +20,7 @@
#define SUB_SUBVIEWER2 10
#define SUB_SUBRIP09 11
#define SUB_JACOSUB 12
+#define SUB_MMAPTXT 13 // NBK - dynamic subtitle must end with .txt
// One of the SUB_* constant above
extern int sub_format;
@@ -32,7 +33,6 @@
#define SUB_ALIGNMENT_HRIGHT 2
typedef struct {
-
int lines;
unsigned long start;
@@ -44,6 +44,7 @@
typedef struct {
subtitle *subtitles;
+ int format; // NBK - allow dynamic mmap'ed subtitles
char *filename;
int sub_uses_time;
int sub_num; // number of subtitle structs
More information about the MPlayer-users
mailing list