annotate libmpcodecs/ae.c @ 16383:3cc0d81806bf

In order to make sure A/V sync is preserved, MEncoder really has to be fed with an audio track. Added a paragraph that explains why, and nuked all the occurences of "-nosound".
author gpoirier
date Sun, 04 Sep 2005 12:21:47 +0000
parents af245d15f502
children d9b74d27974d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
1 #include <stdio.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
2 #include <string.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
3 #include <stdlib.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
4 #include <inttypes.h>
15238
2cc48c37a7eb FreeBSD fix
nexus
parents: 15234
diff changeset
5 #include <unistd.h>
15240
6d6792c02b6f macosx compilation fix
nicodvb
parents: 15238
diff changeset
6 #include <sys/types.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
7 #include <math.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
8 #include "aviheader.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
9 #include "ms_hdr.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
10 #include "muxer.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
11 #include "ae.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
12 #include "../config.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
13
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
14 #ifdef HAVE_TOOLAME
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
15 #include "ae_toolame.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
16 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
17
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
18 #ifdef HAVE_MP3LAME
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
19 #include "ae_lame.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
20 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
21
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
22 #ifdef USE_LIBAVCODEC
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
23 #include "ae_lavc.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
24 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
25
15259
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
26 #ifdef HAVE_FAAC
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
27 #include "ae_faac.h"
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
28 #endif
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
29
15359
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
30 #ifdef HAVE_TWOLAME
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
31 #include "ae_twolame.h"
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
32 #endif
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
33
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
34 audio_encoder_t *new_audio_encoder(muxer_stream_t *stream, audio_encoding_params_t *params)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
35 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
36 int ris;
15242
f27a3f8d3241 gcc 2.95 compilation fix
reimar
parents: 15240
diff changeset
37 audio_encoder_t *encoder;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
38 if(! params)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
39 return NULL;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
40
15242
f27a3f8d3241 gcc 2.95 compilation fix
reimar
parents: 15240
diff changeset
41 encoder = (audio_encoder_t *) calloc(1, sizeof(audio_encoder_t));
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
42 memcpy(&encoder->params, params, sizeof(audio_encoding_params_t));
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
43 encoder->stream = stream;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
44
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
45 switch(stream->codec)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
46 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
47 case ACODEC_PCM:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
48 ris = mpae_init_pcm(encoder);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
49 break;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
50 #ifdef HAVE_TOOLAME
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
51 case ACODEC_TOOLAME:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
52 ris = mpae_init_toolame(encoder);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
53 break;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
54 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
55 #ifdef USE_LIBAVCODEC
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
56 case ACODEC_LAVC:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
57 ris = mpae_init_lavc(encoder);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
58 break;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
59 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
60 #ifdef HAVE_MP3LAME
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
61 case ACODEC_VBRMP3:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
62 ris = mpae_init_lame(encoder);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
63 break;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
64 #endif
15259
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
65 #ifdef HAVE_FAAC
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
66 case ACODEC_FAAC:
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
67 ris = mpae_init_faac(encoder);
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
68 break;
854990f357ee added faac audio encoder
nicodvb
parents: 15242
diff changeset
69 #endif
15359
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
70 #ifdef HAVE_TWOLAME
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
71 case ACODEC_TWOLAME:
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
72 ris = mpae_init_twolame(encoder);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
73 break;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents: 15259
diff changeset
74 #endif
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
75 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
76
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
77 if(! ris)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
78 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
79 free(encoder);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
80 return NULL;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
81 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
82 encoder->bind(encoder, stream);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
83 encoder->decode_buffer = (int*)malloc(encoder->decode_buffer_size);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
84 if(! encoder->decode_buffer)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
85 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
86 free(encoder);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
87 return NULL;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
88 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
89
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
90 encoder->codec = stream->codec;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
91 return encoder;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
92 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
93
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
94