mirror of
https://github.com/wang-bin/QtAV.git
synced 2026-10-28 11:07:07 +08:00
enc: set pixel format support
This commit is contained in:
+1
-1
@@ -109,7 +109,7 @@ AVCodec* AVMuxer::Private::addStream(AVFormatContext* ctx, AVCodecID cid)
|
||||
c->bit_rate = venc->bitRate();
|
||||
c->width = venc->width();
|
||||
c->height = venc->height();
|
||||
c->pix_fmt = QTAV_PIX_FMT_C(YUV420P);
|
||||
c->pix_fmt = (AVPixelFormat)VideoFormat::pixelFormatToFFmpeg(venc->pixelFormat());
|
||||
// Using codec->time_base is deprecated, but needed for older lavf.
|
||||
c->time_base = s->time_base;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ class Q_AV_EXPORT VideoEncoder : public AVEncoder
|
||||
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
|
||||
Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
|
||||
Q_PROPERTY(qreal frameRate READ frameRate WRITE setFrameRate NOTIFY frameRateChanged)
|
||||
Q_PROPERTY(QtAV::VideoFormat::PixelFormat pixelFormat READ pixelFormat WRITE setPixelFormat NOTIFY pixelFormatChanged)
|
||||
Q_DISABLE_COPY(VideoEncoder)
|
||||
DPTR_DECLARE_PRIVATE(VideoEncoder)
|
||||
public:
|
||||
@@ -70,11 +71,18 @@ public:
|
||||
int height() const;
|
||||
void setFrameRate(qreal value);
|
||||
qreal frameRate() const;
|
||||
// pixel format...
|
||||
/*!
|
||||
* \brief setPixelFormat
|
||||
* set Format_Invalid (default) to auto
|
||||
* \param format
|
||||
*/
|
||||
void setPixelFormat(const VideoFormat::PixelFormat format);
|
||||
VideoFormat::PixelFormat pixelFormat() const;
|
||||
Q_SIGNALS:
|
||||
void widthChanged();
|
||||
void heightChanged();
|
||||
void frameRateChanged();
|
||||
void pixelFormatChanged();
|
||||
protected:
|
||||
VideoEncoder(VideoEncoderPrivate& d);
|
||||
private:
|
||||
|
||||
@@ -24,8 +24,14 @@
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include "QtAV/Packet.h"
|
||||
#include "QtAV/VideoFormat.h"
|
||||
#include "QtAV/private/AVCompat.h"
|
||||
|
||||
// FF_API_PIX_FMT
|
||||
#ifdef PixelFormat
|
||||
#undef PixelFormat
|
||||
#endif
|
||||
|
||||
namespace QtAV {
|
||||
|
||||
class Q_AV_PRIVATE_EXPORT AVEncoderPrivate : public DPtrPrivate<AVEncoder>
|
||||
@@ -81,12 +87,16 @@ public:
|
||||
, width(0)
|
||||
, height(0)
|
||||
, frame_rate(25.0)
|
||||
, format_used(VideoFormat::Format_Invalid)
|
||||
, format(format_used)
|
||||
{
|
||||
bit_rate = 400000;
|
||||
}
|
||||
virtual ~VideoEncoderPrivate() {}
|
||||
int width, height;
|
||||
qreal frame_rate;
|
||||
VideoFormat::PixelFormat format_used;
|
||||
VideoFormat format;
|
||||
};
|
||||
} //namespace QtAV
|
||||
#endif // QTAV_AVENCODER_P_H
|
||||
|
||||
@@ -89,7 +89,14 @@ bool VideoEncoderFFmpegPrivate::open()
|
||||
avctx = avcodec_alloc_context3(codec);
|
||||
avctx->width = width; // coded_width works, why?
|
||||
avctx->height = height;
|
||||
avctx->pix_fmt = QTAV_PIX_FMT_C(YUV420P); //
|
||||
if (format.pixelFormat() == VideoFormat::Format_Invalid) {
|
||||
if (codec->pix_fmts) {
|
||||
avctx->pix_fmt = codec->pix_fmts[0];
|
||||
}
|
||||
} else {
|
||||
avctx->pix_fmt = (AVPixelFormat)format.pixelFormatFFmpeg();
|
||||
}
|
||||
format_used = VideoFormat::pixelFormatFromFFmpeg(avctx->pix_fmt);
|
||||
avctx->time_base = av_d2q(1.0/frame_rate, frame_rate*1001.0+2);
|
||||
qDebug("size: %dx%d tbc: %f=%d/%d", width, height, av_q2d(avctx->time_base), avctx->time_base.num, avctx->time_base.den);
|
||||
avctx->bit_rate = bit_rate;
|
||||
|
||||
Reference in New Issue
Block a user