@@ -194,8 +194,7 @@ BMDTimeValue frameRateDuration, frameRateScale;
194194
195195static AVStream *add_audio_stream (AVFormatContext *oc, enum AVCodecID codec_id)
196196{
197- AVCodecContext *c;
198- AVCodec *codec;
197+ AVCodecParameters *par;
199198 AVStream *st;
200199
201200 st = avformat_new_stream (oc, NULL );
@@ -204,38 +203,21 @@ static AVStream *add_audio_stream(AVFormatContext *oc, enum AVCodecID codec_id)
204203 exit (1 );
205204 }
206205
207- c = st->codec ;
208- c ->codec_id = codec_id;
209- c ->codec_type = AVMEDIA_TYPE_AUDIO;
206+ par = st->codecpar ;
207+ par ->codec_id = codec_id;
208+ par ->codec_type = AVMEDIA_TYPE_AUDIO;
210209
211210 /* put sample parameters */
212- c->sample_fmt = sample_fmt;
213- // c->bit_rate = 64000;
214- c->sample_rate = 48000 ;
215- c->channels = g_audioChannels;
216- // some formats want stream headers to be separate
217- if (oc->oformat ->flags & AVFMT_GLOBALHEADER) {
218- c->flags |= CODEC_FLAG_GLOBAL_HEADER;
219- }
220-
221- codec = avcodec_find_encoder (c->codec_id );
222- if (!codec) {
223- fprintf (stderr, " codec not found\n " );
224- exit (1 );
225- }
226-
227- if (avcodec_open2 (c, codec, NULL ) < 0 ) {
228- fprintf (stderr, " could not open codec\n " );
229- exit (1 );
230- }
211+ par->format = sample_fmt;
212+ par->sample_rate = 48000 ;
213+ par->channels = g_audioChannels;
231214
232215 return st;
233216}
234217
235218static AVStream *add_video_stream (AVFormatContext *oc, enum AVCodecID codec_id)
236219{
237- AVCodecContext *c;
238- AVCodec *codec;
220+ AVCodecParameters *par;
239221 AVStream *st;
240222
241223 st = avformat_new_stream (oc, NULL );
@@ -244,53 +226,32 @@ static AVStream *add_video_stream(AVFormatContext *oc, enum AVCodecID codec_id)
244226 exit (1 );
245227 }
246228
247- c = st->codec ;
248- c ->codec_id = codec_id;
249- c ->codec_type = AVMEDIA_TYPE_VIDEO;
229+ par = st->codecpar ;
230+ par ->codec_id = codec_id;
231+ par ->codec_type = AVMEDIA_TYPE_VIDEO;
250232
251- /* put sample parameters */
252- // c->bit_rate = 400000;
253- /* resolution must be a multiple of two */
254- c->width = displayMode->GetWidth ();
255- c->height = displayMode->GetHeight ();
233+ par->width = displayMode->GetWidth ();
234+ par->height = displayMode->GetHeight ();
235+ par->format = pix_fmt;
256236 /* time base: this is the fundamental unit of time (in seconds) in terms
257237 * of which frame timestamps are represented. for fixed-fps content,
258238 * timebase should be 1/framerate and timestamp increments should be
259239 * identically 1.*/
260240 displayMode->GetFrameRate (&frameRateDuration, &frameRateScale);
261- c->time_base .den = frameRateScale;
262- c->time_base .num = frameRateDuration;
263- c->pix_fmt = pix_fmt;
241+ st->time_base .den = frameRateScale;
242+ st->time_base .num = frameRateDuration;
264243
265244 if (codec_id == AV_CODEC_ID_V210 || codec_id == AV_CODEC_ID_R210)
266- c-> bits_per_raw_sample = 10 ;
245+ par-> bits_per_coded_sample = 10 ;
267246 if (codec_id == AV_CODEC_ID_RAWVIDEO)
268- c->codec_tag = avcodec_pix_fmt_to_codec_tag (c->pix_fmt );
269- // some formats want stream headers to be separate
270- if (oc->oformat ->flags & AVFMT_GLOBALHEADER) {
271- c->flags |= CODEC_FLAG_GLOBAL_HEADER;
272- }
273-
274- /* find the video encoder */
275- // codec = avcodec_find_encoder(c->codec_id);
276- // if (!codec) {
277- // fprintf(stderr, "codec not found\n");
278- // exit(1);
279- // }
280-
281- /* open the codec */
282- // if (avcodec_open2(c, codec, NULL) < 0) {
283- // fprintf(stderr, "could not open codec\n");
284- // exit(1);
285- // }
247+ par->codec_tag = avcodec_pix_fmt_to_codec_tag (pix_fmt);
286248
287249 return st;
288250}
289251
290252static AVStream *add_data_stream (AVFormatContext *oc, enum AVCodecID codec_id)
291253{
292- AVCodec *codec;
293- AVCodecContext *c;
254+ AVCodecParameters *par;
294255 AVStream *st;
295256
296257 st = avformat_new_stream (oc, NULL );
@@ -299,25 +260,13 @@ static AVStream *add_data_stream(AVFormatContext *oc, enum AVCodecID codec_id)
299260 exit (1 );
300261 }
301262
302- c = st->codec ;
303- c ->codec_id = codec_id;
304- c ->codec_type = AVMEDIA_TYPE_DATA;
263+ par = st->codecpar ;
264+ par ->codec_id = codec_id;
265+ par ->codec_type = AVMEDIA_TYPE_DATA;
305266
306267 displayMode->GetFrameRate (&frameRateDuration, &frameRateScale);
307- c->time_base .den = frameRateScale;
308- c->time_base .num = frameRateDuration;
309-
310- // some formats want stream headers to be separate
311- if (oc->oformat ->flags & AVFMT_GLOBALHEADER)
312- c->flags |= CODEC_FLAG_GLOBAL_HEADER;
313-
314- /* find the video encoder */
315- codec = (AVCodec*)av_malloc (sizeof (AVCodec));
316- memset (codec, 0 , sizeof (AVCodec));
317- codec->id = c->codec_id ;
318-
319- /* open the codec */
320- c->codec = codec;
268+ st->time_base .den = frameRateScale;
269+ st->time_base .num = frameRateDuration;
321270
322271 return st;
323272}
@@ -376,15 +325,12 @@ void write_data_packet(char *data, int size, int64_t pts)
376325
377326void write_audio_packet (IDeckLinkAudioInputPacket *audioFrame)
378327{
379- AVCodecContext *c;
380328 AVPacket pkt;
381329 BMDTimeValue audio_pts;
382330 void *audioFrameBytes;
383331
384332 av_init_packet (&pkt);
385333
386- c = audio_st->codec ;
387- // hack among hacks
388334 pkt.size = audioFrame->GetSampleFrameCount () *
389335 g_audioChannels * (g_audioSampleDepth / 8 );
390336 audioFrame->GetBytes (&audioFrameBytes);
@@ -401,7 +347,6 @@ void write_audio_packet(IDeckLinkAudioInputPacket *audioFrame)
401347 pkt.flags |= AV_PKT_FLAG_KEY;
402348 pkt.stream_index = audio_st->index ;
403349 pkt.data = (uint8_t *)audioFrameBytes;
404- c->frame_number ++;
405350
406351 avpacket_queue_put (&queue, &pkt);
407352}
@@ -410,12 +355,10 @@ void write_video_packet(IDeckLinkVideoInputFrame *videoFrame,
410355 int64_t pts, int64_t duration)
411356{
412357 AVPacket pkt;
413- AVCodecContext *c;
414358 void *frameBytes;
415359 time_t cur_time;
416360
417361 av_init_packet (&pkt);
418- c = video_st->codec ;
419362 if (g_verbose && frameCount % 25 == 0 ) {
420363 unsigned long long qsize = avpacket_queue_size (&queue);
421364 fprintf (stderr,
@@ -472,7 +415,6 @@ void write_video_packet(IDeckLinkVideoInputFrame *videoFrame,
472415 pkt.size = videoFrame->GetRowBytes () *
473416 videoFrame->GetHeight ();
474417 // fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts);
475- c->frame_number ++;
476418 avpacket_queue_put (&queue, &pkt);
477419}
478420
0 commit comments