Skip to content

AvInputVideo: fix missing frame when transcoding (flush decoder buffer) #19

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 2 commits into from
Dec 8, 2014
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
18 changes: 10 additions & 8 deletions src/AvTranscoder/essenceStream/AvInputAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ AvInputAudio::AvInputAudio( AvInputStream& inputStream )
, _inputStream ( &inputStream )
, _codec( &inputStream.getAudioCodec() )
, _frame ( NULL )
, _selectedStream( inputStream.getStreamIndex() )
{
}

Expand Down Expand Up @@ -156,25 +155,28 @@ bool AvInputAudio::decodeNextFrame()
while( ! got_frame )
{
CodedData data;
if( ! _inputStream->readNextPacket( data ) ) // error or end of file
return false;

AVPacket packet;
av_init_packet( &packet );

packet.stream_index = _selectedStream;
packet.data = data.getPtr();
packet.size = data.getSize();
bool nextPacketRead = _inputStream->readNextPacket( data );

packet.stream_index = _inputStream->getStreamIndex();
packet.data = nextPacketRead ? data.getPtr(): NULL;
packet.size = data.getSize();

int ret = avcodec_decode_audio4( _codec->getAVCodecContext(), _frame, &got_frame, &packet );
av_free_packet( &packet );

if( ! nextPacketRead && ret == 0 && got_frame == 0 ) // error or end of file
return false;

if( ret < 0 )
{
char err[AV_ERROR_MAX_STRING_SIZE];
av_strerror( ret, err, sizeof(err) );
throw std::runtime_error( "an error occured during audio decoding" + std::string( err ) );
}

av_free_packet( &packet );
}
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/AvTranscoder/essenceStream/AvInputAudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class AvExport AvInputAudio : public IInputEssence
AvInputStream* _inputStream; ///< Stream from which we read next frames
const AudioCodec* _codec; ///< Audio decoder. Has link (no ownership)
AVFrame* _frame; ///< Libav object to store decoded data

int _selectedStream; ///< Index of the selected stream in the input file
};

}
Expand Down
15 changes: 9 additions & 6 deletions src/AvTranscoder/essenceStream/AvInputVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ AvInputVideo::AvInputVideo( AvInputStream& inputStream )
, _inputStream ( &inputStream )
, _codec( &inputStream.getVideoCodec() )
, _frame ( NULL )
, _selectedStream( inputStream.getStreamIndex() )
{
}

Expand Down Expand Up @@ -106,24 +105,28 @@ bool AvInputVideo::decodeNextFrame()
while( ! got_frame )
{
CodedData data;
if( ! _inputStream->readNextPacket( data ) ) // error or end of file
return false;

AVPacket packet;
av_init_packet( &packet );

packet.stream_index = _selectedStream; //_inputStream->getStreamIndex();
packet.data = data.getPtr(); //nextPacketRead ? data.getPtr(): NULL;
bool nextPacketRead = _inputStream->readNextPacket( data );

packet.stream_index = _inputStream->getStreamIndex();
packet.data = nextPacketRead ? data.getPtr(): NULL;
packet.size = data.getSize();

int ret = avcodec_decode_video2( _codec->getAVCodecContext(), _frame, &got_frame, &packet );
av_free_packet( &packet );

if( ! nextPacketRead && ret == 0 && got_frame == 0 ) // error or end of file
return false;

if( ret < 0 )
{
char err[AV_ERROR_MAX_STRING_SIZE];
av_strerror( ret, err, sizeof(err) );
throw std::runtime_error( "an error occured during video decoding - " + std::string(err) );
}
av_free_packet( &packet );
}
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/AvTranscoder/essenceStream/AvInputVideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class AvExport AvInputVideo : public IInputEssence
AvInputStream* _inputStream; ///< Stream from which we read next frames
const VideoCodec* _codec; ///< Video decoder. Has link (no ownership)
AVFrame* _frame; ///< Libav object to store decoded data

int _selectedStream; ///< Index of the selected stream in the input file
};

}
Expand Down