MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / open_audio

Function open_audio

libavformat/output-example.c:82–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82static void open_audio(AVFormatContext *oc, AVStream *st)
83{
84 AVCodecContext *c;
85 AVCodec *codec;
86
87 c = st->codec;
88
89 /* find the audio encoder */
90 codec = avcodec_find_encoder(c->codec_id);
91 if (!codec) {
92 fprintf(stderr, "codec not found\n");
93 exit(1);
94 }
95
96 /* open it */
97 if (avcodec_open(c, codec) < 0) {
98 fprintf(stderr, "could not open codec\n");
99 exit(1);
100 }
101
102 /* init signal generator */
103 t = 0;
104 tincr = 2 * M_PI * 110.0 / c->sample_rate;
105 /* increment frequency by 110 Hz per second */
106 tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate;
107
108 audio_outbuf_size = 10000;
109 audio_outbuf = av_malloc(audio_outbuf_size);
110
111 /* ugly hack for PCM codecs (will be removed ASAP with new PCM
112 support to compute the input frame size in samples */
113 if (c->frame_size <= 1) {
114 audio_input_frame_size = audio_outbuf_size / c->channels;
115 switch(st->codec->codec_id) {
116 case CODEC_ID_PCM_S16LE:
117 case CODEC_ID_PCM_S16BE:
118 case CODEC_ID_PCM_U16LE:
119 case CODEC_ID_PCM_U16BE:
120 audio_input_frame_size >>= 1;
121 break;
122 default:
123 break;
124 }
125 } else {
126 audio_input_frame_size = c->frame_size;
127 }
128 samples = av_malloc(audio_input_frame_size * 2 * c->channels);
129}
130
131/* prepare a 16 bit dummy audio frame of 'frame_size' samples and
132 'nb_channels' channels */

Callers 1

mainFunction · 0.85

Calls 3

avcodec_find_encoderFunction · 0.85
avcodec_openFunction · 0.85
av_mallocFunction · 0.85

Tested by

no test coverage detected