Skip to content

Commit e96c7b6

Browse files
author
Clement Champetier
committed
OutputFile: added private method setOutputStream
* This method is called for each video/audio output streams. * It sets general parameters of the stream, depending on the format/codec.
1 parent b40674d commit e96c7b6

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,7 @@ IOutputStream& OutputFile::addVideoStream(const VideoCodec& videoDesc)
4242
stream.codec->level = videoDesc.getAVCodecContext().level;
4343
stream.codec->field_order = videoDesc.getAVCodecContext().field_order;
4444

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);
6246

6347
// need to set the time_base on the AVCodecContext and the AVStream
6448
// compensating the frame rate with the ticks_per_frame and keeping
@@ -85,6 +69,8 @@ IOutputStream& OutputFile::addAudioStream(const AudioCodec& audioDesc)
8569
stream.codec->sample_fmt = audioDesc.getAVCodecContext().sample_fmt;
8670
stream.codec->frame_size = audioDesc.getAVCodecContext().frame_size;
8771

72+
setOutputStream(stream, audioDesc);
73+
8874
// need to set the time_base on the AVCodecContext of the AVStream
8975
av_reduce(&stream.codec->time_base.num, &stream.codec->time_base.den, audioDesc.getAVCodecContext().time_base.num,
9076
audioDesc.getAVCodecContext().time_base.den, INT_MAX);
@@ -329,4 +315,27 @@ void OutputFile::setupRemainingWrappingOptions()
329315
}
330316
}
331317
}
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+
332341
}

src/AvTranscoder/file/OutputFile.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ class AvExport OutputFile : public IOutputFile
9898
void setupRemainingWrappingOptions();
9999
//@}
100100

101+
/**
102+
* @brief Depending on the format/codec, set general parameters of the stream.
103+
* @param avStream: the stream to set.
104+
* @param codec; the description of the codec used in the stream.
105+
*/
106+
void setOutputStream(AVStream& avStream, const ICodec& codec);
107+
101108
private:
102109
FormatContext _formatContext;
103110
std::vector<OutputStream*> _outputStreams; ///< Has ownership

0 commit comments

Comments
 (0)