[MPlayer-cvslog] CVS: main/TOOLS 302m_convert.c, NONE, 1.1 360m_convert.c, NONE, 1.1 Makefile, 1.5, 1.6 README, 1.7, 1.8
Reimar Döffinger CVS
syncmail at mplayerhq.hu
Tue Aug 23 20:03:25 CEST 2005
CVS change done by Reimar Döffinger CVS
Update of /cvsroot/mplayer/main/TOOLS
In directory mail:/var2/tmp/cvs-serv30019
Modified Files:
Makefile README
Added Files:
302m_convert.c 360m_convert.c
Log Message:
Add D-Cinema Audio and Video conversion programs
--- NEW FILE ---
/**
* convert D-Cinema Audio (probably SMPTE 302M) to a
* wav file that MPlayer can play.
* Usage: 302m_convert <infile> <outfile>
*/
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <byteswap.h>
#define le2me_32(x) (x)
#define le2me_16(x) (x)
#define be2me_16(x) bswap_16(x)
// From MPlayer libao/ao_pcm.c
#define WAV_ID_RIFF 0x46464952 /* "RIFF" */
#define WAV_ID_WAVE 0x45564157 /* "WAVE" */
#define WAV_ID_FMT 0x20746d66 /* "fmt " */
#define WAV_ID_DATA 0x61746164 /* "data" */
#define WAV_ID_PCM 0x0001
struct WaveHeader {
uint32_t riff;
uint32_t file_length;
uint32_t wave;
uint32_t fmt;
uint32_t fmt_length;
uint16_t fmt_tag;
uint16_t channels;
uint32_t sample_rate;
uint32_t bytes_per_second;
uint16_t block_align;
uint16_t bits;
uint32_t data;
uint32_t data_length;
};
static struct WaveHeader wavhdr = {
le2me_32(WAV_ID_RIFF),
le2me_32(0x7fffffff),
le2me_32(WAV_ID_WAVE),
le2me_32(WAV_ID_FMT),
le2me_32(16),
le2me_16(WAV_ID_PCM),
le2me_16(6),
le2me_32(96000),
le2me_32(1728000),
le2me_16(18),
le2me_16(24),
le2me_32(WAV_ID_DATA),
le2me_32(0x7fffffff),
};
// this format is completely braindead, and this bitorder
// is the result of pure guesswork (counting how often
// the bits flip), so it might be wrong.
void fixup(unsigned char *in_, unsigned char *out) {
int i;
unsigned char in[3] = {in_[0], in_[1], in_[2]};
unsigned char sync = in[2] & 0x0f; // sync flags
in[2] >>= 4;
out[2] = 0;
for (i = 0; i < 4; i++) {
out[2] <<= 1;
out[2] |= in[2] & 1;
in[2] >>= 1;
}
for (i = 0; i < 4; i++) {
out[2] <<= 1;
out[2] |= in[1] & 1;
in[1] >>= 1;
}
out[1] = 0;
for (i = 0; i < 4; i++) {
out[1] <<= 1;
out[1] |= in[1] & 1;
in[1] >>= 1;
}
for (i = 0; i < 4; i++) {
out[1] <<= 1;
out[1] |= in[0] & 1;
in[0] >>= 1;
}
out[0] = 0;
for (i = 0; i < 4; i++) {
out[0] <<= 1;
out[0] |= in[0] & 1;
in[0] >>= 1;
}
out[0] <<= 4;
out[0] |= sync; // sync flags go into lowest bits
// it seems those might also contain audio data,
// don't know if this is the right order then
// these might be also useful to detect the number
// of channels in case there are files with != 6 channels
}
int main(int argc, char *argv[]) {
FILE *in = fopen(argv[1], "r");
FILE *out = fopen(argv[2], "w");
int i;
uint16_t blocklen, unknown;
unsigned char *block;
if (!in) {
printf("Could not open %s for reading\n", argv[1]);
return EXIT_FAILURE;
}
if (!out) {
printf("Could not open %s for writing\n", argv[2]);
return EXIT_FAILURE;
}
fwrite(&wavhdr, 1, sizeof(wavhdr), out);
do {
fread(&blocklen, 2, 1, in);
blocklen = be2me_16(blocklen);
fread(&unknown, 2, 1, in);
block = malloc(blocklen);
blocklen = fread(block, 1, blocklen, in);
for (i = 0; i < blocklen; i += 3)
fixup(&block[i], &block[i]);
fwrite(block, 1, blocklen, out);
free(block);
} while (!feof(in));
return EXIT_SUCCESS;
}
--- NEW FILE ---
/**
* convert D-Cinema Video (MPEG2 in GXF, SMPTE 360M) to a
* MPEG-ES file that MPlayer can play (use -demuxer mpeges).
* Usage: 360m_convert <infile> <outfile>
*/
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *in = fopen(argv[1], "r");
FILE *out = fopen(argv[2], "w");
int discard = 0;
unsigned char buf[4];
if (!in) {
printf("Could not open %s for reading\n", argv[1]);
return EXIT_FAILURE;
}
if (!out) {
printf("Could not open %s for writing\n", argv[2]);
return EXIT_FAILURE;
}
fread(buf, 4, 1, in);
do {
if (buf[0] == 0 && buf[1] == 0 && buf[2] == 1) {
// encountered a header
// skip data between a 0xbf or 0xbc header and the next 0x00 header
if (buf[3] == 0xbc || buf[3] == 0xbf)
discard = 1;
else if (buf[3] == 0)
discard = 0;
}
if (!discard)
fwrite(&buf[0], 1, 1, out);
buf[0] = buf[1];
buf[1] = buf[2];
buf[2] = buf[3];
fread(&buf[3], 1, 1, in);
} while (!feof(in));
return EXIT_SUCCESS;
}
Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/TOOLS/Makefile,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Makefile 2 Jul 2005 19:19:41 -0000 1.5
+++ Makefile 23 Aug 2005 18:03:23 -0000 1.6
@@ -15,6 +15,8 @@
subrip \
fastmemcpybench \
vivodump \
+ 302m_convert \
+ 360m_convert \
all: $(OBJS)
Index: README
===================================================================
RCS file: /cvsroot/mplayer/main/TOOLS/README,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- README 18 Aug 2005 20:00:57 -0000 1.7
+++ README 23 Aug 2005 18:03:23 -0000 1.8
@@ -469,3 +469,24 @@
Description: Dumps vobsub soft subtitles streams embedded in avi files.
Usage: avisubdump <avi>
+
+Format conversion scripts in the TOOLS dir
+------------------------------------------
+
+302m_convert.c
+
+Author: Reimar Döffinger
+
+Description: Converts D-Cinema Audio (SMPTE 302M?) to WAV.
+
+Usage: 302m_convert <in.302> <out.wav>
+
+
+360m_convert.c
+
+Author: Reimar Döffinger
+
+Description: Converts D-Cinema Videa (MPEG2 in GXF, SMPTE 360M) to MPEG-ES.
+ Use -demuxer mpeges to play the converted file.
+
+Usage: 360m_convert <in.gxf> <out.m2v>
More information about the MPlayer-cvslog
mailing list