changeset 36042:134919b73b04

Add limited -endpos support when dumping. In theory this should even make -endpos with a time work with -dumpstream of DVDs but I could not test it - testers very welcome!
author reimar
date Wed, 03 Apr 2013 11:52:42 +0000
parents 5f730ed5b3d2
children 40c13df3d953
files Changelog DOCS/man/en/mplayer.1 mplayer.c
diffstat 3 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Changelog	Wed Apr 03 09:40:30 2013 +0000
+++ b/Changelog	Wed Apr 03 11:52:42 2013 +0000
@@ -14,6 +14,7 @@
     * Fixes for DVB, teletext and closed-caption based subtitles.
     * Support teletext and CC subtitles in WTV.
     * Support binding keys corresponding to non-ASCII characters.
+    * Limited -endpos support for -dump*
 
     Ports:
     * Windows: support file names as UTF-8 in slave mode and passing
--- a/DOCS/man/en/mplayer.1	Wed Apr 03 09:40:30 2013 +0000
+++ b/DOCS/man/en/mplayer.1	Wed Apr 03 11:52:42 2013 +0000
@@ -1674,6 +1674,7 @@
 Byte position may not be accurate, as it can only stop at a frame boundary.
 When used in conjunction with \-ss option, \-endpos time will shift forward by
 seconds specified with \-ss if not a byte position.
+In addition it may not work well or not at all when used with any of the \-dump options.
 .sp 1
 .I EXAMPLE:
 .PD 0
--- a/mplayer.c	Wed Apr 03 09:40:30 2013 +0000
+++ b/mplayer.c	Wed Apr 03 11:52:42 2013 +0000
@@ -1750,7 +1750,7 @@
 static int is_at_end(MPContext *mpctx, m_time_size_t *end_at, double pts)
 {
     switch (end_at->type) {
-    case END_AT_TIME: return end_at->pos <= pts;
+    case END_AT_TIME: return pts != MP_NOPTS_VALUE && end_at->pos <= pts;
     case END_AT_SIZE: return end_at->pos <= stream_tell(mpctx->stream);
     }
     return 0;
@@ -3269,6 +3269,11 @@
         }
         stream_dump_progress_start();
         while (!mpctx->stream->eof && !async_quit_request) {
+            double pts;
+            if (stream_control(mpctx->stream, STREAM_CTRL_GET_CURRENT_TIME, &pts) != STREAM_OK)
+                pts = MP_NOPTS_VALUE;
+            if (is_at_end(mpctx, &end_at, pts))
+                break;
             len = stream_read(mpctx->stream, buf, 4096);
             if (len > 0) {
                 if (fwrite(buf, len, 1, f) != 1) {
@@ -3473,7 +3478,10 @@
         stream_dump_progress_start();
         while (!ds->eof) {
             unsigned char *start;
-            int in_size = ds_get_packet(ds, &start);
+            double pts;
+            int in_size = ds_get_packet_pts(ds, &start, &pts);
+            if (is_at_end(mpctx, &end_at, pts))
+                break;
             if ((mpctx->demuxer->file_format == DEMUXER_TYPE_AVI || mpctx->demuxer->file_format == DEMUXER_TYPE_ASF || mpctx->demuxer->file_format == DEMUXER_TYPE_MOV)
                 && stream_dump_type == 2)
                 fwrite(&in_size, 1, 4, f);