Saving recording to MP3 container in Qt - qt

I am programming on the Windows 7 platform using Qt 4.8.4, Qt Mobility 1.2 and C++. I am attempting to record audio from the front jack and save it to a file in mp3 format. I have the program working with the LAME encoder, but the file is being saved as WAV.
It appears that I have no control over the container type, which is defaulting to PCM/WAV.
Here are the QAudioEncoderSettings I am using:
QAudioEncoderSettings settings;
settings.setCodec("audio/mpeg");
settings.setSampleRate(boxValue(ui->sampleRateBox).toInt());
settings.setBitRate(boxValue(ui->bitrateBox).toInt());
settings.setQuality(QtMultimediaKit::EncodingQuality(ui->qualitySlider->value()));
settings.setEncodingMode(ui->constantQualityRadioButton->isChecked() ?
QtMultimediaKit::ConstantQualityEncoding :
QtMultimediaKit::ConstantBitRateEncoding);
QString container = "audio/x-mp3";
capture->setEncodingSettings(settings, QVideoEncoderSettings(), container);
A post recording conversion is not an option, as the files may become quite large, and the probability that the process would be ended before the conversion was complete is quite high.
Thank you for any help provided.

You can try Qt Media Encoding Library for that - http://qt-project.org/forums/viewthread/29117/

Related

Output of Print Driver application, PCL

We have a legacy application written by a developer which takes a PDF/text file and converts it to a TIFF. The user just prints the file to a custom print driver.Output of the driver is a Printer control language file and finally TIFF.
The user doesn't see the PCL file. PCL file is internally produced and inputed as a binary reader which gets converted to a TIFF.
How do I see the PCL File?? I would really like to have a small stand-alone test program which converts a PDF to PCl using this print driver and then TIFF.
The print driver is written in C, C++ code.
This driver was written in 2010. With the new Adobe version 2018.009.20050, text in adobe forms is not being captured.
I'd appreciate some pointers!
I do not have an answer but I wish to comment and follow the topic.
Like the poster, I'm working with a few virtual print drivers and have noted this change of behavior from Adobe Reader 2018.009.20050 is impacting them. Examples: Foxit's PDF Printer, as well as an HP PostScript Driver I've been using whenever I need to redirect a printstream to a file.
The issue seems to be that the new release of Adobe Reader is no longer recognizing these PostScript printers as such. A tell-tale sign is that Adobe Reader, when printing, has 'Advanced' options that would typically let someone designate some PostScript options/preferences. With the recent Reader release, these options are now disabled for all of my PostScript-capable printers, except when using the "Adobe PDF Printer".
My guess: like many Windows applications, when Adobe Reader prints to a device that it thinks is NOT PostScript-capable, Reader will choose to rasterize the PDF's text into image/vector data, rather than expressing it as text-and-font information. ( ..and some applications, like Chrome, seem to always do this, nevermind the type of printer. )
I am hoping that Adobe sees a bug here to be fixed soon. It's creating quite a headache otherwise.
In the meantime, I've found that Foxit's most-recent PDF Reader does NOT have this same issue. It continues to create PostScript for my set of virtual printers.
UPDATE (1/2/18):
This is Adobe's support article describing a different issue but the same proposed registry change for avoiding text rasterization.

Generating a waveform from an audio (or video) file?

I'm trying to understand how I can generate a waveform from an audio (or video) file to display to the user.
I've been googling around for quite a while now and can't determine if this is even possible in Qt without using something like FFmpeg. I've seen all of these classes: QMediaPlayer, QMediaContent, QMediaResource, QAudioProbe and experimented with the Qt Media Player Example but am just not seeing where I can access the actual audio buffer.
So I have 2 questions:
Is what I want to do even possible without 3rd party libraries?
If it is possible, can some kind soul outline what I need to read and understand in order to access the audio data
I have tried the suggestions from this question (Audio visualization with QMediaPlayer) but the result of audioProbe->setSource(player) is always false and the method processBuffer never gets called.
audioProbe = new QAudioProbe(this);
bool success = audioProbe->setSource(player);
qDebug() << success;
connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer)));
Update: Adding some additional detail in the hope of clarifying things.
For testing/learning I am using the Media Player Example which ships with Qt, so it is set up correctly with Q_OBJECT etc.
For audio, I tested with both .mp3 and .wav files. FWIW, the player example won't play video for some reason (.mp4, .avi were tested)
The player in the code is QMediaPlayer – which inherits from QMediaObject. The example code for the Player class is here. I added my code (in original comment above) right after the player is instantiated. I also tried adding it once media is loaded.
I tried declaring my slot first as private, then as public – either way, it is never called.
Frustrating that such a simple thing is so hard.
Going the "no external library" route will likely just lead to more of a headache and more work than is necessary. The other advantage of going with an established library is you won't be bound to one file format, as not all formats store their data the same way. If the audio format is uncompressed (wav or other) you can read the header until you get to the data chunk. An answer to this question here details this in C. You should be able to get an idea for the file format from this to apply it to another language.
You will want to understand how many channels are in the wav file, bit depth, and also the sampling rate before you can do anything worthwhile with the data. All this info can be grabbed from the header.
It turns out that QAudioProbe is not supported on OSX – the platform I am working on. Took quite a while (a "Qt while. . .") to ferret that info out so I am posting it here explicitly.
See this document for full details: Qt 5.5.0 Multimedia Backends

QT5 QSound does not play all wave files

I am in the midst of migrating our app based on QT4.X to QT5. Phonon support has been removed in QT5, so I have changed my code that plays a wave file to use QSound.
Change is pretty straightforward. I just had to use QSound, which is now located in Multimedia library. Here is the code:
QSound::play("small_wave_file.wav");
For most of my wave files, this works just fine; however, for my wave file(with 44100Hz sample rate) it does not work.
Official QT bug can be found here.
UPDATE: This bug has been fixed in qt 5.1
It turns out that some wave files confuse QSound. Still not sure exactly what causes the issue. When I loaded my wave file in Audacity, and then exported it back to a different wave file without any changes(same sample rate...). QSound played the file just fine.
In MacOSX when I click "Get Info" on the problematic wave file, general wave info record from the wave file was not available; so perhaps QSound was unable to get sample rate information from; and because it did not know which sample rate to expect from the wave file?
The interesting part is that iTunes played the original file just fine, and it had the correct sample rate somehow. Also Phonon used to play the original file as well just fine.
Anyhow, hopefully this helps with some people that had issues with QSound::play() method.
UPDATE: Since QSound::play() was very buggy on the mac, I opted to use the native NSSound to play my wave files from QT application on the mac. Here is the code:
void play_sound( const char* file)
{
NSSound *sound = [[NSSound alloc] initWithContentsOfFile:[NSString stringWithUTF8String:file] byReference:NO];
[sound play];
[sound release];
}
Also note that Qt has several different sound playback APIs. For small file playback with lower latency I found this to be much faster:
http://doc.qt.io/qt-5/qsoundeffect.html#details
Also:
http://doc.qt.io/qt-5/qmediaplayer.html

Nokia Qt: Save Image In Phone Memory

I am making App. that includes Picture Editing, After Editing I want to save this Image As jpg file in my phone memory.. How can i do this?
Any help?
Thanks..
I don't have a Symbian device to check, but AFAIK it should be something like e.g.
QString filename = "c:\\folder\\filename.jpg";
bool success = mypixmap.save(filename);
assuming you have Symbian capabilities to write to the directory. The success will be true if the save was successful and false otherwise, and if necessary you can mess with the compression quality factor - here's the documentation.
I'm rusty on Symbian permissions, you might need WriteUserData to get this to work.

OpenCV with other GUI (like Qt or WxWidgets) on Win32 VC++

I want to use OpenCV's image processing functions, but not the OpenCV GUI. I'm using OpenCV 2.0. I will use either Qt4 or WxWidgets for GUI functions. I compile with VC++ 2008 Express (VC++ 9.0).
I guess it breaks down to two or three questions:
Is it necessary to do something to disable OpenCV's higui so it does not interfere with the preferred GUI library, and if so, how?
How to convert an OpenCV image into something (bitmap?) that the preferred GUI can display (and perhaps save)?
(Optional) How to convert an image that was loaded using the preferred interface into a form that OpenCV can use?
Okay. I've got the answer to my own question for WxWidgets. One key is not to fight openCV City Hall about RGB sequence. OpenCv really likes "BGR". WxWidgets uses "RGB" only. The opencv data structure has a field for byte sequence, but it is seldom honored. Even the highGui function (on MS Windows) that displays an image will put up spectacularly blue tangerines if the byte sequence is set to "RGB". I stubbornly fixed that bug in my local installation, but other operations failed also. So, I just sigh and set the byte order on the opencv side to "BGR" and do the byte swapping as necessary.
The C++ code below requires that the openCV images that it converts to wxImages are RGB, sequence "BGR", 8 bit depth and 3 interleaved channels, and have width_step = width*3. The routines don't check compatibility. Use at your own peril. A ready-for-primetime version would provide for regions of interest (ROI) and other fanciness.
#include "wx/wx.h"
#include "cv.h"
#include "highgui.h" // Optional
void copy_and_swap_rb(char *s, char *d, int size) {
// Copy image data source s to destination d, swapping R and B channels.
// Assumes 8 bit depth, 3 interleaved channels, and width_step = width*3
const int step = 3;
char *end = s + size;
while (s<end) {
d[0] = s[2];
d[1] = s[1];
d[2] = s[0];
d += step; s += step;
}
}
void wx2cv(wxImage &wx, IplImage *ipl) {
// Copy image data from wxWidgets image to Ipl (opencv) image
// Assumes ipl image has seq "GBR", depth 8, and 3 channels, and
// has the same size as the wxImage, and width_step = width*3.
copy_and_swap_rb((char*)wx.GetData(), ipl->imageData, ipl->imageSize);
}
void cv2wx(IplImage *ipl, wxImage &wx ) {
// Copy image data from Ipl (opencv) image to wxImage
// Assumes ipl image has seq "GBR", depth 8, and 3 channels, and
// has the same size as the wxImage, and width_step = width*3.
copy_and_swap_rb( ipl->imageData, (char*)wx.GetData(),
wx.GetWidth()*wx.GetHeight()*3);
}
IplImage *cv_from_wx(wxImage &wx) {
// Return a new IplImage copied from a wxImage.
// Must be freed by user with cvReleaseImage().
IplImage *ret = cvCreateImage(cvSize(wx.GetWidth(), wx.GetHeight()),
IPL_DEPTH_8U, 3);
wx2cv(wx, ret);
return ret;
}
wxImage wx_from_cv( IplImage *cx) {
// Return new wxImage copied from a compatible IplImage.
// Assumes ipl image has seq "GBR", depth 8, and 3 channels
// Fear not. The copy on return is cheap; does not deep-copy the data.
wxImage wx(cx->width, cx->height, (unsigned char*) malloc(cx->imageSize), false);
cv2wx(cx, wx);
return wx;
}
I know I'm super late to this discussion, but I just happened across it. Anyways, I've been using OpenCV and wxWidgets together quite happily for a few years now, so I thought I'd pitch in:
Is it necessary to do something to disable OpenCV's higui so it does not interfere with the preferred GUI library, and if so, how?
Not generally. There are a couple hiccups that you can run into for specific versions of OpenCV and Windows. For the most part, though, the integration is very smooth. I routinely use wx for my front end and the parts of highgui that enable image capture. I've done this on several versions of Windows, Ubuntu, and OS X.
How to convert an OpenCV image into something (bitmap?) that the preferred GUI can display (and perhaps save)?
An alternative to copying back and forth between a wxImage is stuffing the IplImage's data directly into an OpenGL texture and painting it on a wxGLCanvas. One big advantage for this strategy is that you can then draw on top of the texture using standard OpenGL methods.
(Optional) How to convert an image that was loaded using the preferred interface into a form that OpenCV can use?
Don't :) I use wxFileDialog etc to let the user specify paths, but all of the backend is directly OpenCV.
(begin self plug)
Code I've written to do a lot of this is part of a project called MADTraC, which is a GUI/application framework for real-time computer vision applications.
(end self plug)
Is it necessary to do something to disable OpenCV's higui so it does not interfere with the preferred GUI library, and if so, how?
Answer: I don't see why it should not be doable or it is a poorly designed library (which I don't think OpenCV is).
For your other questions (and the "How" of question 1), I did a quick search on QtCentre and found an interesting thread about OpenCV integration with Qt. There is some source code examples that you can look at.
If you don't find what your are looking for in that thread you can start a new one.
Or google for OpenCV integration in Qt or search on Google Code, there is some projects using both Qt and OpenCV (OpenCV Stereo Vision is one).
Good luck.
Well I don't know much about OpenCV, but I work with wxWidgets alot.
I highly recommend wxWidgets simply because of its intuitive structure and code layout.
Also, QT is only available under the LGPL on Windows, so licensing may be an issue. wxWidgets can be used in commercial projects without restrictions.
As for converting images back and forth, wxWidgets has a large number of classes/functions for working with images.
I have made a little progress. The GUI part of OpenCV does seem to stay out of the way. I have even used it in a WxWidgets application to show an image, and nothing bad seemed to happen. That was on a Windows XP box using VC++ 2008. The only interaction that OpenCV/highGUI appears to have with the windowing system is to make direct Windows API calls and to monitor the event queue for keyboard events, which it passes on.
I'm working on how to convert from OpenCV images to WxWidgets images and back. A big help you guys are. :-)

Resources