QtAV
QtAV copied to clipboard
Scale video size using AVTranscoder
QtAV, 5.14.1 and macOS
Hi, How can I resize a video file using scale method and export it? Considering that QtAV is based on FFMPEG, So I want to do something like this:
ffmpeg -i input.avi -vf scale="iw/1:ih/2" output.avi
Please show me a method with QtAV, because there is no any document for this case.
https://github.com/wang-bin/QtAV/blob/master/src/QtAV/LibAVFilter.h#L55
https://github.com/wang-bin/QtAV/blob/master/src/QtAV/LibAVFilter.h#L55
Thank you for your answer. But I have a problem with result of file! because the output file is corrupted.
This is sample code inside Qt Project:
QtAV::Widgets::registerRenderers();
QtAV::setLogLevel(QtAV::LogLevel::LogAll);
QGuiApplication app(argc, argv);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QtAV::AVPlayer player;
QtAV::LibAVFilter *mVideoFilter;
const QString cv = QString::fromLatin1("mpeg4");
QString outFile = QString::fromLatin1("input.mp4");
mVideoFilter = new QtAV::LibAVFilterVideo(&player);
mVideoFilter->setOptions("scale=320:240");
QtAV::AVTranscoder avt;
player.setFile("output.mp4");
player.setFrameRate(10000.0);
player.audio()->setBackends(QStringList() << QString::fromLatin1("null"));
avt.setMediaSource(&player);
avt.setOutputFormat("mp4");
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);
QObject::connect(&avt, SIGNAL(stopped()), qApp, SLOT(quit()));
avt.setAsync(true);
avt.start();
player.play();
Log file
QtAV 1.13.0(Mar 4 2020, 20:07:12)
Multimedia framework base on Qt and FFmpeg.
Distributed under the terms of LGPLv2.1 or later.
Shanghai, China Copyright (C) 2012-2019 Wang Bin (aka. Lucas Wang) [email protected]
Donate: http://qtav.org/donate.html
Source: https://github.com/wang-bin/QtAV
Home page: http://qtav.org
"Build with Qt-5.14.0"
"FFmpeg/Libav configuration: --extra-version=QtAV --disable-doc --disable-debug --enable-shared --enable-runtime-cpudetect --enable-avresample --disable-postproc --install_name_dir='@rpath' --cc=clang --sysroot=/Applications/Xcode_11.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk --enable-pic --extra-cflags='-mmacosx-version-min=10.7' --extra-ldflags='-mmacosx-version-min=10.7 -Wl,-dead_strip -Wl,-rpath,@loader_path -Wl,-rpath,@loader_path/../Frameworks -Wl,-rpath,@loader_path/lib -Wl,-rpath,@loader_path/../lib'"
"Build with avutil-56.38.100"
"Build with avcodec-58.66.100"
"Build with avformat-58.35.104"
"Build with avfilter-7.71.100"
"Build with avdevice-58.9.103"
"Build with avresample-4.0.0"
"Build with swresample-3.6.100"
"Build with swscale-5.6.100"
Registered audio backends: ("AudioToolbox", "OpenAL", "null")
"AudioQueue is not created. skip close"
"framerate: -1.000/0.000"
Loading QVariant(QString, "input.mp4") ...
"all closed and reseted"
"avformat_open_input: d->format_ctx:'0x7fb62d803800', url:'input.mp4'..."
[FFmpeg:mov,mp4,m4a,3gp,3g2,mj2] unsupported color_parameter_type prof
"avformat_open_input: url:'input.mp4' ret:0"
"avfmtctx.flags: 2097153, iformat.flags"
"invalid index 0 (valid is 0~0) for stream type 2."
"notify_interval: 250"
"stream: 1, duration=2155020 (48866 ms), time_base=0.000023"
"codec: aac(AAC (Advanced Audio Coding))"
"stream: 0, duration=29320 (48866 ms), time_base=0.001667"
"codec: h264(H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)"
Registered audio backends: ("AudioToolbox", "OpenAL", "null")
Registered audio backends: ("AudioToolbox", "OpenAL", "null")
"has audio"
"QtAV::AudioDecoderFFmpeg thread type: Single, count: 1"
AudioOutput format: QtAV::AudioFormat(44100Hz, 4Bytes, channelCount:2, channelLayout: "stereo", sampleFormat: "flt") ; requested: QtAV::AudioFormat(44100Hz, 4Bytes, channelCount:2, channelLayout: "stereo", 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: 0x7fb62bc2d710"
"set AVThread output"
"stream: 1, duration=2155020 (48866 ms), time_base=0.000023"
"codec: aac(AAC (Advanced Audio Coding))"
"**********trying video decoder: FFmpeg..."
"QtAV::VideoDecoderFFmpeg thread type: Frame, count: 5"
"**************Video decoder found:0x7fb62be181a0"
"setCapture 0x7fb62bc64e70"
"stream: 0, duration=29320 (48866 ms), time_base=0.001667"
"codec: h264(H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)"
"auto select clock: audio > external"
"Using AudioClock"
"Clock initial value: 0.000000"
"Starting audio thread..."
"Starting video thread..."
"get av queue a/v thread = 0x7fb62be1cd20 0x7fb62bea1720"
"onSourceStarted framerate: 0.000/30.000"
"no frame could be decompressed: Error number 12715 occurred 0/12715"
"invalid video frame from decoder. undecoded data size: 0"
"[AudioDecoder] got_frame_ptr=false. decoded: 6, un: 0 Error number 6 occurred"
ao.format QtAV::AudioFormat(44100Hz, 4Bytes, channelCount:2, channelLayout: "stereo", sampleFormat: "flt")
swr.format QtAV::AudioFormat(44100Hz, 4Bytes, channelCount:2, channelLayout: "stereo", sampleFormat: "flt")
"decoder set speed: 333.33"
"src audio parameters 'channel layout(or channels), sample rate and sample format must be set before initialize resampler"
"(repeat 1)src audio parameters 'channel layout(or channels), sample rate and sample format must be set before initialize resampler\n[AudioDecoder] got_frame_ptr=false. decoded: 224, un: 0 Error number 224 occurred"
"swr speed=333.33"
"out: {cl: 3, fmt: flt, freq: 44100}"
"in {cl: 3, fmt: fltp, freq: 44100}"
"no frame could be decompressed: Error number 3518 occurred 0/3518"
"invalid video frame from decoder. undecoded data size: 0"
"no frame could be decompressed: Error number 581 occurred 0/581"
"invalid video frame from decoder. undecoded data size: 0"
"no frame could be decompressed: Error number 1203 occurred 0/1203"
"invalid video frame from decoder. undecoded data size: 0"
"no frame could be decompressed: Error number 425 occurred 0/425"
"invalid video frame from decoder. undecoded data size: 0"
"use first supported pixel format '0' for sw encoder"
"size: 560x1080 tbc: 0.033333=1/30"
"OpenGL version: 2.1 hasGLSL: 1"
"GL_VERSION: 2.1 INTEL-14.4.23"
"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: "mp4"
[FFmpeg:mp4] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
"End of file. erreof=1 feof=0"
"audio thread gets an eof packet. pkt.pts: -1.000, d.render_pts0:-1.000"
"[AudioDecoder] got_frame_ptr=false. decoded: 0, un: 3 Undefined error: 0"
"Decode audio failed. undecoded: 3"
"audio decode eof done"
...
...
encoded frames: 268, @8.933 pos: -1
"video thread gets an eof packet."
"(repeat 5)video thread gets an eof packet.\nno frame could be decompressed: Undefined error: 0 3/3"
"video decode eof done. d.render_pts0: -1.000"
"Invalid packet! flush video codec context!!!!!!!!!! video packet queue size: 0"
encoded frames: 269, @8.967 pos: -1
encoded frames: 270, @9.000 pos: -1
"(repeat 1757)Invalid packet! flush video codec context!!!!!!!!!! video packet queue size: 0\nwaiting audio thread......."
"audio thread gets an eof packet. pkt.pts: -1.000, d.render_pts0:-1.000"
"[AudioDecoder] got_frame_ptr=false. decoded: 0, un: 3 Undefined error: 0"
"Decode audio failed. undecoded: 3"
"audio decode eof done"
"Audio thread stops running..."
"waiting video thread......."
"video thread gets an eof packet."
"no frame could be decompressed: Undefined error: 0 3/3"
"video decode eof done. d.render_pts0: -1.000"
"Video thread stops running..."
"Demux thread stops running...."
"demuxer thread emit finished. repeat: 0/0"
"avplayer emit stopped()"
"Can not copy codec properties when it's open"
"About finish video encoding"
"Can not copy codec properties when it's open"
"closing d->format_ctx"
....
....
encoded frames: 1466, @48.867 pos: -1
....
....
"no packet got"
"AVTranscoder stopped"
"Not playing~"
"(repeat 2)Not playing~\n~~~~~~~~~resetGL 0x7fb62bd6d730. from sender 0x7fb62bfa7b50"
"Not playing~"
"AudioQueue is not created. skip close"
"(repeat 1)AudioQueue is not created. skip close\nNot playing~"
"AudioQueue is not created. skip close"
"(repeat 1)AudioQueue is not created. skip close\nNot playing~"
"~AVThreadPrivate wake up paused thread"