Record video with Overlay
-
Hi,
I want to record Video with Overlay.
I have created QGrphicsView and added QGraphicsScene contaning QGraphicsVideoItem(Video) and QGraphicsTextItem(Overlay Text).
When I record video with "QMediaRecorder" It records only video data not overlay text.I am able to CaptureImage with "Overlay Text" using below code but unable to capture video.
QPixmap pixMap = graphicsView->grab(graphicsView->sceneRect().toRect());
pixMap.save(fileName);I am testing the code with Linux PC and webcam.
Let me know the ways to record video with overlay.Thanks,
Nikita -
Hi,
What exactly is on that overlay ?
-
Hi,
Thanks for your time.
An overlay is just like text which contains current date-time, location etc. -
I know what an overlay is. My question was: what are you putting on said overlay ?
Depending on that and how you put your overlay on top of your video, it might be more or less complex to record it.
-
Hi,
Thank you for your support. I have added QGraphicsVideoItem and QGraphicsTextItem in QGrahicsScene to generate overlay text.
Actually, I am new to QT Multimedia. Please go through below code, and if it is not a proper way then let me know another way.
void MainWindow::Init()
{videoItem = new QGraphicsVideoItem(); //Video Item scene = new QGraphicsScene(this); scene->addItem(videoItem); text = scene->addText("Hello World"); //Overlay Text graphicsView = new QGraphicsView(scene); pCamera->setViewfinder(videoItem); pCameraImageCapture = new QCameraImageCapture(pCamera, this); CamRecordInit(); pCamera->start();
}
//Init QMediaRecorder
void MainWindow::CamRecordInit()
{pMediaRecorder = new QMediaRecorder(pCamera); updateRecorderState(pMediaRecorder->state()); connect(pMediaRecorder, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(updateRecorderState(QMediaRecorder::State)));
}
//Start video recording
void MainWindow::StartCamRecord()
{if (pCamera->isCaptureModeSupported(QCamera::CaptureVideo)) pCamera->setCaptureMode(QCamera::CaptureVideo); pMediaRecorder->setOutputLocation(QUrl::fromLocalFile("/home/user/sample")); pMediaRecorder->record(); //This records only live video without Overlay
}
//Capture Image
void MainWindow::CaptureImage()
{static int count = 0; QString fileName = DATA_STORE_LOCATION"ImageCaptured_" + QString::number(count) + ".png"; QPixmap pixMap = graphicsView->grab(graphicsView->sceneRect().toRect()); pixMap.save(fileName); count++;
}
Thanks
-
That's because the recorder acts on the camera itself. It doesn't care about whatever you put on top of the preview content.
One way would be to modify the gstreamer backend so it produces the overlay you want on top of your video.
-
Hi,
Thanks for the answer. I searched but didn't get the idea to modify gstreamer backend.
Let me know the method or some reference link/site to modify gstreamer backend to perform overlay.Thanks!
-
Did you first check whether GStreamer capabilities fill your need in term of overlay ?
-
Yes facing same issue here...Hopefully will find an appropriate answer from here..As no proper source on google regarding gstreamer backend is available.Thanks MySchoolBucks
-
@SGaist
Hi Gaist,Thank you for your time.
I have checked capabilities of Gstreamer to record video with overlay text using below gstreamer command:
gst-launch-1.0 -e v4l2src ! textoverlay text="Name" valignment=top halignment=left font-desc="Sans, 24" ! queue ! x264enc ! h264parse ! queue ! qtmux ! filesink location=testVideoI have tried below methods with QT but didn't work out:
-
Create Object of "QGstreamerVideoOverlay", but it gives declaration error.
-
Do Gstreamer modification with below code, but didn't know how to set overlay text. It gives only live video in "grahicsview".
*gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY("autovideosink"),graphicsView->viewport()->effectiveWinId());
GstMessage msg = new GstMessage();
gst_is_video_overlay_prepare_window_handle_message(msg);
Thanks,
Nikita -
-
I was rather thinking about the textoverlay plugin of GStreamer.
-
use QAbstractVideoFilter for overlaying and recording
-
I was rather thinking about the textoverlay plugin of GStreamer.
@SGaist
I didn't know how to integrate "textoverlay plugin" with QMediaRecorder.It would be great if you can provide a reference document or link to use it.
Thanks,
Nikita -
use QAbstractVideoFilter for overlaying and recording
@vladstelmahovsky
Let me know how to use "QAbstractVideoFilter" to write text and use it with QMediaRecorder.It would be great if you can provide a reference document or link to use it.
Thanks,
Nikita -
@vladstelmahovsky
Let me know how to use "QAbstractVideoFilter" to write text and use it with QMediaRecorder.It would be great if you can provide a reference document or link to use it.
Thanks,
Nikita@nikita.panchal09
you can read https://blog.qt.io/blog/2015/03/20/introducing-video-filters-in-qt-multimedia/
to get an idea about how to handle frames
each frame can be converted to QImage and each QImage can be used to draw text on it and provided to media recorder