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

Function hb_save_preview

libhb/hb.c:516–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

514#define HB_FORMAT_CHARS 4
515
516int hb_save_preview( hb_handle_t * h, int title, int preview, hb_buffer_t *buf, int format )
517{
518 FILE * file;
519 char * filename;
520 char reason[80];
521 char format_string[HB_FORMAT_CHARS];
522
523 switch (format)
524 {
525 case HB_PREVIEW_FORMAT_YUV:
526 strncpy(format_string, "yuv", HB_FORMAT_CHARS);
527 break;
528 case HB_PREVIEW_FORMAT_JPG:
529 strncpy(format_string, "jpg", HB_FORMAT_CHARS);
530 break;
531 default:
532 hb_error("hb_save_preview: Unsupported preview format %d", format);
533 return -1;
534 }
535
536 filename = hb_get_temporary_filename("%d_%d_%d.%s", hb_get_instance_id(h),
537 title, preview, format_string);
538
539 file = hb_fopen(filename, "wb");
540 if (file == NULL)
541 {
542 if (strerror_r(errno, reason, 79) != 0)
543 {
544 strcpy(reason, "unknown -- strerror_r() failed");
545 }
546 hb_error("hb_save_preview: Failed to open %s (reason: %s)",
547 filename, reason);
548 free(filename);
549 return -1;
550 }
551
552 if (format == HB_PREVIEW_FORMAT_YUV)
553 {
554 int pp, hh;
555 for(pp = 0; pp < HB_PLANES_MAX; pp++)
556 {
557 const uint8_t * data = buf->plane[pp].data;
558 const int stride = buf->plane[pp].stride;
559 const int w = buf->plane[pp].width;
560 const int h = buf->plane[pp].height;
561
562 for(hh = 0; hh < h; hh++)
563 {
564 if (fwrite(data, w, 1, file) < w)
565 {
566 if (ferror(file))
567 {
568 if (strerror_r(errno, reason, 79) != 0)
569 {
570 strcpy(reason, "unknown -- strerror_r() failed");
571 }
572 hb_error("hb_save_preview: Failed to write line %d to %s "
573 "(reason: %s). Preview will be incomplete.",

Callers 1

DecodePreviewsFunction · 0.85

Calls 5

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

Tested by

no test coverage detected