Skip to content

Commit

Permalink
Encoder fixes, added muxing capability with NUT format
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaMorphic committed Jun 11, 2022
1 parent c9095f0 commit 2bad3cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
29 changes: 15 additions & 14 deletions libavcodec/libvvenc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/rational.h"

#include "avcodec.h"
#include "encode.h"
#include "internal.h"
Expand Down Expand Up @@ -55,7 +58,7 @@ static av_cold void ff_vvenc_expand_bytes(uint8_t* src, int16_t* dst, int64_t n)
static av_cold int ff_vvenc_encode_init(AVCodecContext *avctx)
{
VVEnCContext *q = avctx->priv_data;
vvenc_init_default (&q->params, avctx->width, avctx->height, avctx->framerate.num, avctx->bit_rate, avctx->global_quality, VVENC_MEDIUM);
vvenc_init_default (&q->params, avctx->width, avctx->height, avctx->framerate.num, avctx->bit_rate, avctx->global_quality, VVENC_FASTER);

q->params.m_verbosity = VVENC_DETAILS;
if ( av_log_get_level() >= AV_LOG_DEBUG ) q->params.m_verbosity = VVENC_DETAILS;
Expand All @@ -67,10 +70,10 @@ static av_cold int ff_vvenc_encode_init(AVCodecContext *avctx)

q->params.m_internChromaFormat = VVENC_CHROMA_420;
if(avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
q->params.m_inputBitDepth[0] = 8;
q->params.m_outputBitDepth[0] = q->params.m_internalBitDepth[0] = q->params.m_inputBitDepth[0] = 8;
}
else if(avctx->pix_fmt == AV_PIX_FMT_YUV420P10LE) {
q->params.m_inputBitDepth[0] = 10;
q->params.m_outputBitDepth[0] = q->params.m_internalBitDepth[0] = q->params.m_inputBitDepth[0] = 10;
}

if(avctx->thread_count > 0) {
Expand All @@ -81,6 +84,7 @@ static av_cold int ff_vvenc_encode_init(AVCodecContext *avctx)
}

q->params.m_FrameScale = avctx->framerate.den;
q->params.m_TicksPerSecond = 90000;

vvenc_init_config_parameter(&q->params);

Expand Down Expand Up @@ -113,8 +117,8 @@ static av_cold int ff_vvenc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}

q->yuvbuf->sequenceNumber = avctx->frame_number;
q->yuvbuf->cts = frame->pts * q->params.m_TicksPerSecond * avctx->time_base.num / avctx->time_base.den;
q->yuvbuf->ctsValid = true;
q->yuvbuf->cts = av_rescale_q(frame->pts, av_make_q(1, q->params.m_TicksPerSecond), avctx->time_base);
q->yuvbuf->ctsValid = true;

if(vvenc_encode(q->encoder, q->yuvbuf, q->au, &q->encDone)) {
return -1;
Expand All @@ -124,8 +128,12 @@ static av_cold int ff_vvenc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (pktSize > 0) {
ff_get_encode_buffer(avctx, avpkt, pktSize, 0);

avpkt->dts = q->au->dts * avctx->time_base.den / (q->params.m_TicksPerSecond * avctx->time_base.num);
avpkt->pts = q->au->cts * avctx->time_base.den / (q->params.m_TicksPerSecond * avctx->time_base.num);
avpkt->dts = av_rescale_q(q->au->dts, av_make_q(1, q->params.m_TicksPerSecond), avctx->time_base);
avpkt->pts = av_rescale_q(q->au->cts, av_make_q(1, q->params.m_TicksPerSecond), avctx->time_base);

if (q->au->refPic) {
avpkt->flags = AV_PKT_FLAG_KEY;
}

memcpy(avpkt->data, q->au->payload, pktSize);
*got_packet_ptr = 1;
Expand All @@ -137,13 +145,6 @@ static av_cold int ff_vvenc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
static av_cold int ff_vvenc_encode_close(AVCodecContext *avctx)
{
VVEnCContext *q = avctx->priv_data;
vvencYUVBuffer* yuvFlush = NULL;

while (!q->encDone) {
if(vvenc_encode(q->encoder, yuvFlush, q->au, &q->encDone)) {
return -1;
}
}

vvenc_encoder_close(q->encoder);
vvenc_YUVBuffer_free(q->yuvbuf, 1);
Expand Down
1 change: 1 addition & 0 deletions libavformat/nut.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const AVCodecTag ff_nut_video_tags[] = {
{ AV_CODEC_ID_XFACE, MKTAG('X', 'F', 'A', 'C') },
{ AV_CODEC_ID_VP9, MKTAG('V', 'P', '9', '0') },
{ AV_CODEC_ID_HEVC, MKTAG('H', 'E', 'V', 'C') },
{ AV_CODEC_ID_VVC, MKTAG('V', 'V', 'C', '0') },
{ AV_CODEC_ID_CPIA, MKTAG('C', 'P', 'i', 'A') },
{ AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 15 ) },
{ AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 15 ) },
Expand Down

0 comments on commit 2bad3cf

Please sign in to comment.