@@ -42,23 +42,7 @@ IOutputStream& OutputFile::addVideoStream(const VideoCodec& videoDesc)
42
42
stream.codec ->level = videoDesc.getAVCodecContext ().level ;
43
43
stream.codec ->field_order = videoDesc.getAVCodecContext ().field_order ;
44
44
45
- if (_formatContext.getAVOutputFormat ().flags & AVFMT_GLOBALHEADER) {
46
- stream.codec ->flags |= CODEC_FLAG_GLOBAL_HEADER;
47
- }
48
-
49
- // if the codec is experimental, allow it
50
- if (videoDesc.getAVCodec ().capabilities & CODEC_CAP_EXPERIMENTAL) {
51
- LOG_WARN (" This codec is considered experimental by libav/ffmpeg:" << videoDesc.getCodecName ());
52
- stream.codec ->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
53
- }
54
-
55
- // some codecs need/can use extradata to decode
56
- uint8_t * srcExtradata = videoDesc.getAVCodecContext ().extradata ;
57
- const int srcExtradataSize = videoDesc.getAVCodecContext ().extradata_size ;
58
- stream.codec ->extradata = (uint8_t *)av_malloc (srcExtradataSize + FF_INPUT_BUFFER_PADDING_SIZE);
59
- memcpy (stream.codec ->extradata , srcExtradata, srcExtradataSize);
60
- memset (((uint8_t *)stream.codec ->extradata ) + srcExtradataSize, 0 , FF_INPUT_BUFFER_PADDING_SIZE);
61
- stream.codec ->extradata_size = videoDesc.getAVCodecContext ().extradata_size ;
45
+ setOutputStream (stream, videoDesc);
62
46
63
47
// need to set the time_base on the AVCodecContext and the AVStream
64
48
// compensating the frame rate with the ticks_per_frame and keeping
@@ -85,6 +69,8 @@ IOutputStream& OutputFile::addAudioStream(const AudioCodec& audioDesc)
85
69
stream.codec ->sample_fmt = audioDesc.getAVCodecContext ().sample_fmt ;
86
70
stream.codec ->frame_size = audioDesc.getAVCodecContext ().frame_size ;
87
71
72
+ setOutputStream (stream, audioDesc);
73
+
88
74
// need to set the time_base on the AVCodecContext of the AVStream
89
75
av_reduce (&stream.codec ->time_base .num , &stream.codec ->time_base .den , audioDesc.getAVCodecContext ().time_base .num ,
90
76
audioDesc.getAVCodecContext ().time_base .den , INT_MAX);
@@ -329,4 +315,27 @@ void OutputFile::setupRemainingWrappingOptions()
329
315
}
330
316
}
331
317
}
318
+
319
+ void OutputFile::setOutputStream (AVStream& avStream, const ICodec& codec)
320
+ {
321
+ // depending on the format, place global headers in extradata instead of every keyframe
322
+ if (_formatContext.getAVOutputFormat ().flags & AVFMT_GLOBALHEADER) {
323
+ avStream.codec ->flags |= CODEC_FLAG_GLOBAL_HEADER;
324
+ }
325
+
326
+ // if the codec is experimental, allow it
327
+ if (codec.getAVCodec ().capabilities & CODEC_CAP_EXPERIMENTAL) {
328
+ LOG_WARN (" This codec is considered experimental by libav/ffmpeg:" << codec.getCodecName ());
329
+ avStream.codec ->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
330
+ }
331
+
332
+ // some codecs need/can use extradata to decode
333
+ uint8_t * srcExtradata = codec.getAVCodecContext ().extradata ;
334
+ const int srcExtradataSize = codec.getAVCodecContext ().extradata_size ;
335
+ avStream.codec ->extradata = (uint8_t *)av_malloc (srcExtradataSize + FF_INPUT_BUFFER_PADDING_SIZE);
336
+ memcpy (avStream.codec ->extradata , srcExtradata, srcExtradataSize);
337
+ memset (((uint8_t *)avStream.codec ->extradata ) + srcExtradataSize, 0 , FF_INPUT_BUFFER_PADDING_SIZE);
338
+ avStream.codec ->extradata_size = codec.getAVCodecContext ().extradata_size ;
339
+ }
340
+
332
341
}
0 commit comments