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

Function hb_read_preview

libhb/hb.c:637–774  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

635}
636
637hb_buffer_t * hb_read_preview(hb_handle_t * h, hb_title_t *title, int preview, int format)
638{
639 FILE * file = NULL;
640 char * filename = NULL;
641 char reason[80];
642 char format_string[HB_FORMAT_CHARS];
643
644 hb_buffer_t * buf;
645 buf = hb_frame_buffer_init(AV_PIX_FMT_YUV420P,
646 title->geometry.width, title->geometry.height);
647 buf->f.color_prim = title->color_prim;
648 buf->f.color_transfer = title->color_transfer;
649 buf->f.color_matrix = title->color_matrix;
650 buf->f.color_range = AVCOL_RANGE_MPEG;
651 buf->f.chroma_location = title->chroma_location;
652
653 if (!buf)
654 {
655 hb_error("hb_read_preview: hb_frame_buffer_init failed");
656 goto done;
657 }
658
659 switch (format)
660 {
661 case HB_PREVIEW_FORMAT_YUV:
662 strncpy(format_string, "yuv", HB_FORMAT_CHARS);
663 break;
664 case HB_PREVIEW_FORMAT_JPG:
665 strncpy(format_string, "jpg", HB_FORMAT_CHARS);
666 break;
667 default:
668 hb_error("hb_read_preview: Unsupported preview format %d", format);
669 return buf;
670 }
671
672 filename = hb_get_temporary_filename("%d_%d_%d.%s", hb_get_instance_id(h),
673 title->index, preview, format_string);
674
675 file = hb_fopen(filename, "rb");
676 if (file == NULL)
677 {
678 if (strerror_r(errno, reason, 79) != 0)
679 {
680 strcpy(reason, "unknown -- strerror_r() failed");
681 }
682 hb_error("hb_read_preview: Failed to open %s (reason: %s)",
683 filename, reason);
684 free(filename);
685 return NULL;
686 }
687
688 if (format == HB_PREVIEW_FORMAT_YUV)
689 {
690 int pp, hh;
691 for (pp = 0; pp < HB_PLANES_MAX; pp++)
692 {
693 uint8_t * data = buf->plane[pp].data;
694 const int stride = buf->plane[pp].stride;

Callers 1

hb_get_previewFunction · 0.85

Calls 6

hb_frame_buffer_initFunction · 0.85
hb_errorFunction · 0.85
hb_get_instance_idFunction · 0.85
hb_fopenFunction · 0.85
strerror_rFunction · 0.85

Tested by

no test coverage detected