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

Function Encode

libhb/encavcodec.c:1370–1446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1368}
1369
1370static void Encode( hb_work_object_t *w, hb_buffer_t **buf_in,
1371 hb_buffer_list_t *list )
1372{
1373 hb_work_private_t * pv = w->private_data;
1374 hb_buffer_t * in = *buf_in;
1375 AVFrame frame = {{0}};
1376 int key_frame = 0;
1377 int ret;
1378
1379 if (in->s.new_chap > 0 && pv->job->chapter_markers)
1380 {
1381 /* chapters have to start with an IDR frame so request that this
1382 frame be coded as IDR. Since there may be multiple frames
1383 currently buffered in the encoder remember the timestamp so
1384 when this frame finally pops out of the encoder we'll mark
1385 its buffer as the start of a chapter. */
1386 key_frame = 1;
1387 hb_chapter_enqueue(pv->chapter_queue, in);
1388 }
1389
1390 // Bizarro ffmpeg requires timestamp time_base to be == framerate
1391 // for the encoders we care about. It writes AVCodecContext.time_base
1392 // to the framerate field of encoded bitstream headers, so if we
1393 // want correct bitstreams, we must set time_base = framerate.
1394 // We can't pass timestamps that are not based on the time_base
1395 // because encoders require accurately based timestamps in order to
1396 // do proper rate control.
1397 //
1398 // I.e. ffmpeg doesn't support VFR timestamps.
1399 //
1400 // Because of this, we have to do some fugly things, like storing
1401 // PTS values and computing DTS ourselves.
1402 //
1403 // Remember timestamp info about this frame
1404 save_frame_info(pv, in);
1405 compute_dts_offset(pv, in);
1406
1407 // Convert the hb_buffer_t to avframe
1408 // This will consume the hb_buffer_t and make it NULL
1409 hb_video_buffer_to_avframe(&frame, buf_in);
1410 frame.pts = pv->frameno_in++;
1411 frame.duration = 0;
1412
1413 // For constant quality, setting the quality in AVCodecContext
1414 // doesn't do the trick. It must be set in the AVFrame.
1415 frame.quality = pv->context->global_quality;
1416
1417 if (key_frame)
1418 {
1419 frame.pict_type = AV_PICTURE_TYPE_I;
1420 frame.flags = AV_FRAME_FLAG_KEY;
1421 }
1422 else
1423 {
1424 frame.pict_type = AV_PICTURE_TYPE_NONE;
1425 frame.flags = 0;
1426 }
1427

Callers 1

encavcodecWorkFunction · 0.70

Calls 6

hb_chapter_enqueueFunction · 0.85
compute_dts_offsetFunction · 0.85
hb_logFunction · 0.85
save_frame_infoFunction · 0.70
get_packetsFunction · 0.70

Tested by

no test coverage detected