How to render custom video data in Qt ? - qt

I have never done a Qt video application - newbie in this area. I have a custom video file format to render using Qt. The video file format is 256-byte header, then pixel data, then 256-byte header, then pixel data and so on.
The header consist info like width, height in pixels, bytes per pixels, frame rate etc and the pixel data is in Bayer (GBRG). I may have to process data before display - like convert to RGB (not sure yet). I see there are lot of video related classes like QGL*, QMovie, QVideo* ... don't know where to start ? I have seen mandelbrotwidget example which looks like a good place to start but still need some advice. Also, do I have to write a Qt Image plugin for Bayer pattern?
Thank you.

Good advice is to do all by yourself. If you have simple data structure read it by simple C++-code.
Conversation from Bayer RGB to RGB like here you can also make without using any Qt objects.
And now, when you'll got trivial RGB-image (even in your own structure) per frame, you can show it on widgets such as QGL* -- if you prefer OpenGL rendering, or Qt's classes such as QPainter, QImage...
Some more links: C++ GUI Programming with Qt4, 2nd Edition, Graphics View Framework

The best place to start is by learning the basics of custom drawing in Qt. In short, a very simple implementation would require you to:
Create a custom QWidget subclass
Override the paintEvent() method
Use a QPainter/QImage to decode your raw video data into image data and draw it on screen
Qt has lots of good sample code to get you started, such as:
http://qt-project.org/doc/qt-4.8/examples-painting.html
Once you have a simple implementation up and running, and a basic grasp of Qt concepts/classes, then you'll be ready to profile, optimize, and make use of more advanced Qt functionality (GL, video) as needed.

Related

How to print a QQuickView's contents to PDF?

I'm upgrading some Qt (C++ & QML) code from Qt4.8 to Qt5.1.
The Qt4.8 code is a trivial C++ "QML viewer" app subclassing a QDeclarativeView, and a bunch of QML.
It's been easy enough to change this to use Qt5/QtQuick2's QQuickView except for one thing:
The Qt4.8 app has a method for printing to PDF:
void MyQMLViewer::printToPDF(const QString& filename) const {
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPageSize(QPrinter::A3);
printer.setOutputFileName(filename);
printer.setOrientation(QPrinter::Landscape);
QPainter painter(&printer);
render(&painter);
}
There were a few "environment" changes needed for Qt5.1 to get a QPrinter (ie add QT += printsupport to the project .pro file and #include <QtPrintSupport>), but there seems to be a more fundamental problem that QQuickView doesn't provide anything which is obviously compatible with the QGraphicsView/QPainter/QPaintDevice world of QPrinter (specifically, QQuickView has no render method, and all the drawing/painting/rendering-related methods it does have seem very tied up with OpenGL).
Any suggestions for how to best obtain high-quality PDF output from a QQuickView ?
(Note that I am not simply looking to screenshot the view; with QDeclarativeView, the code above generates PDFs with much better resolution even than the app fullscreened on my largest monitor).
I see the "QDeclarativeItem and QDeclarativeView" section of the "Porting QML Applications to Qt 5" guide does mention the loss of QGraphicsView-specific functionality, but doesn't offer any solutions (although it does mention workrounds for the case of items with custom QPainter-based rendering being bought into the new regime).
Update with some additional background info: an example of a PDF printed from QDeclarativeView using the above code can be found here. There's a png of the same view on a decent size monitor here. (This is actually the last slide in a series of slides; it's actually a gallery of the previous slides which bounces each slide onto the screen; if I had the time I'd look into the feasibility of the gallery being the only thing and transforming each scattered slide into view for a Prezi-style presentation; suspect QDeclarative isn't really performant enough though, which is one reason for wanting to get onto QtQuick2+Qt5.2's new scene graph stuff). Anyway, If you zoom the PDF up to 100% you'll see the text is... well it's better than anything a sanely sized image file will manage I think, although the sloping text baselines perhaps look a little uneven. There is also an issue with opacity values not being represented in the PDF (so the drop shadows and "bubbles" come out solid); another one of my motivations for trying for a QtQuick2 version was actually to see if translucent elements were dealt with any better. I assume the PDF just contains rasterized (or maybe vector outlines) of all the elements as utilities like "pdftotext" can't extract anything from it. I don't know enough about PDF tools to know how to inspect the internal structure of the thing but I assume there's some hierarchy there and the QML element tree is all laid out using a similar structure of nested transforms to the QML. Just for comparison and the sort of richness I'm potentially working towards here's a poster I did with LaTeX/Beamerposter; I find Beamerposter's rigid block structure rather limiting (and fiddly) compared with the possibilities QML seems to offer though. BTW, another thing on my wishlist/todolist is a QML element which can render LaTeX source, math and all, just to get the best of both worlds.
Update: Recent Qt blog post on all the backend changes in Qt5.8 has a comment linking to this Qt issue to use the new possibility of QPainter-rendered QtQuick scenes to render PDFs.
At the moment, there is no code in Qt that supports rendering of a scene graph to a pdf. The underlying data that is used to render Qt Quick 2 is held in the scene graph. As Laszlo suggests, you'd need to iterate the scene graph and generate PDF primitives. There's some impedance mismatch there, but it should be doable with some sweat. I think a proof of concept could be small enough to fit here, so I'll see how easy it could be :)
If you really want a PDF, you currently have no choice but to render it to a large image at 300dpi and wrap that in a PDF. The image doesn't have to be large if the poster has large areas of solid color. PDF can do do TIFF encoding and also JPEG encoding.

Custom real-time drawing in Qt5 and Qt Quick 2

I have been looking far and wide to find out how, if it’s possible, you can fill a particular area in a QML screen with an OpenGL context and do custom OpenGL only in that context. I’ve seen plenty of demos where the QML components like buttons, etc lay on top or below a screen-wide OpenGL context (as is typically required by games), but I’d like to be able to situate several distinct OpenGL contexts within QML and have the QML file define how large they are, where they are positioned, etc.
Now, since Qt 5 is all OpenGL under the hood, it makes me wonder if using a Canvas element with custom drawing via javascript could result in similar rendering performance as custom OpenGL? This would be a meaningful alternative but it’s not clear to me how the javascript drawing is handled via runtime compared to custom OpenGL drawing.
What is it that you want to draw? QQuickPaintedItem may be the simplest way to go about it. When you're using QOpenGLFramebufferObject as the target, the painter will use OpenGL to paint the texture. It might be easier than writing your own OpenGL code if all you're doing is 2D.

trying to make a bitmap editor in qt

I want to make a program using qt.
I have to make a bitmap editor for special purposes.
I had been looking widgets that could allow me to get this task done, one of them is QGraphicsView with QGraphicsScene.
As expected, I want my program to have many features.
They are listed below:
Exporting to image formats such as .bmp.
Support for clipboard, copy and paste. I hope this clipboard can be compatible with other similar programs.
The image must have a resolution. I mean the pixels of the screen can be bigger than the pixels of the image and vice-versa.
Selecting squared areas.
So, what I need to know is if I am using the correct widget. If not, which widget can I use? which are the member functions of the widget that I need to know?
There several ways to achieve what you want, but as your question is too broad, I would suggest looking at the Qt Scribble example and come back with specific questions relating to what it doesn't do.
The link suggested previously was replaced with a new one that points to the corresponding Qt 5 example.

QT - How to synchronize data between two widgets?

I have a QT program with a custom widget that I'm implementing. This widget is an Hexeditor, and it's already functional.
But now I want to put on the window another instance of the same Hexeditor, and I want to synchronize the data between them, so if I change a byte in one Hexeditor, the same byte is automatically changed on the other Hexeditor.
What is the best solution for this problem? What are my options? Sometimes the files can be very big, so I'm trying to find the best solution.
This is a general question, and probably is valid for other text widgets.
Thanks
I would use the very good MVC architecture widgets in Qt.
As a hexeditor is generally laid out as a table, I would use QAbstractTableModel to actually store the hex data, and then QTableView to display the data. You can then have an arbitrary mount of hex editors connected to the same model and all will be synchronised automatically. You will also have to modify a QStyledItemDelegate to provide hex-only editing in the view, but that's really straightforward.

Get information about pics and video files with qt

Well i have a project in which gets pics and videos from folders and also i can view them it it and when i view them i want to also see those tags kinda like the camera which took it, dimensions , the ISO, the exposure time and others for pics and camera model framerate and dimensions...
Thanks in advance
I've never seen anything like this in Qt. Anyway, Qt is a C++ framework, you can use whatever library you want to use. QImageMetaData and QMeta are very near Qt style, but can only be used for images (never tried those).
Anyway, I would use the XMP toolkit. You also mentioned videos, so in that case XMP can handle both. It is very simple to use, well documented and fast (license is BSD). It is written in C++, so you can port it on whatever platform you want.
I think Qt itself does not provide a way to extract exif data (which is what I guess you're trying to extract). You could perhaps try QMeta. I have not used this myself, so no guarantees.

Resources