core: add --stream-capture

This is a partial revert of commit 7059c15, and basically re-adds
--capture, just with different option names and slightly different
semantics.
This commit is contained in:
wm4 2013-05-11 22:19:33 +02:00
parent e6e5a7b221
commit faad40aad9
9 changed files with 71 additions and 0 deletions

View File

@ -341,6 +341,7 @@ sub-scale x subtitle font size multiplicator
ass-use-margins x see ``--ass-use-margins``
ass-vsfilter-aspect-compat x see ``--ass-vsfilter-aspect-compat``
ass-style-override x see ``--ass-style-override``
stream-capture x a filename, see ``--capture``
tv-brightness x
tv-contrast x
tv-saturation x

View File

@ -1528,6 +1528,15 @@
Print out a custom string during playback instead of the standard status
line. Expands properties. See ``--playing-msg``.
--stream-capture=<filename>
Allows capturing the primary stream (not additional audio tracks or other
kind of streams) into the given file. Capturing can also be started and
stopped changing the filename with the ``stream-capture`` slave property.
Generally this will not produce usable results for anything else than MPEG
or raw streams, unless capturing includes the file headers and is not
interrupted. Note that, due to cache latencies, captured data may begin and
end somewhat delayed compared to what you see displayed.
--playlist=<filename>
Play files according to a playlist file (ASX, Winamp, SMIL, or
one-file-per-line format).

View File

@ -634,6 +634,8 @@ const m_option_t mplayer_opts[]={
OPT_FLAG("untimed", untimed, 0),
OPT_STRING("stream-capture", stream_capture, 0),
#ifdef CONFIG_LIRC
{"lircconf", &lirc_configfile, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
#endif

View File

@ -197,6 +197,20 @@ static int mp_property_stream_path(m_option_t *prop, int action, void *arg,
return m_property_strdup_ro(prop, action, arg, stream->url);
}
static int mp_property_stream_capture(m_option_t *prop, int action,
void *arg, MPContext *mpctx)
{
if (!mpctx->stream)
return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_SET) {
char *filename = *(char **)arg;
stream_set_capture_file(mpctx->stream, filename);
// fall through to mp_property_generic_option
}
return mp_property_generic_option(prop, action, arg, mpctx);
}
/// Demuxer name (RO)
static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
@ -1357,6 +1371,7 @@ static const m_option_t mp_properties[] = {
0, 0, 0, NULL },
{ "stream-path", mp_property_stream_path, CONF_TYPE_STRING,
0, 0, 0, NULL },
M_OPTION_PROPERTY_CUSTOM("stream-capture", mp_property_stream_capture),
{ "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
0, 0, 0, NULL },
{ "stream-pos", mp_property_stream_pos, CONF_TYPE_INT64,

View File

@ -4233,6 +4233,8 @@ goto_enable_cache: ;
if (demux_was_interrupted(mpctx))
goto terminate_playback;
stream_set_capture_file(mpctx->stream, opts->stream_capture);
//============ Open DEMUXERS --- DETECT file type =======================
mpctx->audio_delay = opts->audio_delay;

View File

@ -85,6 +85,7 @@ typedef struct MPOpts {
int osd_fractions;
char *vobsub_name;
int untimed;
char *stream_capture;
int loop_times;
int ordered_chapters;
int chapter_merge_threshold;

View File

@ -593,6 +593,7 @@ int cache_stream_fill_buffer(stream_t *s){
s->buf_len=len;
s->pos+=len;
// printf("[%d]",len);fflush(stdout);
stream_capture_write(s);
return len;
}

View File

@ -41,6 +41,7 @@
#include <winsock2.h>
#endif
#include "core/bstr.h"
#include "core/mp_msg.h"
#include "osdep/shmem.h"
#include "osdep/timer.h"
@ -312,6 +313,37 @@ static int stream_reconnect(stream_t *s)
return 0;
}
void stream_set_capture_file(stream_t *s, const char *filename)
{
if (!bstr_equals(bstr0(s->capture_filename), bstr0(filename))) {
if (s->capture_file)
fclose(s->capture_file);
talloc_free(s->capture_filename);
s->capture_file = NULL;
s->capture_filename = NULL;
if (filename) {
s->capture_file = fopen(filename, "wb");
if (s->capture_file) {
s->capture_filename = talloc_strdup(NULL, filename);
} else {
mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
"Error opening capture file: %s\n", strerror(errno));
}
}
}
}
void stream_capture_write(stream_t *s)
{
if (s->capture_file) {
if (fwrite(s->buffer, s->buf_len, 1, s->capture_file) < 1) {
mp_tmsg(MSGT_GLOBAL, MSGL_ERR, "Error writing capture file: %s\n",
strerror(errno));
stream_set_capture_file(s, NULL);
}
}
}
int stream_read_internal(stream_t *s, void *buf, int len)
{
int orig_len = len;
@ -367,6 +399,7 @@ int stream_fill_buffer(stream_t *s)
s->buf_pos = 0;
s->buf_len = len;
// printf("[%d]",len);fflush(stdout);
stream_capture_write(s);
return len;
}
@ -566,6 +599,7 @@ void free_stream(stream_t *s)
#ifdef CONFIG_STREAM_CACHE
cache_uninit(s);
#endif
stream_set_capture_file(s, NULL);
if (s->close)
s->close(s);

View File

@ -188,6 +188,9 @@ typedef struct stream {
unsigned char buffer[STREAM_BUFFER_SIZE >
STREAM_MAX_SECTOR_SIZE ? STREAM_BUFFER_SIZE :
STREAM_MAX_SECTOR_SIZE];
FILE *capture_file;
char *capture_filename;
} stream_t;
#ifdef CONFIG_NETWORKING
@ -197,6 +200,9 @@ typedef struct stream {
int stream_fill_buffer(stream_t *s);
int stream_seek_long(stream_t *s, int64_t pos);
void stream_set_capture_file(stream_t *s, const char *filename);
void stream_capture_write(stream_t *s);
#ifdef CONFIG_STREAM_CACHE
int stream_enable_cache_percent(stream_t *stream, int64_t stream_cache_size,
float stream_cache_min_percent,