string getCodec(MediaStream st, int streamI, ConvertMedia convertAll, string ext, string extra265Paras = "") { var cmd = " -codec:" + streamI + " "; var convert = st.convert; if (convertAll != null) { convert = convertAll; } if (convert.audio_code != "" && st.isAudio()) { cmd += convert.audio_code; if (convert.audio_bit_rate != "") { cmd += " -ab:" + streamI + " " + convert.audio_bit_rate + "k "; } else if (convert.audio_quality != "") { cmd += " -aq:" + streamI + " " + convert.audio_quality + " "; } else { cmd += " -aq:" + streamI + " 2 "; } if (convert.audio_channels != "") { cmd += " -ac:" + streamI + " " + convert.audio_channels + " "; } if (convert.audio_sample_rate != "") { cmd += " -ar:" + streamI + " " + convert.audio_sample_rate + " "; } } else if (convert.video_code != "" && st.isVideo()) { cmd += convert.video_code; } else { if (st.isSubtitle() && !st.isImgSubtitle() && st.hasMovText(ext)) { cmd += " mov_text "; } else if (ext == "mkv" && st.isMovText()) { cmd += " srt "; } else { cmd += " copy "; } } if (st.isVideo()) { if (convert.video_crfs > 0) { var crf = convert.video_crfs - 1; if (convert.video_code.IndexOf("nvenc") > 0) { cmd += " -qp:" + streamI + " " + crf + " "; } else if (convert.video_code.IndexOf("qsv") > 0) { cmd += " -global_quality:" + streamI + " " + crf + " "; } else if (convert.video_code.IndexOf("vp9") >= 0) { cmd += " -crf:" + streamI + " " + crf + " -b:v:" + streamI + " 0 "; } else { cmd += " -crf:" + streamI + " " + crf + " "; } } else if (convert.video_bit_rate != "") { var rate = int.Parse(convert.video_bit_rate); cmd += " -b:v:" + streamI + " " + rate + "k "; } if (convert.video_max_bit_rate != "") { cmd += " -maxrate:v:" + streamI + " " + convert.video_max_bit_rate + "k "; var buf_size = convert.video_buffer_size; if (buf_size == "") { buf_size = convert.video_max_bit_rate + ""; } cmd += " -bufsize " + buf_size + "k "; } if (convert.preset != "") { if (convert.video_code == "vp9") { cmd += " -deadline:" + streamI + " " + convert.preset + " "; } else { cmd += " -preset:" + streamI + " " + convert.preset + " "; } } if (convert.video_display_size != "") { var size = convert.video_display_size; if (convert.video_display_size.Contains("-1")) { var whs = convert.video_display_size.Replace(" ", "").Split(':'); if (whs.Length == 2) { int w = int.Parse(whs[0]); int h = int.Parse(whs[1]); if (whs[0] == "-1") { if (st.height != 0) { w = h * st.width / st.height; } } else if (whs[1] == "-1") { if (st.width != 0) { h = w * st.height / st.width; } } size = getScale(w, h); } } cmd += " -s:" + streamI + " " + size + " "; } cmd += getFieldAttr(convert, streamI); if (convert.video_code == "h264") { var paras = convert.x26x_params.GetType().GetProperties().JoinStr(":", it => FileConvertParameter.getFieldStr(it, convert.x26x_params)); if (paras != "") { cmd += " -x264-params:" + streamI + " \"" + paras + "\" "; } } else if (convert.video_code == "hevc") { var vals = convert.x26x_params.GetType().GetProperties().Select(it => FileConvertParameter.getFieldStr(it, convert.x26x_params, true)). Concat(convert.x265_params.GetType().GetProperties().Select(it => FileConvertParameter.getFieldStr(it, convert.x265_params, true))); if (extra265Paras != "") { vals = new string[] { extra265Paras }.Concat(vals); } var paras = vals.JoinStr(":", it => it); if (paras != "") { cmd += " -x265-params:" + streamI + " \"" + paras + "\" "; } } } if (convert.command_line != "" && convertAll == null) { cmd += " " + convert.command_line + " "; } return(cmd); }
public string getCMD() { return(FileConvertParameter.reflectFilter(this)); }