Skip to content
Open
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
20 changes: 11 additions & 9 deletions erizo/src/erizo/media/ExternalOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ void ExternalOutput::syncClose() {
av_write_trailer(context_);
}

if (video_stream_ && video_stream_->codec != nullptr) {
avcodec_close(video_stream_->codec);
}
//call avformat_free_context will close codec ,free video_stream_, codec

if (audio_stream_ && audio_stream_->codec != nullptr) {
avcodec_close(audio_stream_->codec);
}
// if (video_stream_ && video_stream_->codec != nullptr) {
// avcodec_close(video_stream_->codec);
// }

// if (audio_stream_ && audio_stream_->codec != nullptr) {
// avcodec_close(audio_stream_->codec);
// }

if (context_ != nullptr) {
avio_close(context_->pb);
Expand Down Expand Up @@ -411,9 +413,9 @@ bool ExternalOutput::initContext() {
if (context_->oformat->flags & AVFMT_GLOBALHEADER) {
audio_stream_->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
}

context_->streams[0] = video_stream_;
context_->streams[1] = audio_stream_;
// call avformat_new_stream will insert stream into streams
// context_->streams[0] = video_stream_;
// context_->streams[1] = audio_stream_;
if (avio_open(&context_->pb, context_->filename, AVIO_FLAG_WRITE) < 0) {
ELOG_ERROR("Error opening output file");
return false;
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/media/codecs/AudioCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int AudioEncoder::encodeAudio(unsigned char* inBuffer, int nSamples, AVPacket* p

int AudioEncoder::closeEncoder() {
if (aCoderContext_ != NULL) {
avcodec_close(aCoderContext_);
avcodec_free_context(&aCoderContext_);
}
if (aFrame_ != NULL) {
av_frame_free(&aFrame_);
Expand Down Expand Up @@ -246,7 +246,7 @@ int AudioDecoder::decodeAudio(unsigned char* inBuff, int inBuffLen,

int AudioDecoder::closeDecoder() {
if (aDecoderContext_ != NULL) {
avcodec_close(aDecoderContext_);
avcodec_free_context(&aDecoderContext_);
}
if (dFrame_ != NULL) {
av_frame_free(&dFrame_);
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/media/codecs/VideoCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int VideoEncoder::encodeVideo(unsigned char* inBuffer, int inLength, unsigned ch

int VideoEncoder::closeEncoder() {
if (coder_context_ != NULL)
avcodec_close(coder_context_);
avcodec_free_context(&coder_context_);
if (cPicture != NULL)
av_frame_free(&cPicture);

Expand Down Expand Up @@ -361,7 +361,7 @@ int VideoDecoder::decodeVideo(unsigned char* inBuff, int inBuffLen,

int VideoDecoder::closeDecoder() {
if (!initWithContext_ && vDecoderContext != NULL)
avcodec_close(vDecoderContext);
avcodec_free_context(&vDecoderContext);
if (dPicture != NULL)
av_frame_free(&dPicture);
return 0;
Expand Down