From: dennis Date: Wed, 22 Mar 2017 10:15:25 +0000 (+0300) Subject: transcoding: Add possibility to transcode only specified video codecs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a334c453cd36bb4b622a5a17e5349c1055143fe2;p=thirdparty%2Ftvheadend.git transcoding: Add possibility to transcode only specified video codecs --- diff --git a/src/plumbing/transcoding.c b/src/plumbing/transcoding.c index 4fc05feab..18d6357ab 100644 --- a/src/plumbing/transcoding.c +++ b/src/plumbing/transcoding.c @@ -1801,6 +1801,29 @@ transcoder_init_video(transcoder_t *t, streaming_start_component_t *ssc) AVCodec *icodec, *ocodec; transcoder_props_t *tp = &t->t_props; int sct; + char *str, *token, *saveptr, codec_list[sizeof(tp->tp_src_vcodec)]; + int codec_match=0; + + strncpy(codec_list, tp->tp_src_vcodec, sizeof(tp->tp_src_vcodec)-1); + + tvhinfo(LS_TRANSCODE, "tp->tp_src_vcodec=\"%s\" ssc->ssc_type=%d (%s)\n", + tp->tp_src_vcodec, + ssc->ssc_type, + streaming_component_type2txt(ssc->ssc_type)); + + if (codec_list[0] != '\0') { + for (str=codec_list; ; str = NULL) { + token = strtok_r(str," ,|;" , &saveptr); + if (token == NULL) + break; //no match found, use profile settings + if(!strcasecmp(token, streaming_component_type2txt(ssc->ssc_type))) {//match found + codec_match=1; + } + } + } + + if(!codec_match) + return transcoder_init_stream(t, ssc); //copy codec if (tp->tp_vcodec[0] == '\0') return 0; @@ -2116,6 +2139,8 @@ transcoder_set_properties(streaming_target_t *st, tp->tp_resolution = props->tp_resolution; memcpy(tp->tp_language, props->tp_language, 4); + + strncpy(tp->tp_src_vcodec, props->tp_src_vcodec, sizeof(tp->tp_src_vcodec)-1); } diff --git a/src/plumbing/transcoding.h b/src/plumbing/transcoding.h index 9b2871ca7..3fc42b0e0 100644 --- a/src/plumbing/transcoding.h +++ b/src/plumbing/transcoding.h @@ -33,6 +33,7 @@ typedef struct transcoder_prop { int32_t tp_resolution; long tp_nrprocessors; + char tp_src_vcodec[128]; } transcoder_props_t; extern uint32_t transcoding_enabled; diff --git a/src/profile.c b/src/profile.c index 10bfb4ac9..6226f6907 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1691,8 +1691,24 @@ typedef struct profile_transcode { char *pro_vcodec_preset; char *pro_acodec; char *pro_scodec; + char *pro_src_vcodec; } profile_transcode_t; + +static htsmsg_t * +profile_class_src_vcodec_list ( void *o, const char *lang ) +{ + static const struct strtab_str tab[] = { + { N_("Any"), "" }, + { "MPEG2VIDEO", "MPEG2VIDEO" }, + { "H264", "H264" }, + { "VP8", "VP8" }, + { "HEVC", "HEVC" }, + { "VP9", "VP9" }, + }; + return strtab2htsmsg_str(tab, 1, lang); +} + static htsmsg_t * profile_class_mc_list ( void *o, const char *lang ) { @@ -1916,6 +1932,21 @@ const idclass_t profile_transcode_class = .opts = PO_ADVANCED, .group = 2 }, + { + .type = PT_STR, + .id = "src_vcodec", + .name = N_("Source video codec"), + .desc = N_("Transcode video only if source video codec mattch. " + "\"Any\" will ingnore source vcodec check and always do transcode. " + "Separate codec names with coma. " + "If no codec match found - transcode with \"copy\" codec, " + "if match found - transcode with parameters in this profile."), + .off = offsetof(profile_transcode_t, pro_src_vcodec), + .def.i = SCT_UNKNOWN, + .list = profile_class_src_vcodec_list, + .opts = PO_ADVANCED, + .group = 2 + }, { .type = PT_STR, .id = "vcodec", @@ -2065,6 +2096,14 @@ profile_transcode_work(profile_chain_t *prch, props.tp_abitrate = profile_transcode_abitrate(pro); strncpy(props.tp_language, pro->pro_language ?: "", 3); + if (!pro->pro_src_vcodec) { + strcpy(props.tp_src_vcodec, ""); + } else if(!strncasecmp("Any",pro->pro_src_vcodec,3)) { + strcpy(props.tp_src_vcodec, ""); + } else { + strncpy(props.tp_src_vcodec, pro->pro_src_vcodec ?: "", sizeof(props.tp_src_vcodec)-1); + } + dst = prch->prch_gh = globalheaders_create(dst); #if ENABLE_TIMESHIFT