FFmpeg: Encoding cleanup

This commit is contained in:
Jeffrey Pfau 2016-09-21 14:09:49 -07:00
parent cf6006f9f8
commit 1e10098e33
3 changed files with 7 additions and 5 deletions

View File

@ -8,6 +8,7 @@ Bugfixes:
- FFmpeg: Fix encoding AAC - FFmpeg: Fix encoding AAC
Misc: Misc:
- All: Only update version info if needed - All: Only update version info if needed
- FFmpeg: Encoding cleanup
0.5.0: (2016-09-19) 0.5.0: (2016-09-19)
Features: Features:

View File

@ -395,7 +395,6 @@ void _ffmpegPostAudioFrame(struct mAVStream* stream, int16_t left, int16_t right
if ((encoder->currentAudioSample * 4) < encoder->audioBufferSize) { if ((encoder->currentAudioSample * 4) < encoder->audioBufferSize) {
return; return;
} }
encoder->currentAudioSample = 0;
int channelSize = 2 * av_get_bytes_per_sample(encoder->audio->sample_fmt); int channelSize = 2 * av_get_bytes_per_sample(encoder->audio->sample_fmt);
avresample_convert(encoder->resampleContext, avresample_convert(encoder->resampleContext,
@ -409,14 +408,15 @@ void _ffmpegPostAudioFrame(struct mAVStream* stream, int16_t left, int16_t right
#endif #endif
avresample_read(encoder->resampleContext, encoder->audioFrame->data, encoder->postaudioBufferSize / channelSize); avresample_read(encoder->resampleContext, encoder->audioFrame->data, encoder->postaudioBufferSize / channelSize);
AVRational timeBase = { 1, PREFERRED_SAMPLE_RATE }; encoder->audioFrame->pts = av_rescale_q(encoder->currentAudioFrame - encoder->currentAudioSample, encoder->audio->time_base, encoder->audioStream->time_base);
encoder->audioFrame->pts = encoder->nextAudioPts; encoder->currentAudioSample = 0;
encoder->nextAudioPts = av_rescale_q(encoder->currentAudioFrame, timeBase, encoder->audioStream->time_base);
AVPacket packet; AVPacket packet;
av_init_packet(&packet); av_init_packet(&packet);
packet.data = 0; packet.data = 0;
packet.size = 0; packet.size = 0;
packet.pts = encoder->audioFrame->pts;
int gotData; int gotData;
#ifdef FFMPEG_USE_PACKETS #ifdef FFMPEG_USE_PACKETS
avcodec_send_frame(encoder->audio, encoder->audioFrame); avcodec_send_frame(encoder->audio, encoder->audioFrame);
@ -483,6 +483,7 @@ void _ffmpegPostVideoFrame(struct mAVStream* stream, const color_t* pixels, size
av_frame_make_writable(encoder->videoFrame); av_frame_make_writable(encoder->videoFrame);
#endif #endif
encoder->videoFrame->pts = av_rescale_q(encoder->currentVideoFrame, encoder->video->time_base, encoder->videoStream->time_base); encoder->videoFrame->pts = av_rescale_q(encoder->currentVideoFrame, encoder->video->time_base, encoder->videoStream->time_base);
packet.pts = encoder->videoFrame->pts;
++encoder->currentVideoFrame; ++encoder->currentVideoFrame;
sws_scale(encoder->scaleContext, (const uint8_t* const*) &pixels, (const int*) &stride, 0, encoder->iheight, encoder->videoFrame->data, encoder->videoFrame->linesize); sws_scale(encoder->scaleContext, (const uint8_t* const*) &pixels, (const int*) &stride, 0, encoder->iheight, encoder->videoFrame->data, encoder->videoFrame->linesize);

View File

@ -52,7 +52,7 @@ struct FFmpegEncoder {
AVFrame* audioFrame; AVFrame* audioFrame;
size_t currentAudioSample; size_t currentAudioSample;
int64_t currentAudioFrame; int64_t currentAudioFrame;
int64_t nextAudioPts; int64_t nextAudioPts; // TODO (0.6): Remove
struct AVAudioResampleContext* resampleContext; struct AVAudioResampleContext* resampleContext;
#ifdef FFMPEG_USE_NEW_BSF #ifdef FFMPEG_USE_NEW_BSF
struct AVBSFContext* absf; // Needed for AAC in MP4 struct AVBSFContext* absf; // Needed for AAC in MP4