Exemplo n.º 1
0
bool FFmpegImageStream::open(const std::string & filename, FFmpegParameters* parameters)
{
    setFileName(filename);

    if (! m_decoder->open(filename, parameters))
        return false;

    setImage(
        m_decoder->video_decoder().width(), m_decoder->video_decoder().height(), 1, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE,
        const_cast<unsigned char *>(m_decoder->video_decoder().image()), NO_DELETE
    );


    setPixelAspectRatio(m_decoder->video_decoder().pixelAspectRatio());

    OSG_NOTICE<<"ffmpeg::open("<<filename<<") size("<<s()<<", "<<t()<<") aspect ratio "<<m_decoder->video_decoder().pixelAspectRatio()<<std::endl;

#if 1
    // swscale is reported errors and then crashing when rescaling video of size less than 10 by 10.
    if (s()<=10 || t()<=10) return false;
#endif

    m_decoder->video_decoder().setUserData(this);
    m_decoder->video_decoder().setPublishCallback(publishNewFrame);

    if (m_decoder->audio_decoder().validContext())
    {
        OSG_NOTICE<<"Attaching FFmpegAudioStream"<<std::endl;

        getAudioStreams().push_back(new FFmpegAudioStream(m_decoder.get()));
    }

    _status = PAUSED;
    applyLoopingMode();

    start(); // start thread

    return true;
}
Exemplo n.º 2
0
bool NAMFFmpegImageStream::open(const std::string & filename)
{
    setFileName(filename);

    if (! m_decoder->open(filename))
        return false;

    //setImage(
    //    m_decoder->video_decoder().width(), m_decoder->video_decoder().height(), 1, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE,
    //    const_cast<unsigned char *>(m_decoder->video_decoder().image()), NO_DELETE
    //);

   // OpenCV Image creation
   //cvNamedWindow( "Test", 0 );
   //cvResizeWindow("Test", m_decoder->video_decoder().width(), m_decoder->video_decoder().height());

   // According to previous line the number of channels is 4: RGBA
   _nbChannels = 4;
   _opencvImage = cvCreateImage(cvSize(m_decoder->video_decoder().width(), m_decoder->video_decoder().height()), IPL_DEPTH_8U, _nbChannels);
   
   
   //TEST
   createIplImageFromGLimage(const_cast<unsigned char *>(m_decoder->video_decoder().image()));
   
   process(_opencvImage);
   //OpenCV_to_OSG(_opencvImage,this);
   setImage(
            m_decoder->video_decoder().width(), m_decoder->video_decoder().height(), 1, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE,
            (unsigned char*)(_opencvImage->imageData), NO_DELETE
            );
   /*setImage(
            m_decoder->video_decoder().width(), m_decoder->video_decoder().height(), 1, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE,
            //(unsigned char*)(_opencvImage->imageData), NO_DELETE
            _movieImage->data(),NO_DELETE
            );*/
   
   // END TEST
   
   
   
    setPixelAspectRatio(m_decoder->video_decoder().pixelAspectRatio());

    OSG_NOTICE<<"ffmpeg::open("<<filename<<") size("<<s()<<", "<<t()<<") aspect ratio "<<m_decoder->video_decoder().pixelAspectRatio()<<std::endl;

#if 1
    // swscale is reported errors and then crashing when rescaling video of size less than 10 by 10.
    if (s()<=10 || t()<=10) return false;
#endif

    m_decoder->video_decoder().setUserData(this);
    m_decoder->video_decoder().setPublishCallback(publishNewFrame);

    /*if (m_decoder->audio_decoder().validContext())
    {
        OSG_NOTICE<<"Attaching FFmpegAudioStream"<<std::endl;

       getAudioStreams().push_back(new osgFFmpeg::FFmpegAudioStream(m_decoder.get()));
    }*/

    _status = PAUSED;
    applyLoopingMode();

    start(); // start thread

    return true;
}
Exemplo n.º 3
0
bool FFmpegPlayer::open(const std::string & filename, FFmpegParameters* parameters, VideoOutputDevice * pVOD)
{
    av_log(NULL, AV_LOG_INFO, "FFmpeg plugin release version: %d", JAZZROS_FFMPEG_LIBRARY_RELEASE_VERSION_INT);
    av_log(NULL, AV_LOG_INFO, "OS physical RAM size: %d MB", getMemorySize() / 1000000);

    setFileName(filename);

    m_pVOD = pVOD;

    m_vodd = m_pVOD->CreateData();

    if (m_fileHolder.open(filename, parameters, m_vodd->getFFPixelFormat()) < 0)
        return false;

    /**
     * We need initialize video output device before open streamer and after holder has been opened
     */
    if (m_fileHolder.videoIndex() >= 0) {
        if (m_pVOD->Initialize() == 0) {

            if (m_vodd->Initialize(m_pVOD, m_fileHolder.getFrameSize()) != 0) {

                av_log(NULL, AV_LOG_ERROR, "ERROR: Cannot initialize video output device");
                m_fileHolder.close();
                return false;
            }

            pVOD->SetCurrentData (m_vodd);
        }
    }

    if (m_streamer.open(& m_fileHolder, this) < 0)
    {
        m_fileHolder.close();
        return false;
    }
    // If video exist...
    if (m_fileHolder.videoIndex() >= 0)
    {
        m_pVOD->render(m_vodd, m_streamer.getFrame());

        setPixelAspectRatio(m_fileHolder.pixelAspectRatio());

        av_log(NULL, AV_LOG_INFO, "File( %s ) size(%d, %d) aspect ratio %f",
               filename.c_str(),
               s(),t(),
               m_fileHolder.pixelAspectRatio());

        // swscale is reported errors and then crashing when rescaling video of size less than 10 by 10.
        if (s()<=10 || t()<=10)
            return false;
    }
    // If audio exist...
    if (m_fileHolder.isHasAudio())
    {
        av_log(NULL, AV_LOG_INFO, "Attaching FFmpegAudioStream");

        getAudioStreams().push_back(new FFmpegAudioStream(& m_fileHolder, & m_streamer));
    }

    _status = PAUSED;
    applyLoopingMode();

    start(); // start thread

    return true;
}