Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libav: transcode in HEVC
- add HEVC to the set of working encoders
- add default options
- copy over extradata
  • Loading branch information
lekma authored and perexg committed Sep 29, 2015
1 parent 4d47d33 commit 5fd66bf
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/plumbing/transcoding.c
Expand Up @@ -132,7 +132,7 @@ typedef struct transcoder {
#define WORKING_ENCODER(x) \
((x) == AV_CODEC_ID_H264 || (x) == AV_CODEC_ID_MPEG2VIDEO || \
(x) == AV_CODEC_ID_VP8 || /* (x) == AV_CODEC_ID_VP9 || */ \
(x) == AV_CODEC_ID_AAC || \
(x) == AV_CODEC_ID_HEVC || (x) == AV_CODEC_ID_AAC || \
(x) == AV_CODEC_ID_MP2 || (x) == AV_CODEC_ID_VORBIS)

/**
Expand Down Expand Up @@ -939,7 +939,8 @@ send_video_packet(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt,
if (!octx->coded_frame)
return;

if (ts->ts_type == SCT_H264 && octx->extradata_size &&
if ((ts->ts_type == SCT_H264 || ts->ts_type == SCT_HEVC) &&
octx->extradata_size &&
(ts->ts_first || octx->coded_frame->pict_type == AV_PICTURE_TYPE_I)) {
n = pkt_alloc(NULL, octx->extradata_size + epkt->size, epkt->pts, epkt->dts);
memcpy(pktbuf_ptr(n->pkt_payload), octx->extradata, octx->extradata_size);
Expand Down Expand Up @@ -1199,6 +1200,20 @@ transcoder_stream_video(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt)

break;

case SCT_HEVC:
octx->pix_fmt = PIX_FMT_YUV420P;
octx->flags |= CODEC_FLAG_GLOBAL_HEADER;

av_dict_set(&opts, "preset", "superfast", 0);
av_dict_set(&opts, "tune", "fastdecode", 0);

This comment has been minimized.

Copy link
@CvH

CvH Sep 29, 2015

Contributor

http://x265.readthedocs.org/en/latest/presets.html#zero-latency
--tune zerolatency should also be included, should help a lot for a quick responding stream

This comment has been minimized.

Copy link
@lekma

lekma Sep 29, 2015

Author Contributor

tune=zerolatency is: b-adapt=0, bframes=0, rc-lookahead=0, scenecut=0, cutree=0, frame-threads=1
b-adapt=0 and cutree=0 are set by preset=superfast.
frame-threads=1 is a big no no (it kills server responsiveness).
the rest is added in x265_opts.

av_dict_set(&opts, "crf", "18", 0);

This comment has been minimized.

Copy link
@stbenz

stbenz Sep 30, 2015

Contributor

Would be cool, if t->t_props.tp_vbitrate is used here instead of a fixed value. Also a different set of parameters for t->t_props.tp_vbitrate >= 64, where it's used as average bitrate and optimized for a little higher compression, so the bitrate setting is equivalent to the other encoders.

// decrease latency as much as possible
av_dict_set(&opts, "x265_opts", "bframes=0", 0);
av_dict_set(&opts, "x265_opts", ":rc-lookahead=0", AV_DICT_APPEND);
av_dict_set(&opts, "x265_opts", ":scenecut=0", AV_DICT_APPEND);

break;

default:
break;
}
Expand Down

0 comments on commit 5fd66bf

Please sign in to comment.