-
Notifications
You must be signed in to change notification settings - Fork 50
Fix encoding of last frames #245
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
Changes from all commits
dbcfed4
af03c26
1f12795
bd2cf15
5828fe3
d5a155a
eb29b44
dea73ee
cdf2697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,8 +96,6 @@ bool AudioEncoder::encodeFrame(const Frame& sourceFrame, CodedData& codedFrame) | |
AVCodecContext& avCodecContext = _codec.getAVCodecContext(); | ||
|
||
AVPacket& packet = codedFrame.getAVPacket(); | ||
packet.stream_index = 0; | ||
|
||
if((avCodecContext.coded_frame) && (avCodecContext.coded_frame->pts != (int)AV_NOPTS_VALUE)) | ||
{ | ||
packet.pts = avCodecContext.coded_frame->pts; | ||
|
@@ -108,55 +106,38 @@ bool AudioEncoder::encodeFrame(const Frame& sourceFrame, CodedData& codedFrame) | |
packet.flags |= AV_PKT_FLAG_KEY; | ||
} | ||
|
||
#if LIBAVCODEC_VERSION_MAJOR > 53 | ||
int gotPacket = 0; | ||
int ret = avcodec_encode_audio2(&avCodecContext, &packet, &sourceFrame.getAVFrame(), &gotPacket); | ||
if(ret != 0 && gotPacket == 0) | ||
{ | ||
throw std::runtime_error("Encode audio frame error: avcodec encode audio frame - " + | ||
getDescriptionFromErrorCode(ret)); | ||
} | ||
#else | ||
int ret = avcodec_encode_audio(&avCodecContext, packet.data, packet.size, &sourceFrame.getAVFrame()); | ||
if(ret < 0) | ||
{ | ||
throw std::runtime_error("Encode audio frame error: avcodec encode audio frame - " + | ||
getDescriptionFromErrorCode(ret)); | ||
} | ||
#endif | ||
|
||
#if LIBAVCODEC_VERSION_MAJOR > 53 | ||
return ret == 0 && gotPacket == 1; | ||
#endif | ||
return ret == 0; | ||
return encode(&sourceFrame.getAVFrame(), packet); | ||
} | ||
|
||
bool AudioEncoder::encodeFrame(CodedData& codedFrame) | ||
{ | ||
AVCodecContext& avCodecContext = _codec.getAVCodecContext(); | ||
return encode(NULL, codedFrame.getAVPacket()); | ||
} | ||
|
||
AVPacket& packet = codedFrame.getAVPacket(); | ||
packet.stream_index = 0; | ||
bool AudioEncoder::encode(const AVFrame* decodedData, AVPacket& encodedData) | ||
{ | ||
// Be sure that data of AVPacket is NULL so that the encoder will allocate it | ||
encodedData.data = NULL; | ||
|
||
AVCodecContext& avCodecContext = _codec.getAVCodecContext(); | ||
#if LIBAVCODEC_VERSION_MAJOR > 53 | ||
int gotPacket = 0; | ||
int ret = avcodec_encode_audio2(&avCodecContext, &packet, NULL, &gotPacket); | ||
if(ret != 0 && gotPacket == 0) | ||
const int ret = avcodec_encode_audio2(&avCodecContext, &encodedData, decodedData, &gotPacket); | ||
if(ret != 0) | ||
{ | ||
throw std::runtime_error("Encode audio frame error: avcodec encode last audio frame - " + | ||
throw std::runtime_error("Encode audio frame error: avcodec encode audio frame - " + | ||
getDescriptionFromErrorCode(ret)); | ||
} | ||
return ret == 0 && gotPacket == 1; | ||
|
||
return gotPacket == 1; | ||
#else | ||
int ret = avcodec_encode_audio(&avCodecContext, packet.data, packet.size, NULL); | ||
const int ret = avcodec_encode_audio(&avCodecContext, encodedData.data, encodedData.size, decodedData); | ||
if(ret < 0) | ||
{ | ||
throw std::runtime_error("Encode audio frame error: avcodec encode last audio frame - " + | ||
throw std::runtime_error("Encode audio frame error: avcodec encode audio frame - " + | ||
getDescriptionFromErrorCode(ret)); | ||
} | ||
return ret == 0; | ||
|
||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm.. Shouldn't ret be more than 0 ? And wouldn't it be a bad value ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes: https://ffmpeg.org/doxygen/2.7/group__lavc__encoding.html#gaf12a9da0d33f50ff406e03572fab4763 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes ! Okay ! |
||
#endif | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark here..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep: dea73ee