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

Function CreateBlackBuf

libhb/sync.c:349–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347}
348
349static hb_buffer_t * CreateBlackBuf( sync_stream_t * stream,
350 int64_t dur, int64_t pts )
351{
352 // I would like to just allocate one black frame here and give
353 // it the full duration. But encoders that use B-Frames compute
354 // the dts delay based on the pts of the 2nd or 3rd frame which
355 // can be a very large value in this case. This large dts delay
356 // causes problems with computing the dts of the frames (which is
357 // extrapolated from the pts and the computed dts delay). And the
358 // dts problems lead to problems with frame duration.
359 double frame_dur, next_pts, duration;
360 hb_buffer_list_t list;
361 hb_buffer_t *buf = NULL;
362 hb_job_t *job = stream->common->job;
363
364 hb_buffer_list_clear(&list);
365 duration = dur;
366 next_pts = pts;
367
368 frame_dur = 90000. * job->title->vrate.den / job->title->vrate.num;
369
370 // Only create black buffers of frame_dur or longer
371 while (duration >= frame_dur)
372 {
373 if (buf == NULL)
374 {
375 buf = hb_frame_buffer_init(job->input_pix_fmt,
376 job->title->geometry.width,
377 job->title->geometry.height);
378 uint8_t *planes[4];
379 ptrdiff_t linesizes[4];
380 for (int i = 0; i <= buf->f.max_plane; ++i)
381 {
382 planes[i] = buf->plane[i].data;
383 linesizes[i] = buf->plane[i].stride;
384 }
385 av_image_fill_black(planes, linesizes,
386 job->input_pix_fmt, job->color_range,
387 buf->f.width, buf->f.height);
388 buf->f.color_prim = job->title->color_prim;
389 buf->f.color_transfer = job->title->color_transfer;
390 buf->f.color_matrix = job->title->color_matrix;
391 buf->f.color_range = job->color_range;
392 buf->f.chroma_location = job->chroma_location;
393
394 // Dolby Vision requires a RPU on every buffer, attach the first
395 // found during scan in the absence of something better
396 if (job->title->initial_rpu)
397 {
398 hb_data_t *rpu = job->title->initial_rpu;
399 AVBufferRef *ref = av_buffer_alloc(rpu->size);
400 memcpy(ref->data, rpu->bytes, rpu->size);
401
402 AVFrameSideData *sd_dst = NULL;
403 sd_dst = hb_buffer_new_side_data_from_buf(buf, job->title->initial_rpu_type, ref);
404
405 if (!sd_dst)
406 {

Callers 1

alignStreamFunction · 0.85

Calls 6

hb_buffer_list_clearFunction · 0.85
hb_frame_buffer_initFunction · 0.85
hb_buffer_shallow_dupFunction · 0.85
hb_buffer_list_appendFunction · 0.85

Tested by

no test coverage detected