QtAV
QtAV copied to clipboard
Exported video has no sound!
QtAV, Qt 5.15.0 and macOS
How can I create audio encoder? my exported video file has no sound!
Log file
Registered audio backends: ("AudioToolbox", "OpenAL", "null")
"avfmtctx.flags: 2097153, iformat.flags"
"invalid index 0 (valid is 0~0) for stream type 2."
"notify_interval: 33"
"stream: 1, duration=470694 (10673 ms), time_base=0.000023"
"codec: aac()"
"stream: 0, duration=6405 (10675 ms), time_base=0.001667"
"codec: h264()"
"has audio"
"QtAV::AudioDecoderFFmpeg thread type: Single, count: 1"
"AudioQueue is not created. skip close"
AudioOutput format: QtAV::AudioFormat(44100Hz, 4Bytes, channelCount:1, channelLayout: "mono", sampleFormat: "flt") ; requested: QtAV::AudioFormat(44100Hz, 4Bytes, channelCount:1, channelLayout: "mono", sampleFormat: "fltp")
"src audio parameters 'channel layout(or channels), sample rate and sample format must be set before initialize resampler"
"new audio thread"
"demux thread setAudioThread"
"output not changed: 0x7f8277d1b900"
"set AVThread output"
"stream: 1, duration=470694 (10673 ms), time_base=0.000023"
"codec: aac()"
"**********trying video decoder: FFmpeg..."
"QtAV::VideoDecoderFFmpeg thread type: Frame, count: 5"
"**************Video decoder found:0x7f8277e0fec0"
"setCapture 0x7f8277f33930"
"stream: 0, duration=6405 (10675 ms), time_base=0.001667"
"codec: h264()"
"auto select clock: audio > external"
"Using AudioClock"
"Clock initial value: 0.000000"
"Starting audio thread..."
"Starting video thread..."
"get av queue a/v thread = 0x7f8277dce6a0 0x7f8277e5a4a0"
"onSourceStarted framerate: 0.000/29.977"
"no frame could be decompressed: Error number 386338 occurred 0/386338"
"invalid video frame from decoder. undecoded data size: 0"
"swr speed=1.00"
"out: {cl: 4, fmt: flt, freq: 44100}"
"in {cl: 4, fmt: fltp, freq: 44100}"
"use first supported sample rate: 96000"
"use first supported sample format: 8"
"channel layout and supported channel layout are not set. use stereo"
QtAV::AudioFormat(96000Hz, 4Bytes, channelCount:2, channelLayout: "stereo", sampleFormat: "fltp")
"no frame could be decompressed: Error number 174630 occurred 0/174630"
"invalid video frame from decoder. undecoded data size: 0"
"no frame could be decompressed: Error number 118810 occurred 0/118810"
"invalid video frame from decoder. undecoded data size: 0"
"no frame could be decompressed: Error number 82397 occurred 0/82397"
"invalid video frame from decoder. undecoded data size: 0"
"use first supported sw pixel format '23' for hw encoder"
"size: 1920x1080 tbc: 0.033359=427/12800"
"OpenGL version: 2.1 hasGLSL: 1"
"GL_VERSION: 2.1 INTEL-14.7.8"
"GL_VENDOR: Intel Inc."
"GL_RENDERER: Intel(R) Iris(TM) Graphics 6100"
"GL_SHADING_LANGUAGE_VERSION: 1.20"
"Is OpenGLES: 0"
"Is EGL: 0"
"GLSL version: 120"
"Has PBO: 1"
"16 bit texture depth: 16.\n"
"using gl_param_3r16"
"Has 16bit texture: 1"
"check gl3 rg: 0x822B"
"Has RG texture: 1"
QSurfaceFormat(version 2.1, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize -1, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile QSurfaceFormat::NoProfile)
"AVClock started!!!!!!!!"
force format: "mov"
[FFmpeg:mov] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[FFmpeg:mov] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[FFmpeg:mov] track 1: codec frame size is not set
force format: "mov"
"swr speed=1.00"
"out: {cl: 3, fmt: fltp, freq: 96000}"
"in {cl: 4, fmt: fltp, freq: 44100}"
[FFmpeg:mov] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[FFmpeg:mov] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[FFmpeg:mov] track 1: codec frame size is not set
"swr speed=1.00"
"out: {cl: 4, fmt: flt, freq: 44100}"
"in {cl: 4, fmt: fltp, freq: 44100}"
13:53:58: The program has unexpectedly finished.
This is my code:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtAV>
#include <QtAVWidgets>
#include <QtAV/AVTranscoder.h>
#include <QtAV/VideoEncoder.h>
#include <QtAV/AudioEncoder.h>
#include <QtDebug>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
// QtAV::Widgets::registerRenderers();
QtAV::setLogLevel(QtAV::LogLevel::LogAll);
QtAV::AVPlayer player;
QtAV::LibAVFilter *mVideoFilter;
const QString cv = QString::fromLatin1("h264");
const QString ca = QString::fromLatin1("aac");
QString outFile = QString::fromLatin1("out.MOV");
mVideoFilter = new QtAV::LibAVFilterVideo(&player);
//mVideoFilter->setOptions("scale=320:240");
QtAV::AVTranscoder avt;
player.setFile("input.MOV");
// player.setFrameRate(10000.0);
// player.audio()->setBackends(QStringList() << QString::fromLatin1("null"));
avt.setMediaSource(&player);
avt.setOutputFormat("mov");
avt.setOutputMedia(outFile);
if (!avt.createVideoEncoder()) {
qWarning("Failed to create video encoder");
return 1;
}
QtAV::VideoEncoder *venc = avt.videoEncoder();
venc->setCodecName(cv);
venc->setBitRate(1024 * 1024);
if(!avt.createAudioEncoder()){
qWarning("Failed to create audio encoder");
return 1;
}
QtAV::AudioEncoder *aenc = avt.audioEncoder();
aenc->setCodecName("aac");
QObject::connect(&avt, SIGNAL(stopped()), qApp, SLOT(quit()));
avt.setAsync(true);
avt.start();
player.play();
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
``
Any idea? :-)
Your code here
QtAV::AudioEncoder *aenc = avt.audioEncoder();
aenc->setCodecName("aac");
aenc
will return null. So you can add a few of code like this:
if (!avt.createAudioEncoder()) {
qWarning("Failed to create audio encoder");
return 1;
}
AudioEncoder *aenc = avt.audioEncoder();
aenc->setCodecName(ca);
BUT There will be another problem if you build with the latest ffmpeg for using the deprecated api in the file AudioEncoderFFmpeg.cpp
line number is 207.
int ret = avcodec_encode_audio2(d.avctx, &pkt, f, &got_packet);