Check if a audio format of a given file is supported in Qt6 - qt

There have been many changes in QtMultimedia between Qt5 and Qt6.
With QMediaFormat::supportedAudioCodecs, we get a list of QMediaFormat::AudioCodec supported by the system.
Now we should get the QMediaFormat::AudioCodec that is used by a given file.
For that, it seems possible to use QMediaPlayer::metaData but unfortunately, on all the files I tested, the metadata does not contain QMediaFormat::AudioCodec or I don't know how to retrieve this value. In Qt5, it looks QMediaContent was suitable to get media information but it has been removed in Qt6.

Related

How to convert mbtiles to .osm.pbf

I'm writing a Qt application that is supposed to show a geo-map of a specific geographical region in one of its views on top of which I need to be able to draw various other graphical elements.
The requirements are that all the map-tiles must be pre-downloaded for off-line use as during the use of the application there will be no internet connection.
After lengthy search for a suitable library that I could link into my Qt project that would support my needs (off-line tile loading, rendering and painting the map in Qt framework, non-QML only C++ integration) I thought libOsmScout would do the job.
However, I have managed to download .mbtiles files for my region from OpenMapTiles just to realise that libOsmScout cannot natively work with .mbtiles.
The library can only work (indirectly after "import") with .osm.pbf files.
(http://libosmscout.sourceforge.net/tutorials/importing/)
I've searched extensively the web but all the results were pointing to conversion procedures in the opposite direction, i.e. into the .mbtiles.
So my question is: is it possible to convert .mbtiles files to .osm.pbf format so I can then import it into libOsmScout compatible internal set of files?
If it is possible, what the process?
Any help or guidance would be much appreciated.
Thanks.
Easiest way is to use ogr2ogr to convert to pbf format.
ogr2ogr -f MVT output_dir_name input.mbtiles -dsco MAXZOOM=2
This will create a directory structure with each zoom level having a directory and pbf file named according to the tile position.
Or
using this tool called MBUtil.
There are some steps which you can follow from the github repo.
After that, you can then use the following command to convert to directory structure with each tile in pbf format.
mb-util input.mbtiles output_dir_name image_format=pbf
where tiles is the directory name you want

How to query the containing partition of a file with KDE/Qt4?

I'm using KDE, and I'm toying with the idea of hacking the code for Dolphin File Manager (and potentially Konqueror if necessary) to get context-sensitive drag and drop behaviour (i.e. files are moved within the same partition, or copied if they're moved across partitions or the source is read only).
To do this, I think I'd need to find out the containing partition of the source and destination (easy enough on Windows using the drive letter, but on Linux, as mount points can be almost anywhere, it can't be reliably derived from the file path), and compare them.
Does anyone know how I can find out the partition that contains a given file?
It must be possible - I know Nautilus provides this sort of behaviour, but I'm not familiar enough with GTK to track down the appropriate section in the source code to see how its done...
Qt doesn't provide API for this. For POSIX, have a look at stat.
For KDE, you can use KIO::stat() to get mostly the same info as POSIX' stat function but asynchronously.
The device id should be in the field UDS_DEVICE_ID of the result.

Translate QT application without text in code

Is there a way to translate a QT app into different languages without defining the texts directly in the source? I want to separate the text from source. This would result in some kind of resource files for ALL languages, including the default language (e.g. English).
You won't be able to leave the English (or your source language, not necessarily English) source out of the XML (.ts) files as lupdate will put it there each time you run it. However as long as a translation exists for the chosen language, the source text will be ignored. If there is no translation text, it will default to the source text. This is useful since you'll be guaranteed to get some sort of text in your translation, but it'll be up to your test team to insure that the translations exist. I wrote a python script to automate the checking of the translation files since we have 9 languages and nearly 1k strings per translation. To test for this, we used a very simple sed script to create pseudo-loc source strings so if there were translations missing, the pseudo-loc text would be very evident.
Regarding the process for editing the .ts files, we farmed out the translations to individual translators, providing them with the .ts file for their language, and usually about an hour's worth of hand's on instruction in using QT Linguist. If the translator was onsite and wanted to see their translations on our device immediately, I wrote an autorun script that would place the resultant .qm file in the right place in our embedded file system and restart the application to display the new translations. If they weren't onsite, we'd run them through the python script mentioned above to check for a number of different problems, then simply check in the .ts file so it'd get built the next time around.
HTH
You might be able to use the QT_TRANSLATE_NOOP family of macros to do what you want. Those simply mark some text as "need to be translated" so that lupdate picks it up, but you can refer to those translated values by variable constants in your code. So ...
const char *kHelloWorld = QT_TRANSLATE_NOOP("SomeScope", "Hello world");
Later...
return qApp->translate("SomeScope", kHelloWorld);
This is still in your source code somewhere, but it is at least one step removed. You could theoretically have the QT_TRANSLATE_NOOP stuff in an entirely different Qt project, but then you'd need some way in your real project to know what you are supposed to translate. (You still need the char* constants somewhere.)
What are you trying to accomplish exactly by not having the English text in the source? That might help people provide more appropriate answers.
EDIT
Based on your comment below about intended usage
OK, then this is precisely what the normal Qt translation process does. Running lupdate creates those XML files (they have a .ts extension). They can be opened by translators in the very-easy-to-use Qt Linguist. They are translated, then sent back to you (the programmer), where you run lrelease on them to create the binary translation files you will ship with the app. The translations are resolved at runtime, so there is no need to recompile.
If you wanted to enable a user to do this, you would:
Ship your application with an empty (untranslated) .ts file and the lrelease program.
Provide instructions on how to use Qt Linguist to translate. (They could use a text editor and modify the Xml directly, but it's a lot easier with Linguist.)
Explain how to run lrelease and where to drop the binary translation files so that your application pulls them in.
On this last step, you could theoretically provide a nice wizard-like app that hides the implementation details.
What we will do is:
* Include a translation for the former default language. Using this *.ts file to auto-generate the other *.ts files. This is required as we keep the translations outside the QT environment as they match with other projects not related to QT.
Then have only have to make sure this translation contains the correct value.
In the future we can define IDs in the code witch represent Text in the default translation. Like translating TXT_ID_ABOUT to "About".

Is it possible to use Qt's built-in libpng library directly?

I'm saving a QImage to a PNG file and QPNGHandler isn't customizable enough (I need png_set_filter) so I need to write my own PNG handler. If Qt was configured without -system-libpng, is it possible for me to directly access Qt's bundled version?
Right now I'm statically compiling Qt, but that could change.
Yes, I suppose it should be possible. I see the symbols are inside libQtGui.so:
arm-none-linux-gnueabi-nm libQtGui.so.4.7.2 | grep png_create_read_struct
0027b7c0 T png_create_read_struct
0027b3b4 T png_create_read_struct_2
I see it includes all the sources inside libQtGui.so from src/gui/image/qpnghandler.pri unless system-png is specified in configure. I guess you'll have to manually get the headers ad specify in your .pro file cause I don't think Qt is exporting those when installing.

How to create a graph in order to parse an mp4 file to get the duration?

I am trying to find duration of an mp4 file using direct show component of windows using the Dotnet wrapper(directShow-lib 2005). But the method i used was GetDuration of IMediaSeeking interface. But this returns zero as duration.
After searching i found the following statement:
"It doesn't matter whether it's in a container or not, it
only matters whether you have a parser/reader for it. There
is no stock DirectShow parser to read raw H.264 files and no
third-party one I can think of. Also, whether IMediaSeeking
would work with such a raw file is implementation-dependent.
Last, most H.264-related filters use MPEG2Video or
VideoInfo2 and neither works with MediaDet, so you would
have to build the graph yourself."
Any body please help me to do this in c#.net?
You'll need to either find or make an MP4 file source filter to make this work. You can build one with mp4v2 or follow the instructions here.

Resources