Skip to content

OutputStream: set global header flag if required + enable experimental codecs #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/AvTranscoder/file/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ IOutputStream& OutputFile::addVideoStream(const VideoCodec& videoDesc)
stream.codec->level = videoDesc.getAVCodecContext().level;
stream.codec->field_order = videoDesc.getAVCodecContext().field_order;

// some codecs need/can use extradata to decode
uint8_t* srcExtradata = videoDesc.getAVCodecContext().extradata;
const int srcExtradataSize = videoDesc.getAVCodecContext().extradata_size;
stream.codec->extradata = (uint8_t*)av_malloc(srcExtradataSize + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(stream.codec->extradata, srcExtradata, srcExtradataSize);
memset(((uint8_t*)stream.codec->extradata) + srcExtradataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
stream.codec->extradata_size = videoDesc.getAVCodecContext().extradata_size;
setOutputStream(stream, videoDesc);

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

setOutputStream(stream, audioDesc);

// need to set the time_base on the AVCodecContext of the AVStream
av_reduce(&stream.codec->time_base.num, &stream.codec->time_base.den, audioDesc.getAVCodecContext().time_base.num,
audioDesc.getAVCodecContext().time_base.den, INT_MAX);
Expand Down Expand Up @@ -319,4 +315,27 @@ void OutputFile::setupRemainingWrappingOptions()
}
}
}

void OutputFile::setOutputStream(AVStream& avStream, const ICodec& codec)
{
// depending on the format, place global headers in extradata instead of every keyframe
if (_formatContext.getAVOutputFormat().flags & AVFMT_GLOBALHEADER) {
avStream.codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
}

// if the codec is experimental, allow it
if(codec.getAVCodec().capabilities & CODEC_CAP_EXPERIMENTAL) {
LOG_WARN("This codec is considered experimental by libav/ffmpeg:" << codec.getCodecName());
avStream.codec->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
}

// some codecs need/can use extradata to decode
uint8_t* srcExtradata = codec.getAVCodecContext().extradata;
const int srcExtradataSize = codec.getAVCodecContext().extradata_size;
avStream.codec->extradata = (uint8_t*)av_malloc(srcExtradataSize + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(avStream.codec->extradata, srcExtradata, srcExtradataSize);
memset(((uint8_t*)avStream.codec->extradata) + srcExtradataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
avStream.codec->extradata_size = codec.getAVCodecContext().extradata_size;
}

}
7 changes: 7 additions & 0 deletions src/AvTranscoder/file/OutputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ class AvExport OutputFile : public IOutputFile
void setupRemainingWrappingOptions();
//@}

/**
* @brief Depending on the format/codec, set general parameters of the stream.
* @param avStream: the stream to set.
* @param codec; the description of the codec used in the stream.
*/
void setOutputStream(AVStream& avStream, const ICodec& codec);

private:
FormatContext _formatContext;
std::vector<OutputStream*> _outputStreams; ///< Has ownership
Expand Down