Index: stream/cache2.c =================================================================== --- stream/cache2.c (revision 32396) +++ stream/cache2.c (working copy) @@ -510,6 +510,8 @@ s->buf_len=len; s->pos+=len; // printf("[%d]",len);fflush(stdout); + if (s->capture_file) + stream_capture_do(s); return len; } Index: stream/stream.c =================================================================== --- stream/stream.c (revision 32396) +++ stream/stream.c (working copy) @@ -179,6 +179,7 @@ } } s = new_stream(-2,-2); + s->capture_file = NULL; s->url=strdup(filename); s->flags |= mode; *ret = sinfo->open(s,mode,arg,file_format); @@ -269,6 +270,14 @@ //=================== STREAMER ========================= +void stream_capture_do(stream_t *s) { + if (fwrite(s->buffer, s->buf_len, 1, s->capture_file) < 1) { + mp_msg(MSGT_GLOBAL, MSGL_ERR, "Error writing capture file: %s\n", strerror(errno)); + fclose(s->capture_file); + s->capture_file = NULL; + } +} + int stream_fill_buffer(stream_t *s){ int len; // we will retry even if we already reached EOF previously. @@ -300,6 +309,8 @@ s->buf_len=len; s->pos+=len; // printf("[%d]",len);fflush(stdout); + if (s->capture_file) + stream_capture_do(s); return len; } @@ -463,6 +474,11 @@ #ifdef CONFIG_STREAM_CACHE cache_uninit(s); #endif + if (s->capture_file) { + fclose(s->capture_file); + s->capture_file = NULL; + } + if(s->close) s->close(s); if(s->fd>0){ /* on unix we define closesocket to close Index: stream/stream.h =================================================================== --- stream/stream.h (revision 32396) +++ stream/stream.h (working copy) @@ -23,6 +23,7 @@ #include "m_option.h" #include "mp_msg.h" #include "url.h" +#include #include #include #include @@ -165,6 +166,7 @@ streaming_ctrl_t *streaming_ctrl; #endif unsigned char buffer[STREAM_BUFFER_SIZE>STREAM_MAX_SECTOR_SIZE?STREAM_BUFFER_SIZE:STREAM_MAX_SECTOR_SIZE]; + FILE *capture_file; } stream_t; #ifdef CONFIG_NETWORKING @@ -173,6 +175,7 @@ int stream_fill_buffer(stream_t *s); int stream_seek_long(stream_t *s, off_t pos); +void stream_capture_do(stream_t *s); #ifdef CONFIG_STREAM_CACHE int stream_enable_cache(stream_t *stream,int size,int min,int prefill); Index: input/input.c =================================================================== --- input/input.c (revision 32396) +++ input/input.c (working copy) @@ -173,6 +173,7 @@ { MP_CMD_LOADFILE, "loadfile", 1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, { MP_CMD_LOADLIST, "loadlist", 1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, { MP_CMD_RUN, "run", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } }, + { MP_CMD_CAPTURING, "capturing", 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_TV_TELETEXT_ADD_DEC, "teletext_add_dec", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } }, { MP_CMD_TV_TELETEXT_GO_LINK, "teletext_go_link", 1, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, @@ -461,6 +462,7 @@ #endif { { 'T', 0 }, "vo_ontop" }, { { 'f', 0 }, "vo_fullscreen" }, + { { 'c', 0 }, "capturing" }, { { 's', 0 }, "screenshot 0" }, { { 'S', 0 }, "screenshot 1" }, { { 'w', 0 }, "panscan -0.1" }, Index: input/input.h =================================================================== --- input/input.h (revision 32396) +++ input/input.h (working copy) @@ -43,6 +43,7 @@ MP_CMD_TV_STEP_CHANNEL, MP_CMD_TV_STEP_NORM, MP_CMD_TV_STEP_CHANNEL_LIST, + MP_CMD_CAPTURING, MP_CMD_VO_FULLSCREEN, MP_CMD_SUB_POS, MP_CMD_DVDNAV, Index: DOCS/tech/slave.txt =================================================================== --- DOCS/tech/slave.txt (revision 32396) +++ DOCS/tech/slave.txt (working copy) @@ -73,6 +73,10 @@ If [abs] is non-zero, parameter is set to . is in the range [-100, 100]. +capturing [value] + Toggle/set capturing the primary stream like -dumpstream. + Requires the -capture parameter to be given. + change_rectangle Change the position of the rectangle filter rectangle. @@ -527,6 +531,7 @@ switch_audio int -2 255 X X X select audio stream switch_angle int -2 255 X X X select DVD angle switch_title int -2 255 X X X select DVD title +capturing flag 0 1 X X X dump primary stream if enabled fullscreen flag 0 1 X X X deinterlace flag 0 1 X X X ontop flag 0 1 X X X Index: DOCS/man/en/mplayer.1 =================================================================== --- DOCS/man/en/mplayer.1 (revision 32396) +++ DOCS/man/en/mplayer.1 (working copy) @@ -281,6 +281,8 @@ Toggle subtitle alignment: top / middle / bottom. .IPs "x and z" Adjust subtitle delay by +/\- 0.1 seconds. +.IPs "c (\-capture only)" +Start/stop capturing the primary stream. .IPs "r and t" Move subtitles up/down. .IPs "i (\-edlout mode only)" @@ -1340,6 +1342,18 @@ this position rather than performing a stream seek (default: 50). . .TP +.B \-capture (MPlayer only) +Allows capturing the primary stream (not additional audio tracks or other +kind of streams) into the file specified by \-dumpfile or \"stream.dump\" +by default. +If this option is given, capturing can be started and stopped by pressing +the key bound to this function (see section INTERACTIVE CONTROL). +Same as for \-dumpstream, this will likely not produce usable results for +anything else than MPEG streams. +Note that, due to cache latencies, captured data may begin and end +somewhat delayed compared to what you see displayed. +. +.TP .B \-cdda (CDDA only) This option can be used to tune the CD Audio reading feature of MPlayer. .sp 1 @@ -1465,7 +1479,8 @@ .TP .B \-dumpfile (MPlayer only) Specify which file MPlayer should dump to. -Should be used together with \-dumpaudio / \-dumpvideo / \-dumpstream. +Should be used together with \-dumpaudio / \-dumpvideo / \-dumpstream / +\-capture. . .TP .B \-dumpstream (MPlayer only) Index: mplayer.c =================================================================== --- mplayer.c (revision 32396) +++ mplayer.c (working copy) @@ -264,8 +264,9 @@ #endif // dump: -static char *stream_dump_name="stream.dump"; - int stream_dump_type=0; +char *stream_dump_name="stream.dump"; +int stream_dump_type=0; +int capture_dump=0; // A-V sync: static float default_max_pts_correction=-1; Index: cfg-mplayer.h =================================================================== --- cfg-mplayer.h (revision 32396) +++ cfg-mplayer.h (working copy) @@ -292,6 +292,8 @@ {"dumpjacosub", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 8, NULL}, {"dumpsami", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 9, NULL}, + {"capture", &capture_dump, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + #ifdef CONFIG_LIRC {"lircconf", &lirc_configfile, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL}, #endif Index: mplayer.h =================================================================== --- mplayer.h (revision 32396) +++ mplayer.h (working copy) @@ -39,7 +39,9 @@ /* for the GUI */ extern int auto_quality; extern int disable_gui_conf; + extern int stream_dump_type; +extern char *stream_dump_name; void update_set_of_subtitles(void); Index: help/help_mp-hu.h =================================================================== --- help/help_mp-hu.h (revision 32396) +++ help/help_mp-hu.h (working copy) @@ -213,6 +213,8 @@ #define MSGTR_OSDChapter "Fejezet: (%d) %s" #define MSGTR_OSDAngle "Szög: %d/%d" #define MSGTR_OSDDeinterlace "Deinterlace: %s" +#define MSGTR_OSDCapturing "Mentés: %s" +#define MSGTR_OSDCapturingFailure "Mentés sikertelen" // property values #define MSGTR_Enabled "bekapcsolva" Index: help/help_mp-it.h =================================================================== --- help/help_mp-it.h (revision 32396) +++ help/help_mp-it.h (working copy) @@ -208,6 +208,8 @@ #define MSGTR_OSDChapter "Capitolo: (%d) %s" #define MSGTR_OSDAngle "Angolazione: %d/%d" #define MSGTR_OSDDeinterlace "Deinterlacciamento: %s" +#define MSGTR_OSDCapturing "Registrazione: %s" +#define MSGTR_OSDCapturingFailure "Registrazione fallito" // property values #define MSGTR_Enabled "abilitat" Index: help/help_mp-en.h =================================================================== --- help/help_mp-en.h (revision 32396) +++ help/help_mp-en.h (working copy) @@ -213,6 +213,8 @@ #define MSGTR_OSDChapter "Chapter: (%d) %s" #define MSGTR_OSDAngle "Angle: %d/%d" #define MSGTR_OSDDeinterlace "Deinterlace: %s" +#define MSGTR_OSDCapturing "Capturing: %s" +#define MSGTR_OSDCapturingFailure "Capturing failed" // property values #define MSGTR_Enabled "enabled" Index: command.c =================================================================== --- command.c (revision 32396) +++ command.c (working copy) @@ -1108,6 +1108,48 @@ return M_PROPERTY_NOT_IMPLEMENTED; } +static int mp_property_capture(m_option_t *prop, int action, + void *arg, MPContext *mpctx) +{ + int ret; + int capturing = !!mpctx->stream->capture_file; + + if (!mpctx->stream) + return M_PROPERTY_UNAVAILABLE; + + ret = m_property_flag(prop, action, arg, &capturing); + if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) { + if (capturing) { + if (capture_dump) { + if (!(mpctx->stream->capture_file = fopen(stream_dump_name, "wb"))) { + mp_msg(MSGT_GLOBAL, MSGL_ERR, "Error opening capture file: %s\n", strerror(errno)); + ret = M_PROPERTY_ERROR; + } + } else { + mp_msg(MSGT_GLOBAL, MSGL_ERR, "Capturing not enabled (forgot -capture parameter?)\n"); + ret = M_PROPERTY_ERROR; + } + } else { + fclose(mpctx->stream->capture_file); + mpctx->stream->capture_file = NULL; + } + } + + switch (ret) { + case M_PROPERTY_ERROR: + set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDCapturingFailure); + break; + case M_PROPERTY_OK: + set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDCapturing, + mpctx->stream->capture_file ? MSGTR_Enabled : MSGTR_Disabled); + break; + default: + break; + } + + return ret; +} + /// Panscan (RW) static int mp_property_panscan(m_option_t *prop, int action, void *arg, MPContext *mpctx) @@ -2096,6 +2138,8 @@ 0, 0, 0, NULL }, { "pause", mp_property_pause, CONF_TYPE_FLAG, M_OPT_RANGE, 0, 1, NULL }, + { "capturing", mp_property_capture, CONF_TYPE_FLAG, + M_OPT_RANGE, 0, 1, NULL }, // Audio { "volume", mp_property_volume, CONF_TYPE_FLOAT, @@ -2285,6 +2329,7 @@ { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus }, { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL }, { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL }, + { "capturing", MP_CMD_CAPTURING, 1, 0, -1, NULL }, // audio { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume }, { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus }, Index: command.h =================================================================== --- command.h (revision 32396) +++ command.h (working copy) @@ -22,6 +22,8 @@ struct MPContext; struct mp_cmd; +extern int capture_dump; + int run_command(struct MPContext *mpctx, struct mp_cmd *cmd); char *property_expand_string(struct MPContext *mpctx, char *str); void property_print_help(void);