]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
transcoding: Add possibility to transcode only specified video codecs
authordennis <dennis_y@mail.ru>
Wed, 22 Mar 2017 10:15:25 +0000 (13:15 +0300)
committerJaroslav Kysela <perex@perex.cz>
Mon, 24 Apr 2017 14:55:54 +0000 (16:55 +0200)
src/plumbing/transcoding.c
src/plumbing/transcoding.h
src/profile.c

index 4fc05feabcdf5e976b93e1cc10d6ae5d17d386a0..18d6357ab6ec25e1d76030a9b764e5c4421726f4 100644 (file)
@@ -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);
 }
 
 
index 9b2871ca7b686ccbd6c7aab580772fe2087094ab..3fc42b0e00bf3a2cd893cd07d78818d8cd441c3a 100644 (file)
@@ -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;
index 10bfb4ac94b8cd71f52d33b84f02e88d6b5efb4a..6226f690780f27df5ccee36e31b0b95c5da5f59a 100644 (file)
@@ -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