Exemple #1
0
bool FFDecVAAPI::open( StreamInfo *streamInfo, Writer *writer )
{
	if ( canUseHWAccel( streamInfo ) )
	{
		AVCodec *codec = init( streamInfo );
		if ( codec && hasHWAccel( "vaapi" ) )
		{
			if ( writer && writer->name() != VAApiWriterName )
				writer = NULL;
			hwAccelWriter = writer ? ( VideoWriter * )writer : new VAApiWriter( getModule() );
			if ( ( writer || hwAccelWriter->open() ) && hwAccelWriter->HWAccellInit( codec_ctx->width, codec_ctx->height, avcodec_get_name( codec_ctx->codec_id ) ) )
			{
				codec_ctx->hwaccel_context = av_mallocz( sizeof( vaapi_context ) );
				( ( vaapi_context * )codec_ctx->hwaccel_context )->display    = ( ( VAApiWriter * )hwAccelWriter )->getVADisplay();
				( ( vaapi_context * )codec_ctx->hwaccel_context )->context_id = ( ( VAApiWriter * )hwAccelWriter )->getVAContext();
				( ( vaapi_context * )codec_ctx->hwaccel_context )->config_id  = ( ( VAApiWriter * )hwAccelWriter )->getVAConfig();
				codec_ctx->thread_count   = 1;
				codec_ctx->get_buffer     = HWAccelHelper::get_buffer;
				codec_ctx->release_buffer = HWAccelHelper::release_buffer;
				codec_ctx->get_format     = get_format;
				codec_ctx->slice_flags    = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
				codec_ctx->opaque         = dynamic_cast< HWAccelHelper * >( hwAccelWriter );
				if ( openCodec( codec ) )
					return true;
			}
			else
			{
				if ( !writer )
					delete hwAccelWriter;
				hwAccelWriter = NULL;
			}
		}
	}
	return false;
}
void SimpleVideoInput::openFormatContext(const std::string & fileName)
{
	initLibavcodec();
	
	///////////////////
	// Open file
		
	AVFormatContext *pFormatCtx = nullptr;
	if (avformat_open_input(&pFormatCtx, fileName.c_str(), nullptr, nullptr) != 0)
		throw std::runtime_error("Cannot open file: Does not exists or is no supported format");

	m_detail->format
		= std::shared_ptr<AVFormatContext>(pFormatCtx,
										   [](AVFormatContext *format)
										   {
											   avformat_close_input(&format);
										   });
	if (avformat_find_stream_info(pFormatCtx, nullptr) < 0)
		throw std::runtime_error("File contains no streams");

	findFirstVideoStream();
	openCodec();
	prepareTargetBuffer();
	prepareResizeContext();

	m_detail->isOpened = true;
}
bool OMXAudioPlayer::open(StreamInfo& hints,
                          OMXClock *av_clock,
                          OMXReader *omx_reader,
                          std::string device)
{
    if(ThreadHandle())
    {
        close();
    }

    if (!av_clock)
    {
        return false;
    }


    omxStreamInfo   = hints;
    omxClock        = av_clock;
    omxReader       = omx_reader;
    deviceName      = device;
    currentPTS      = DVD_NOPTS_VALUE;
    doAbort         = false;
    doFlush         = false;
    cachedSize      = 0;
    audioCodecOMX   = NULL;
    channelMap      = NULL;
    speed           = DVD_PLAYSPEED_NORMAL;

// omxClock->SetMasterClock(false);

    bool success  = openCodec();
    if(!success)
    {
        ofLogError(__func__) << "openCodec: " << success;
        close();
        return success;
    }

    success = openDecoder();
    if(!success)
    {
        ofLogError(__func__) << "openDecoder: " << success;
        close();
        return success;
    }

    Create();

    isOpen        = true;

    return true;
}
void RtspStreamWorker::openCodecs(AVFormatContext *context, AVDictionary *options)
{
    for (unsigned int i = 0; i < context->nb_streams; i++)
    {
        AVStream *stream = context->streams[i];
        bool codecOpened = openCodec(stream, options);
        if (!codecOpened)
        {
            qDebug() << "RtspStream: cannot find decoder for stream" << i << "codec" <<
                        stream->codec->codec_id;
            continue;
        }

        char info[512];
        avcodec_string(info, sizeof(info), stream->codec, 0);
        qDebug() << "RtspStream: stream #" << i << ":" << info;
    }
}
void RtspStreamWorker::openCodecs(AVFormatContext *context, AVDictionary *options)
{
    for (unsigned int i = 0; i < context->nb_streams; i++)
    {
        qDebug() << "processing stream id " << i;

        AVStream *stream = context->streams[i];
        bool codecOpened = openCodec(stream, options);
        if (!codecOpened)
        {
            qDebug() << "RtspStream: cannot find decoder for stream" << i << "codec" <<
                        stream->codec->codec_id;
            continue;
        }

        if (stream->codec->codec_type==AVMEDIA_TYPE_VIDEO)
            m_videoStreamIndex = i;

        if (stream->codec->codec_type==AVMEDIA_TYPE_AUDIO)
            m_audioStreamIndex = i;

        char info[512];
        avcodec_string(info, sizeof(info), stream->codec, 0);
        qDebug() << "RtspStream: stream #" << i << ":" << info;
    }

    if (m_audioStreamIndex > -1)
    {
        qDebug() << "audio stream time base " << context->streams[m_audioStreamIndex]->codec->time_base.num
                 << "/"
                 << context->streams[m_audioStreamIndex]->codec->time_base.den;

        emit audioFormat(context->streams[m_audioStreamIndex]->codec->sample_fmt,
                         context->streams[m_audioStreamIndex]->codec->channels,
                         context->streams[m_audioStreamIndex]->codec->sample_rate);
    }

    qDebug() << "video stream index: " << m_videoStreamIndex;
    qDebug() << "audio steam index: " << m_audioStreamIndex;
}
Exemple #6
0
bool FFDecVDPAU::open(StreamInfo *streamInfo, Writer *writer)
{
	/*
	 * AV_PIX_FMT_YUVJ420P doesn't work on FFmpeg/VDPAU, but works on VAAPI over VDPAU.
	 * I tested FFmpeg 2.7 and it works, but crashes (assertion failed) in FFmpeg >= 2.8.
	*/
	const bool canUseYUVJ420P = avcodec_version() < 0x383C64;
	if (streamInfo->img_fmt == AV_PIX_FMT_YUV420P || (canUseYUVJ420P && streamInfo->img_fmt == AV_PIX_FMT_YUVJ420P))
	{
		AVCodec *codec = init(streamInfo);
		if (codec && hasHWAccel("vdpau"))
		{
			if (writer && writer->name() != VDPAUWriterName)
				writer = NULL;
			hwAccelWriter = writer ? (VideoWriter *)writer : new VDPAUWriter(getModule());
			if ((writer || hwAccelWriter->open()) && hwAccelWriter->HWAccellInit(codec_ctx->width, codec_ctx->height, avcodec_get_name(codec_ctx->codec_id)))
			{
				codec_ctx->hwaccel_context = av_mallocz(sizeof(AVVDPAUContext));
				((AVVDPAUContext *)codec_ctx->hwaccel_context)->decoder = ((VDPAUWriter *)hwAccelWriter)->getVdpDecoder();
				((AVVDPAUContext *)codec_ctx->hwaccel_context)->render  = ((VDPAUWriter *)hwAccelWriter)->getVdpDecoderRender();
				codec_ctx->thread_count   = 1;
				codec_ctx->get_buffer2    = HWAccelHelper::get_buffer;
				codec_ctx->get_format     = get_format;
				codec_ctx->slice_flags    = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
				codec_ctx->opaque         = dynamic_cast< HWAccelHelper * >(hwAccelWriter);
				if (openCodec(codec))
					return true;
			}
			else
			{
				if (!writer)
					delete hwAccelWriter;
				hwAccelWriter = NULL;
			}
		}
	}
	return false;
}
Exemple #7
0
bool Encoder::bootstrap(AVCodecID codecId, int width, int height, int fps) {
    return setCodec(codecId) && createContext(width, height, fps) && openCodec() && createFrame();
}