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
void QuicktimeImageStream::run()
{

   bool playing = false;
   bool done = false;

   while (!done) {


      ThreadCommand cmd = getCmd();
      OSG_DEBUG << "movietime: " << _movieData->getMovieTime() << " rate: " << _movieData->getMovieRate() << " state " << cmd << " playing: " << playing << " done " << done << "  " << _wrIndex << "/" << _rdIndex << std::endl;
      // Handle commands
      {
         if (cmd != THREAD_IDLE) {
            OSG_DEBUG << "new cmd: " << cmd << std::endl;
            switch (cmd) {
                    case THREAD_START: // Start or continue stream
                       applyLoopingMode();
                       _movieData->setMovieRate(1.0);

                       playing = true;
                       break;

                    case THREAD_STOP:
                       _movieData->setMovieRate(0);
                       OSG_INFO << "QT-ImageStream: stop at "<< std::endl;
                       playing = false;
                       break;

                    case THREAD_REWIND:
                       SetMovieRate(_movieData->getMovie(),0.0);
                       GoToBeginningOfMovie(_movieData->getMovie());
                       break;

                    case THREAD_FORWARD:
                       SetMovieRate(_movieData->getMovie(),0.0);
                       GoToEndOfMovie(_movieData->getMovie());
                       break;

                    case THREAD_SEEK:
                       _movieData->setMovieTime(_currentRate);
                       playing = true;
                       break;

                    case THREAD_SETRATE:
                       _movieData->setMovieRate(_currentRate);
                       playing = (_currentRate != 0.0);
                       break;

                    case THREAD_CLOSE:
                       _movieData->setMovieRate(0.0);
                       break;

                    case THREAD_QUIT: // TODO
                       _movieData->setMovieRate(0.0);
                       OSG_INFO << "QT-ImageStream: quit" << std::endl;
                       //playing = false;
                       done = true;
                       break;
                    default:
                       OSG_WARN << "QT-ImageStream: Unknown command " << cmd << std::endl;
                       break;
            }
         }

         MoviesTask(_movieData->getMovie(),0);
         _current = _movieData->getMovieTime();
      }


      if (_lastUpdate!= _current)
      {
         // force the texture to update the image
         dirty();
         // update internal time and take care of looping
         _lastUpdate = _current;
      }

      if (playing)
      {
         OpenThreads::Thread::microSleep(16000);
      }
      else if (!done)
      {
         OpenThreads::Thread::microSleep(IDLE_TIMEOUT);
      }
   }


}
Exemplo n.º 3
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.º 4
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;
}