Skip to content

Commit 8ddf8e1

Browse files
authored
Merge pull request #255 from cchampet/fix_outputVideoCodecFlags
OutputStream: set global header flag if required + enable experimental codecs
2 parents cd61868 + e96c7b6 commit 8ddf8e1

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +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-
// some codecs need/can use extradata to decode
46-
uint8_t* srcExtradata = videoDesc.getAVCodecContext().extradata;
47-
const int srcExtradataSize = videoDesc.getAVCodecContext().extradata_size;
48-
stream.codec->extradata = (uint8_t*)av_malloc(srcExtradataSize + FF_INPUT_BUFFER_PADDING_SIZE);
49-
memcpy(stream.codec->extradata, srcExtradata, srcExtradataSize);
50-
memset(((uint8_t*)stream.codec->extradata) + srcExtradataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
51-
stream.codec->extradata_size = videoDesc.getAVCodecContext().extradata_size;
45+
setOutputStream(stream, videoDesc);
5246

5347
// need to set the time_base on the AVCodecContext and the AVStream
5448
// compensating the frame rate with the ticks_per_frame and keeping
@@ -75,6 +69,8 @@ IOutputStream& OutputFile::addAudioStream(const AudioCodec& audioDesc)
7569
stream.codec->sample_fmt = audioDesc.getAVCodecContext().sample_fmt;
7670
stream.codec->frame_size = audioDesc.getAVCodecContext().frame_size;
7771

72+
setOutputStream(stream, audioDesc);
73+
7874
// need to set the time_base on the AVCodecContext of the AVStream
7975
av_reduce(&stream.codec->time_base.num, &stream.codec->time_base.den, audioDesc.getAVCodecContext().time_base.num,
8076
audioDesc.getAVCodecContext().time_base.den, INT_MAX);
@@ -319,4 +315,27 @@ void OutputFile::setupRemainingWrappingOptions()
319315
}
320316
}
321317
}
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+
322341
}

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)