[MPlayer-dev-eng] [PATCH] an attempt for '-of raw'
Moritz Bunkus
moritz at bunkus.org
Wed Jan 8 21:04:46 CET 2003
Hi.
This patch adds '-of raw'. This should do what the name indicates -
dump the raw video/audio streams to different files. So you should be
able to demultiplex an MPEG with
mencoder -ovc -oac -of raw -o streams file.mpg
and so on. Could be meant as a further replacement for the dumping
functions of mplayer (e.g. -vo yuv4mpeg) or just to get raw XviD/FFmpeg
streams.
Unfortunately it does not work properly. A file I tested was
demultiplexed, but only the video was ok - the audio file was totally
messed up. Same with an OGM.
I don't know all too much about the muxing/demuxing internals of
mencoder, so I hope that some kind soul could take a look at this patch
and help me a bit. I'd really appreciate that :)
Oh... and another question: at the moment I take out_filename and
append '-<streamid>', e.g. '-0', '-1' and so on. Any better
suggestions?
--
==> Ciao, Mosu (Moritz Bunkus)
-------------- next part --------------
diff -NurX diffexcludes -x DOCS main/cfg-mencoder.h of-raw/cfg-mencoder.h
--- main/cfg-mencoder.h 2003-01-03 13:40:09.000000000 +0100
+++ of-raw/cfg-mencoder.h 2003-01-07 18:17:52.000000000 +0100
@@ -133,9 +133,11 @@
struct config of_conf[]={
{"avi", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_AVI, NULL},
{"mpeg", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_MPEG, NULL},
+ {"raw", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_RAW, NULL},
{"help", "\nAvailable output formats:\n"
" avi - Microsoft Audio/Video Interleaved\n"
" mpeg - MPEG-1 system stream format\n"
+ " raw - raw video/audio data\n"
"\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
diff -NurX diffexcludes -x DOCS main/help/help_mp-en.h of-raw/help/help_mp-en.h
--- main/help/help_mp-en.h 2003-01-02 15:41:40.000000000 +0100
+++ of-raw/help/help_mp-en.h 2003-01-07 18:56:42.000000000 +0100
@@ -507,4 +507,12 @@
#define MSGTR_MSGBOX_LABEL_Error "Error!"
#define MSGTR_MSGBOX_LABEL_Warning "Warning!"
+// --- muxer layer, muxer_*
+#define MSGTR_MUXER_NoFilename "No output filename given"
+#define MSGTR_MUXER_TooManyStreams "Too many streams. Increase MUXER_MAX_STREAMS and recompile."
+#define MSGTR_MUXER_StreamType "Warning: unknown stream type encountered."
+#define MSGTR_MUXER_OutOfMemory "Out of memory"
+#define MSGTR_MUXER_CreateFile "Could not create file for raw stream writing."
+#define MSGTR_MUXER_Write "Writing failed, reason %d (%s)"
+
#endif
diff -NurX diffexcludes -x DOCS main/libmpdemux/muxer.c of-raw/libmpdemux/muxer.c
--- main/libmpdemux/muxer.c 2002-12-28 01:48:07.000000000 +0100
+++ of-raw/libmpdemux/muxer.c 2003-01-07 18:19:28.000000000 +0100
@@ -21,6 +21,9 @@
case MUXER_TYPE_MPEG:
muxer_init_muxer_mpeg(muxer);
break;
+ case MUXER_TYPE_RAW:
+ muxer_init_muxer_raw(muxer);
+ break;
case MUXER_TYPE_AVI:
default:
muxer_init_muxer_avi(muxer);
diff -NurX diffexcludes -x DOCS main/libmpdemux/muxer.h of-raw/libmpdemux/muxer.h
--- main/libmpdemux/muxer.h 2002-12-27 23:43:20.000000000 +0100
+++ of-raw/libmpdemux/muxer.h 2003-01-07 18:55:39.000000000 +0100
@@ -6,6 +6,7 @@
#define MUXER_TYPE_AVI 0
#define MUXER_TYPE_MPEG 1
+#define MUXER_TYPE_RAW 2
#define MUXER_MPEG_BLOCKSIZE 2048 // 2048 or 2324 - ?
@@ -34,6 +35,7 @@
// mpeg specific:
unsigned int gop_start; // frame number of this GOP start
size_t ipb[3]; // sizes of I/P/B frames
+ void *priv; // private stream specific data stored by the muxer
} muxer_stream_t;
typedef struct {
diff -NurX diffexcludes -x DOCS main/libmpdemux/muxer_raw.c of-raw/libmpdemux/muxer_raw.c
--- main/libmpdemux/muxer_raw.c 1970-01-01 01:00:00.000000000 +0100
+++ of-raw/libmpdemux/muxer_raw.c 2003-01-07 19:40:19.000000000 +0100
@@ -0,0 +1,98 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+#include "config.h"
+#include "../version.h"
+
+#include "wine/mmreg.h"
+#include "wine/avifmt.h"
+#include "wine/vfw.h"
+#include "bswap.h"
+
+#include "muxer.h"
+#include "../help_mp.h"
+#include "../mp_msg.h"
+
+extern char *out_filename;
+
+static muxer_stream_t *raw_new_stream(muxer_t *muxer, int type) {
+ muxer_stream_t *s;
+ FILE *fout;
+ char *name;
+
+ if ((out_filename == NULL) || (*out_filename == 0)) {
+ mp_msg(MSGT_MUX, MSGL_ERR, MSGTR_MUXER_NoFilename);
+ return NULL;
+ }
+ name = (char *)malloc(strlen(out_filename) + 10);
+ if (name == NULL) {
+ mp_msg(MSGT_MUX, MSGL_ERR, MSGTR_MUXER_OutOfMemory);
+ return NULL;
+ }
+ if(muxer->avih.dwStreams >= MUXER_MAX_STREAMS) {
+ mp_msg(MSGT_MUX, MSGL_ERR, MSGTR_MUXER_TooManyStreams);
+ return NULL;
+ }
+ s=malloc(sizeof(muxer_stream_t));
+ if (s == NULL) {
+ mp_msg(MSGT_MUX, MSGL_ERR, MSGTR_MUXER_OutOfMemory);
+ return NULL;
+ }
+ memset(s, 0, sizeof(muxer_stream_t));
+ muxer->streams[muxer->avih.dwStreams] = s;
+ s->type=type;
+ s->id=muxer->avih.dwStreams;
+ if ((type != MUXER_TYPE_VIDEO) && (type != MUXER_TYPE_AUDIO)) {
+ mp_msg(MSGT_MUX, MSGL_WARN, MSGTR_MUXER_StreamType);
+ free(s);
+ return NULL;
+ }
+ sprintf(name, "%s-%d", out_filename, muxer->avih.dwStreams);
+ fout = fopen(name, "w");
+ free(name);
+ if (fout == NULL) {
+ mp_msg(MSGT_MUX, MSGL_ERR, MSGTR_MUXER_CreateFile);
+ free(s);
+ return NULL;
+ }
+ s->priv = (void *)fout;
+ muxer->avih.dwStreams++;
+
+ return s;
+}
+
+static void raw_write_chunk(muxer_t *muxer, muxer_stream_t *s, FILE *f,
+ size_t len, unsigned int flags) {
+ if (s->priv != NULL)
+ if (fwrite(s->buffer, 1, len, (FILE *)s->priv) != len) {
+ mp_msg(MSGT_MUX, MSGL_ERR, MSGTR_MUXER_Write, errno, strerror(errno));
+ fclose((FILE *)s->priv);
+ s->priv = NULL;
+ }
+ // alter counters:
+ if(s->h.dwSampleSize){
+ // CBR
+ s->h.dwLength += len / s->h.dwSampleSize;
+ if(len % s->h.dwSampleSize)
+ printf("Warning! len isn't divisable by samplesize!\n");
+ } else {
+ // VBR
+ s->h.dwLength++;
+ }
+ s->timer = (double)s->h.dwLength * s->h.dwScale / s->h.dwRate;
+ s->size += len;
+}
+
+static void raw_write_header(muxer_t *muxer, FILE *f) {
+}
+
+void muxer_init_muxer_raw(muxer_t *muxer) {
+ muxer->cont_new_stream = &raw_new_stream;
+ muxer->cont_write_chunk = &raw_write_chunk;
+ muxer->cont_write_header = &raw_write_header; // does nothing
+ muxer->cont_write_index = &raw_write_header; // does nothing
+}
diff -NurX diffexcludes -x DOCS main/mp_msg.h of-raw/mp_msg.h
--- main/mp_msg.h 2002-10-01 08:45:08.000000000 +0200
+++ of-raw/mp_msg.h 2003-01-07 18:33:23.000000000 +0100
@@ -83,6 +83,8 @@
#define MSGT_AFILTER 37 // Audio filter messages
+#define MSGT_MUX 38 // muxer layer, muxer_*
+
#define MSGT_MAX 64
void mp_msg_init();
More information about the MPlayer-dev-eng
mailing list