mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
Added support for writing wave files and specifying filename to write to.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1113 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
2fe79a9b75
commit
b9e199808d
@ -27,6 +27,9 @@ extern int vo_dbpp;
|
|||||||
extern int osd_level;
|
extern int osd_level;
|
||||||
extern int sub_unicode;
|
extern int sub_unicode;
|
||||||
|
|
||||||
|
extern char *ao_outputfilename;
|
||||||
|
extern int ao_pcm_waveheader;
|
||||||
|
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
extern char *mDisplayName;
|
extern char *mDisplayName;
|
||||||
#endif
|
#endif
|
||||||
@ -105,6 +108,10 @@ struct config conf[]={
|
|||||||
{"dumpaudio", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 1},
|
{"dumpaudio", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 1},
|
||||||
{"dumpvideo", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 2},
|
{"dumpvideo", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 2},
|
||||||
|
|
||||||
|
{"aofile", &ao_outputfilename, CONF_TYPE_STRING, 0, 0, 0},
|
||||||
|
{"waveheader", &ao_pcm_waveheader, CONF_TYPE_FLAG, 0, 0, 1},
|
||||||
|
{"nowaveheader", &ao_pcm_waveheader, CONF_TYPE_FLAG, 0, 1, 0},
|
||||||
|
|
||||||
// {"auds", &avi_header.audio_codec, CONF_TYPE_STRING, 0, 0, 0},
|
// {"auds", &avi_header.audio_codec, CONF_TYPE_STRING, 0, 0, 0},
|
||||||
// {"vids", &avi_header.video_codec, CONF_TYPE_STRING, 0, 0, 0},
|
// {"vids", &avi_header.video_codec, CONF_TYPE_STRING, 0, 0, 0},
|
||||||
{"mc", &default_max_pts_correction, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10},
|
{"mc", &default_max_pts_correction, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10},
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
static ao_info_t info =
|
static ao_info_t info =
|
||||||
{
|
{
|
||||||
"PCM writer audio output",
|
"RAW PCM/WAVE file writer audio output",
|
||||||
"pcm",
|
"pcm",
|
||||||
"Atmosfear",
|
"Atmosfear",
|
||||||
""
|
""
|
||||||
@ -22,6 +22,49 @@ LIBAO_EXTERN(pcm)
|
|||||||
// ao_outburst
|
// ao_outburst
|
||||||
// ao_buffersize
|
// ao_buffersize
|
||||||
|
|
||||||
|
char *ao_outputfilename = NULL;
|
||||||
|
int ao_pcm_waveheader = 1;
|
||||||
|
|
||||||
|
#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
|
||||||
|
{
|
||||||
|
unsigned long riff;
|
||||||
|
unsigned long file_length;
|
||||||
|
unsigned long wave;
|
||||||
|
unsigned long fmt;
|
||||||
|
unsigned long fmt_length;
|
||||||
|
short fmt_tag;
|
||||||
|
short channels;
|
||||||
|
unsigned long sample_rate;
|
||||||
|
unsigned long bytes_per_second;
|
||||||
|
short block_align;
|
||||||
|
short bits;
|
||||||
|
unsigned long data;
|
||||||
|
unsigned long data_length;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static struct WaveHeader wavhdr = {
|
||||||
|
WAV_ID_RIFF,
|
||||||
|
0x00000000,
|
||||||
|
WAV_ID_WAVE,
|
||||||
|
WAV_ID_FMT,
|
||||||
|
16,
|
||||||
|
WAV_ID_PCM,
|
||||||
|
2,
|
||||||
|
44100,
|
||||||
|
192000,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
WAV_ID_DATA,
|
||||||
|
0x00000000
|
||||||
|
};
|
||||||
|
|
||||||
static FILE *fp = NULL;
|
static FILE *fp = NULL;
|
||||||
|
|
||||||
// to set/get/query special features/parameters
|
// to set/get/query special features/parameters
|
||||||
@ -32,22 +75,44 @@ static int control(int cmd,int arg){
|
|||||||
// open & setup audio device
|
// open & setup audio device
|
||||||
// return: 1=success 0=fail
|
// return: 1=success 0=fail
|
||||||
static int init(int rate,int channels,int format,int flags){
|
static int init(int rate,int channels,int format,int flags){
|
||||||
|
if(!ao_outputfilename) {
|
||||||
|
ao_outputfilename = (char *) malloc(sizeof(char) * 14);
|
||||||
|
strcpy(ao_outputfilename,(ao_pcm_waveheader ? "audiodump.wav" : "audiodump.pcm"));
|
||||||
|
}
|
||||||
|
|
||||||
printf("PCM: File: audiodump.pcm Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
|
wavhdr.fmt_length = 16; /* = format? */
|
||||||
|
wavhdr.channels = channels;
|
||||||
|
wavhdr.sample_rate = rate;
|
||||||
|
wavhdr.bytes_per_second = rate * (format / 8) * channels;
|
||||||
|
wavhdr.bits = format,
|
||||||
|
|
||||||
|
printf("PCM: File: %s (%s) Samplerate: %iHz Channels: %s Format %s\n", ao_outputfilename, (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
|
||||||
printf("PCM: Info - fastest dumping is achieved with -vo null -hardframedrop.\n");
|
printf("PCM: Info - fastest dumping is achieved with -vo null -hardframedrop.\n");
|
||||||
fp = fopen("audiodump.pcm", "wb");
|
printf("PCM: Info - to write WAVE files use -waveheader (default), for RAW PCM -nowaveheader.\n");
|
||||||
|
fp = fopen(ao_outputfilename, "wb");
|
||||||
|
|
||||||
ao_outburst = 4096;
|
ao_outburst = 4096;
|
||||||
|
|
||||||
|
|
||||||
if(fp) return 1;
|
if(fp) {
|
||||||
printf("PCM: Failed to open audiodump.pcm for writing!\n");
|
if(ao_pcm_waveheader) /* Reserve space for wave header */
|
||||||
|
fseek(fp, sizeof(wavhdr), SEEK_SET);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("PCM: Failed to open %s for writing!\n", ao_outputfilename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// close audio device
|
// close audio device
|
||||||
static void uninit(){
|
static void uninit(){
|
||||||
|
|
||||||
|
if(ao_pcm_waveheader){ /* Write wave header */
|
||||||
|
wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr);
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
fwrite(&wavhdr,sizeof(wavhdr),1,fp);
|
||||||
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
free(ao_outputfilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop playing and empty buffers (for seeking/pause)
|
// stop playing and empty buffers (for seeking/pause)
|
||||||
@ -81,6 +146,9 @@ static int play(void* data,int len,int flags){
|
|||||||
//printf("PCM: Writing chunk!\n");
|
//printf("PCM: Writing chunk!\n");
|
||||||
fwrite(data,len,1,fp);
|
fwrite(data,len,1,fp);
|
||||||
|
|
||||||
|
if(ao_pcm_waveheader)
|
||||||
|
wavhdr.data_length += len;
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user