bool KaraokeVideoBackground::Start( const CStdString& filename ) { if ( !filename.empty() ) { if ( !openVideoFile( filename ) ) return false; m_timeFromPrevSong = 0; } else { if ( !openVideoFile( g_advancedSettings.m_karaokeDefaultBackgroundFilePath ) ) return false; if ( m_timeFromPrevSong != 0.0 && !m_decoder->seek( m_timeFromPrevSong ) ) m_timeFromPrevSong = 0; } // Allocate the texture m_texture = new CTexture( m_videoWidth, m_videoHeight, XB_FMT_A8R8G8B8 ); if ( !m_texture ) { CLog::Log( LOGERROR, "Karaoke Video Background: Could not allocate texture" ); return false; } m_nextFrameTime = 0.0; return true; }
bool JokerWindow::openDocument(const QString &fileName) { QFileInfo info(fileName); if(_settings->videoFileType().contains(info.suffix().toLower())) { #ifdef USE_VIDEO return openVideoFile(fileName); #else return false; #endif } /// Clear the selected people name list (except for the first document). if(!_firstDoc) _settings->setSelectedPeopleNameList(QStringList()); else _firstDoc = false; if(!_doc->openStripFile(fileName)) return false; /// If the document is opened successfully : /// - Update the current document name (settings, windows title) PhEditableDocumentWindow::openDocument(fileName); _watcher.addPath(_doc->filePath()); #ifdef USE_VIDEO /// - Load the deinterlace settings on_actionDeinterlace_video_triggered(_doc->videoDeinterlace()); /// - Open the corresponding video file if it exists. if(openVideoFile(_doc->videoFilePath())) { _videoEngine.setTimeIn(_doc->videoTimeIn()); _mediaPanel.setTimeIn(_doc->videoTimeIn()); } else _videoEngine.close(); #endif /// - Set the video aspect ratio. ui->actionForce_16_9_ratio->setChecked(_doc->forceRatio169()); /// - Goto to the document last position. setCurrentTime(_doc->lastTime()); /// - Disable the need to save flag. return true; }
/* //////////////////////////////////////////////////////////////////////////// * Open ttmpeg2 project: open video file * anaylize the stream * enable navigation */ void TTMpeg2MainWnd::openProject(QString fileName) { if (!openVideoFile(fileName)) { // TODO: throw exception return; } videoFileInfo->setFileName(fileName); onAnalyze(); isProjectOpen = true; enableControls(true); }
/* //////////////////////////////////////////////////////////////////////////// * Load an existing video file */ void TTMpeg2MainWnd::onLoadVideoFile(QString fn) { closeProject(); openProject(fn); if (!openVideoFile(fn)) { //TODO: throw exception return; } videoFileInfo->setFileName(fn); isProjectOpen = true; onAnalyze(); }
void JokerWindow::on_actionOpen_Video_triggered() { hideMediaPanel(); QString lastFolder = _settings->lastVideoFolder(); QString filter = tr("Movie files") + " ("; foreach(QString type, _settings->videoFileType()) filter += "*." + type + " "; filter += ");;"; QFileDialog dlg(this, tr("Open a video..."), lastFolder, filter); if(dlg.exec()) { QString videoFile = dlg.selectedFiles()[0]; if(openVideoFile(videoFile)) _strip.clock()->setTime(_doc->videoTimeIn()); } fadeInMediaPanel(); }
bool JokerWindow::openDocument(QString fileName) { /// Clear the selected people name list (except for the first document). if(!_firstDoc) _settings->setSelectedPeopleNameList(QStringList()); else _firstDoc = false; if(!_doc->openStripFile(fileName)) return false; /// If the document is opened successfully : /// - Update the current document name (settings, windows title) setCurrentDocument(fileName); _watcher.addPath(_doc->filePath()); /// - Load the deinterlace settings _videoEngine.setDeinterlace(_doc->videoDeinterlace()); ui->actionDeinterlace_video->setChecked(_doc->videoDeinterlace()); /// - Open the corresponding video file if it exists. if(openVideoFile(_doc->videoFilePath())) { _videoEngine.setTimeIn(_doc->videoTimeIn()); _mediaPanel.setTimeIn(_doc->videoTimeIn()); } else _videoEngine.close(); /// - Set the video aspect ratio. ui->actionForce_16_9_ratio->setChecked(_doc->forceRatio169()); /// - Goto to the document last position. _strip.clock()->setTime(_doc->lastTime()); /// - Disable the need to save flag. return true; }
bool JokerWindow::eventFilter(QObject * sender, QEvent *event) { /// The event filter catch the following event: switch (event->type()) { case QEvent::FileOpen: /// - FileOpen : To process a file dragged on the application dock icon (MacOS) { #warning /// @todo move to PhDocumentWindow QString filePath = static_cast<QFileOpenEvent *>(event)->file(); QString fileType = filePath.split(".").last().toLower(); // As the plist file list all the supported format // if the file is not a strip file, it's a video file, we don't need any protection if(_settings->stripFileType().contains(fileType)) { if(checkSaveFile()) openDocument(filePath); } else if(_settings->videoFileType().contains(fileType)) openVideoFile(filePath); break; } case QEvent::ApplicationDeactivate: /// - ApplicationDeactivate : to hide the mediapanel hideMediaPanel(); break; case QEvent::MouseMove: /// - Mouse move show the media panel { fadeInMediaPanel(); // Check if it is near the video/strip border QMouseEvent * mouseEvent = (QMouseEvent*)event; if(_resizingStrip) { QApplication::setOverrideCursor(Qt::SizeVerCursor); if(mouseEvent->buttons() & Qt::LeftButton) _settings->setStripHeight(1.0 - ((float) mouseEvent->pos().y() /(float) this->height())); } else QApplication::setOverrideCursor(Qt::ArrowCursor); break; } case QEvent::DragEnter: /// - Accept and process a file drop on the window event->accept(); break; case QEvent::Drop: { #warning /// @todo move to PhDocumentWindow const QMimeData* mimeData = static_cast<QDropEvent *>(event)->mimeData(); // If there is one file (not more) we open it if (mimeData->urls().length() == 1) { QString filePath = mimeData->urls().first().toLocalFile(); QString fileType = filePath.split(".").last().toLower(); if(fileType == "detx" or fileType == "strip" or fileType == "joker") { if(checkSaveFile()) openDocument(filePath); } else if (fileType == "avi" or fileType == "mov") openVideoFile(filePath); } break; } case QEvent::MouseButtonDblClick: /// - Double mouse click toggle fullscreen mode _resizingStrip = false; if(sender == this) toggleFullScreen(); break; case QEvent::MouseButtonRelease: QApplication::setOverrideCursor(Qt::ArrowCursor); break; case QEvent::MouseButtonPress: { QMouseEvent *mouseEvent = (QMouseEvent*)event; if((sender == this) && (mouseEvent->buttons() & Qt::RightButton)) { /// - Right mouse click on the video open the video file dialog. if(mouseEvent->y() < this->height() * (1.0f - _settings->stripHeight())) on_actionOpen_Video_triggered(); else /// - Left mouse click on the strip open the strip file dialog. on_actionOpen_triggered(); return true; } float stripHeight = this->height() * _settings->stripHeight(); if((mouseEvent->pos().y() > (this->height() - stripHeight) - 10) && (mouseEvent->pos().y() < (this->height() - stripHeight) + 10)) { QApplication::setOverrideCursor(Qt::SizeVerCursor); _resizingStrip = true; } } default: break; } return PhDocumentWindow::eventFilter(sender, event); }
VideoPlayer::VideoPlayer(QString programPath, QWidget *parent) : QWidget(parent) ,programDir(programPath) ,WIDTH(600) ,HEIGHT(380) ,videoNameWidth(300) ,videoListWidth(200) ,hideButtonsTime(2000) ,forwardStep(5) ,retreatStep(5) ,volumnChangeStep(5) ,hideCursor(false) ,keepAwakeTimes(0) { //设置窗口无边框 this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint); this->installEventFilter(this); //初始化窗口位置、大小 QDesktopWidget desktop; setGeometry((desktop.width()-WIDTH)/2, (desktop.height()-HEIGHT)/2, WIDTH, HEIGHT); setObjectName("videoPlayer"); //背景label lab_background = new QLabel(this); lab_background->setGeometry(0, 0, WIDTH, HEIGHT); lab_background->setObjectName("lab_background"); // videoList = new VideoList(0, 25, videoListWidth, this->height()-50, false, this); // videoList->show(); //设置鼠标跟踪,响应鼠标移动事件 this->setMouseTracking(true); lab_background->setMouseTracking(true); // videoWidget = new VideoWidget; videoWidget->hide(); videoWidget->installEventFilter(this); videoWidget->setMouseTracking(true); //保持视频屏幕常亮 helpKeepAwake = new HelpKeepAwake; //布局 layout_top = new QGridLayout; layout_top->addWidget(lab_background, 0, 0, 1, 1); layout_top->addWidget(videoWidget, 0, 0, 1, 1); layout_top->setSpacing(0); layout_top->setMargin(0); this->setLayout(layout_top); // videoContral = new VideoContral(this); videoContral->setGeometry(this->x(), this->y(), this->width(), this->height()); tbn_openVideoFile = new QToolButton(this); tbn_openVideoFile->setText("放入视频"); tbn_openVideoFile->setGeometry((this->width()-126-32)/2+35, (this->height()-41)/2+95, 80, 30); tbn_openVideoFile->setObjectName("tbn_openVideoFile"); //初始化多媒体播放器 player = new QMediaPlayer(this); QMediaPlaylist *playlist = new QMediaPlaylist; QMediaPlaylist *playlistHistory = new QMediaPlaylist; playlist_list.append(playlistHistory); playlist_list.append(playlist); player->setVideoOutput(videoWidget); player->setPlaylist(playlist); player->setVolume(60); connect(tbn_openVideoFile,SIGNAL(clicked()), this, SLOT(openVideoFile())); connect(player, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged())); /* connect(this, SIGNAL(moveWindow(QPoint)), videoList, SLOT(toMoveWindow(QPoint)));*/ //设置样式表 setStyleSheet( "#videoPlayer{" // "border-radius: 3px;" "}" "#lab_background{" // "border-radius: 3px;" "border-image: url(:/Images/videoPlayerBg.png);" "}" "#tbn_openVideoFile{" "background: rgba(0, 0, 0, 30);" "color: rgba(200, 255, 255, 255);" "}" ); //创建定时器(1.5秒无鼠标动作按钮自动隐藏) timerHideWidgets = new QTimer(this); timerHideWidgets->start(hideButtonsTime); connect(timerHideWidgets, SIGNAL(timeout()), this, SLOT(hideWidgets_timeout())); //操作控制 connect(videoWidget, SIGNAL(clicked()), this, SLOT(videoPlayPause())); connect(videoWidget, SIGNAL(switchFullScreen()), this, SLOT(switchFullScreen())); // connect(videoWidget, SIGNAL(goForward()), this, SLOT(videoGoForward())); // connect(videoWidget, SIGNAL(retreat()), this, SLOT(videoRetreat())); connect(videoWidget, SIGNAL(playJump(int)), this, SLOT(videoPlayJump(int))); connect(videoWidget, SIGNAL(volumnAdd()), this, SLOT(volumnAdd())); connect(videoWidget, SIGNAL(volumnReduce()), this, SLOT(volumnReduce())); connect(videoContral, SIGNAL(isHideWidget(bool)), this, SLOT(isHideWidget(bool))); connect(videoContral, SIGNAL(playerStop()), player, SLOT(stop())); connect(videoContral, SIGNAL(playPause()), this, SLOT(videoPlayPause())); connect(videoContral, SIGNAL(playNext()), player->playlist(), SLOT(next())); connect(videoContral, SIGNAL(currentMediaEnd()), this, SLOT(currentMediaEnd())); // connect(videoContral, SIGNAL(goForward()), this, SLOT(videoGoForward())); // connect(videoContral, SIGNAL(retreat()), this, SLOT(videoRetreat())); connect(videoContral, SIGNAL(playJump(int)), this, SLOT(videoPlayJump(int))); connect(videoContral, SIGNAL(switchFullScreen()), this, SLOT(switchFullScreen())); connect(player, SIGNAL(durationChanged(qint64)), videoContral, SLOT(durationChanged(qint64))); connect(player, SIGNAL(durationChanged(qint64)), this, SLOT(setVideoTitle())); connect(player, SIGNAL(positionChanged(qint64)), videoContral, SLOT(positionChanged(qint64))); connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(playStateChanged(QMediaPlayer::State))); // connect(videoContral, SIGNAL(itemDoubleClicked(int, int)), this, SLOT(itemDoubleClicked(int, int))); // videoWidget->setFocus(); timerKeepAwake = new QTimer(this); connect(timerKeepAwake, SIGNAL(timeout()), this, SLOT(timeoutKeepAwake())); }
void MainWindow::createActions() { newAction = new QAction("&New",this); newAction->setIcon(QIcon(":/images/new.png")); newAction->setShortcut(tr("Ctrl+N")); newAction->setStatusTip("Create a new edit session"); connect(newAction,SIGNAL(triggered()), this,SLOT(newFile())); openFileAction = new QAction("&Open file",this); openFileAction->setIcon(QIcon(":/images/open.png")); openFileAction->setShortcut(tr("Ctrl+O")); openFileAction->setStatusTip("Open/load data from file"); connect(openFileAction,SIGNAL(triggered()), this,SLOT(openFile())); openVideoAction= new QAction("Open video image",this); openVideoAction->setIcon(QIcon(":/images/video-x-generic.svg")); //openVideoAction->setShortcut(tr("Ctrl+O+O")); //openVideoAction->setStatusTip("Open/load contexts data from file"); connect(openVideoAction,SIGNAL(triggered()), this,SLOT(openVideoFile())); saveProjectAction= new QAction("&Save project",this); saveProjectAction->setIcon(QIcon(":/images/save.png")); saveProjectAction->setShortcut(tr("Ctrl+P")); saveProjectAction->setStatusTip("Save data to project file"); connect(saveProjectAction,SIGNAL(triggered()), this,SLOT(saveProjectFile())); saveContextsAction = new QAction("Save contexts",this); saveContextsAction->setIcon(QIcon(":/images/insert-object.svg")); saveContextsAction->setShortcut(tr("Ctrl+S+C")); saveContextsAction->setStatusTip("Save contexts data to file"); connect(saveContextsAction,SIGNAL(triggered()), this,SLOT(saveContextsToFile())); saveRulesAction = new QAction("Save rules",this); saveRulesAction->setIcon(QIcon(":/images/insert-object.svg")); saveRulesAction->setShortcut(tr("Ctrl+S+C")); saveRulesAction->setStatusTip("Save rule data to file"); connect(saveRulesAction,SIGNAL(triggered()), this,SLOT(saveRulesToFile())); exitAction = new QAction("&Exit",this); exitAction->setIcon(QIcon(":/images/application-exit.svg")); exitAction->setShortcut(tr("Ctrl+Q")); exitAction->setStatusTip("Close application"); connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); aboutAction = new QAction("&About",this); aboutAction->setIcon(QIcon(":/images/find.png")); aboutAction->setShortcut(tr("Ctrl+A")); aboutAction->setStatusTip("About"); connect(aboutAction,SIGNAL(triggered()), this,SLOT(about())); newRuleAction = new QAction("&New rule",this); newRuleAction->setIcon(QIcon(":/images/rule.svg")); connect(newRuleAction,SIGNAL(triggered()), this,SLOT(newRule())); runVirtualFencingAction = new QAction("&Video",this); runVirtualFencingAction->setIcon(QIcon(":/images/arrow.png")); connect(runVirtualFencingAction,SIGNAL(triggered()), this,SLOT(runVirtualFencing())); addLineAction = new QAction("Add &Line",this); addLineAction->setIcon(QIcon(":/images/linepointer.png")); addLineAction->setShortcut(tr("Ctrl+L")); addLineAction->setStatusTip("Add line"); connect(addLineAction,SIGNAL(triggered()), this,SLOT(about())); }
int main(int argc, char *argv[]) { av_register_all(); AVFormatContext *pFormatCtx = NULL; openVideoFile(&pFormatCtx, argv[1]); av_dump_format(pFormatCtx, 0, argv[1], 0); AVCodecContext *pCodecCtx = NULL; AVCodec *pCodec = NULL; // Open codec openCodecAndCtx(pFormatCtx, &pCodecCtx, &pCodec); // Copy context /* pCodecCtx = avcodec_alloc_context3(pCodec); if (avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) { fprintf(stderr, "Counldn't copy codec context"); return -1; } */ AVFrame *pFrame = NULL; // Allocate video frame pFrame = av_frame_alloc(); // Allocate an AVFrame structure AVFrame *pFrameRGB = av_frame_alloc(); if (pFrameRGB == NULL) return -1; uint8_t *buffer = NULL; int numBytes; // Determine required buffer size and allocate buffer numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); buffer = (uint8_t *)av_malloc(numBytes * sizeof(uint8_t)); avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); struct SwsContext *sws_ctx = NULL; int frameFinished; AVPacket packet; sws_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL ); int i = 0; while (av_read_frame(pFormatCtx, &packet) >= 0) { if (packet.stream_index == videoStream) { avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); if (frameFinished) { sws_scale(sws_ctx, (uint8_t const * const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize); } ++i; if (i <= 240 && i >= 230) { SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i); } } } av_free_packet(&packet); av_free(buffer); av_free(pFrameRGB); av_free(pFrame); avcodec_close(pCodecCtx); avformat_close_input(&pFormatCtx); return 0; }