void FFMPEGMovie::_consume()
{
    while( !_stopConsuming )
    {
        {
            std::unique_lock<std::mutex> lock( _targetMutex );
            while( !_targetChangedSent )
                _targetChanged.wait( lock );
            _targetChangedSent = false;

            if( _stopConsuming )
                return;

            if( _seekTo( _targetTimestamp ))
                _ptsPosition = UNDEFINED_PTS; // Reset position after seeking
        }

        PicturePtr frame;
        while( !_stopConsuming && _getPtsDelta() >= getFrameDuration() && !isAtEOF( ))
        {
            frame = _queue.dequeue();
            _ptsPosition = _videoStream->getPositionInSec( frame->getTimestamp( ));
        }

        if( !frame )
        {
            auto exception = std::runtime_error( "Frame unavailable error" );
            _promise.set_exception( std::make_exception_ptr( exception ));
            return;
        }

        _promise.set_value( frame );
    }
}