changeset 31957:49848f9a8f30

Add -edl-start-pts option to Adjust positions in EDL records according to file's start time. Patch by Vlad Seryakov, vseryakov at gmail.
author reynaldo
date Fri, 03 Sep 2010 23:49:35 +0000
parents a6c25d94e60e
children 4cccb69779ef
files DOCS/man/en/mplayer.1 cfg-mplayer.h command.c edl.h mplayer.c
diffstat 5 files changed, 34 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Fri Sep 03 18:50:03 2010 +0000
+++ b/DOCS/man/en/mplayer.1	Fri Sep 03 23:49:35 2010 +0000
@@ -890,6 +890,22 @@
 (default: 2 seconds).
 .
 .TP
+.B \-edl-start-pts
+Adjust positions in EDL records according to file's start time.
+Some formats, especially MPEG TS usually start with non-zero PTS
+values and when producing EDL file with \-edlout option, EDL records
+contain absolute values that are correct only to this particular file.
+If re-encoded into different format, this EDL file no longer applies.
+Specifying \-edl-start-pts will automatically adjust EDL positions according
+to start time: when producing EDL file, it will substract start time from every
+EDL record, when playing with EDL file, it will add file's start time to every
+EDL position.
+.
+.TP
+.B \-noedl-start-pts
+Disable adjusting EDL positions.
+.
+.TP
 .B \-enqueue (GUI only)
 Enqueue files given on the command line in the playlist instead of playing them
 immediately.
--- a/cfg-mplayer.h	Fri Sep 03 18:50:03 2010 +0000
+++ b/cfg-mplayer.h	Fri Sep 03 23:49:35 2010 +0000
@@ -103,6 +103,8 @@
      CONF_TYPE_PRINT, 0, 0, 0, NULL},
     {"edlout", &edl_output_filename,  CONF_TYPE_STRING, 0, 0, 0, NULL},
     {"edl-backward-delay", &edl_backward_delay,  CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
+    {"edl-start-pts", &edl_start_pts,  CONF_TYPE_FLAG, 0, 0, 1, NULL},
+    {"noedl-start-pts", &edl_start_pts,  CONF_TYPE_FLAG, 0, 1, 0, NULL},
 
 #ifdef CONFIG_X11
     {"display", &mDisplayName, CONF_TYPE_STRING, 0, 0, 0, NULL},
--- a/command.c	Fri Sep 03 18:50:03 2010 +0000
+++ b/command.c	Fri Sep 03 23:49:35 2010 +0000
@@ -66,6 +66,7 @@
 #include "mp_core.h"
 #include "mp_fifo.h"
 #include "libavutil/avstring.h"
+#include "edl.h"
 
 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
 
@@ -2614,7 +2615,8 @@
                     if (mpctx->begin_skip > v)
                         mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
                     else {
-                        fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
+                        double pts = edl_start_pts ? start_pts : 0;
+                        fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip - pts, v - pts, 0);
                         mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
                     }
                     mpctx->begin_skip = MP_NOPTS_VALUE;
--- a/edl.h	Fri Sep 03 18:50:03 2010 +0000
+++ b/edl.h	Fri Sep 03 23:49:35 2010 +0000
@@ -40,6 +40,7 @@
 
 extern char *edl_filename; // file to extract EDL entries from (-edl)
 extern char *edl_output_filename; // file to put EDL entries in (-edlout)
+extern int edl_start_pts; // Start pts to be added/subtracted to EDL pos
 
 void free_edl(edl_record_ptr next_edl_record); // free's entire EDL list.
 edl_record_ptr edl_parse_file(void); // fills EDL stack
--- a/mplayer.c	Fri Sep 03 18:50:03 2010 +0000
+++ b/mplayer.c	Fri Sep 03 23:49:35 2010 +0000
@@ -142,7 +142,7 @@
 int quiet=0;
 int enable_mouse_movements=0;
 float start_volume = -1;
-
+double start_pts = MP_NOPTS_VALUE;
 char *heartbeat_cmd;
 
 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
@@ -339,6 +339,7 @@
 // (next seek, pause,...), otherwise after the seek it will
 // enter the same scene again and skip forward immediately
 float edl_backward_delay = 2;
+int edl_start_pts = 0; ///< Automatically add/sub this from EDL start/stop pos
 int use_filedir_conf;
 int use_filename_title;
 
@@ -555,7 +556,6 @@
 
 static void print_file_properties(const MPContext *mpctx, const char *filename)
 {
-  double start_pts = MP_NOPTS_VALUE;
   double video_start_pts = MP_NOPTS_VALUE;
   mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n",
 	  filename_recode(filename));
@@ -3640,6 +3640,16 @@
 
   print_file_properties(mpctx, filename);
 
+  // Adjust EDL positions with start_pts
+  if (edl_start_pts && start_pts) {
+      edl_record_ptr edl = edl_records;
+      while (edl) {
+          edl->start_sec += start_pts;
+          edl->stop_sec += start_pts;
+          edl = edl->next;
+      }
+  }
+
 if(!mpctx->sh_video) goto main; // audio-only
 
 if(!reinit_video_chain()) {