MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / nal_encode

Function nal_encode

libhb/encx265.c:599–684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

597}
598
599static hb_buffer_t* nal_encode(hb_work_object_t *w,
600 x265_picture *pic_out,
601 x265_nal *nal, uint32_t nnal)
602{
603 hb_work_private_t *pv = w->private_data;
604 hb_buffer_t *buf = NULL;
605 int payload_size = 0;
606
607 if (nnal <= 0)
608 {
609 return NULL;
610 }
611
612 for (int i = 0; i < nnal; i++)
613 {
614 payload_size += nal[i].sizeBytes;
615 }
616
617 buf = hb_buffer_init(payload_size);
618 if (buf == NULL)
619 {
620 return NULL;
621 }
622
623 buf->s.flags = 0;
624 buf->size = 0;
625
626 // copy the bitstream data
627 for (int i = 0; i < nnal; i++)
628 {
629 if (HB_HEVC_NALU_KEYFRAME(nal[i].type))
630 {
631 buf->s.flags |= HB_FLAG_FRAMETYPE_REF;
632 buf->s.flags |= HB_FLAG_FRAMETYPE_KEY;
633 }
634 memcpy(buf->data + buf->size, nal[i].payload, nal[i].sizeBytes);
635 buf->size += nal[i].sizeBytes;
636 }
637
638 // use the pts to get the original frame's duration.
639 buf->s.duration = get_frame_duration(pv, pic_out->pts);
640 buf->s.stop = pic_out->pts + buf->s.duration;
641 buf->s.start = pic_out->pts;
642 buf->s.renderOffset = pic_out->dts;
643 if (*w->init_delay == 0 && pic_out->dts < 0)
644 {
645 *w->init_delay -= pic_out->dts;
646 }
647
648 switch (pic_out->sliceType)
649 {
650 case X265_TYPE_IDR:
651 buf->s.flags |= HB_FLAG_FRAMETYPE_REF;
652 buf->s.flags |= HB_FLAG_FRAMETYPE_KEY;
653 buf->s.frametype = HB_FRAME_IDR;
654 break;
655 case X265_TYPE_P:
656 buf->s.flags |= HB_FLAG_FRAMETYPE_REF;

Callers 2

x265_encodeFunction · 0.70
encx265WorkFunction · 0.70

Calls 4

hb_buffer_initFunction · 0.85
hb_chapter_dequeueFunction · 0.85
hb_buffer_closeFunction · 0.85
get_frame_durationFunction · 0.70

Tested by

no test coverage detected