bool Movie::saveFrame(AVPacket *frame) { bool saved = false; if (m_hasAudio && frame->stream_index == m_audio->getStreamID()) { // If it was an audio frame... m_audio->pushFrame(frame); saved = true; } else if (m_hasVideo && frame->stream_index == m_video->getStreamID()) { // If it was a video frame... m_video->pushFrame(frame); saved = true; } else { if (usesDebugMessages()) std::cerr << "Movie::SaveFrame() - unknown packet stream id (" << frame->stream_index << ")\n"; } return saved; }
void Movie::draw(sf::RenderTarget& target, sf::RenderStates states) const { if (usesDebugMessages()) { printWithTime("audio playing : " + ftostr(m_audio->getPlayingOffset().asSeconds()) + "s"); printWithTime("reference playing : " + ftostr(getPlayingOffset().asSeconds()) + "s"); } states.transform *= getTransform(); m_video->draw(target, states); }
bool Movie::openFromFile(const std::string& filename) { int err = 0; bool preloaded = false; // Make sure everything is cleaned before opening a new movie stop(); close(); // Load all the decoders av_register_all(); // Open the movie file err = avformat_open_input(&m_avFormatCtx, filename.c_str(), NULL, NULL); if (err != 0) { outputError(err, "unable to open file " + filename); return false; } // Read the general movie informations err = avformat_find_stream_info(m_avFormatCtx, NULL); if (err < 0) { outputError(err); close(); return false; } if (usesDebugMessages()) // Output the movie informations av_dump_format(m_avFormatCtx, 0, filename.c_str(), 0); // Perform the audio and video loading m_hasVideo = m_video->initialize(); m_hasAudio = m_audio->initialize(); if (m_hasVideo) { preloaded = m_video->preLoad(); if (!preloaded) // Loading first frames failed { if (sfe::Movie::usesDebugMessages()) std::cerr << "Movie::OpenFromFile() - Movie_video::PreLoad() failed.\n"; } } return m_hasAudio || (m_hasVideo && preloaded); }
void Movie::play(void) { if (m_status != Playing) { if (m_hasAudio) { sf::Time startOffset = m_audio->getPlayingOffset(); sf::Clock timer; m_audio->play(); timer.restart(); while (startOffset == m_audio->getPlayingOffset() && timer.getElapsedTime() < sf::seconds(5)) sf::sleep(sf::milliseconds(1)); // Note: this is a workaround for SFML issue #201 // Audio initialization may silently fail and audio won't start playing if (timer.getElapsedTime() >= sf::seconds(5)) std::cerr << "*** warning: Movie::play() - no audio progress for 5 sec, giving up on syncing" << std::endl; m_progressAtPause = m_audio->getPlayingOffset(); } m_overallTimer.restart(); IFVIDEO(m_video->play()); if (usesDebugMessages()) printWithTime("did start movie timer"); // Don't restart watch thread if we're resuming if (m_status != Paused) { *m_shouldStopCond = 0; m_shouldStopCond->restore(); m_watchThread.launch(); } m_status = Playing; } }