<?xml version="1.0" encoding="utf-8"?>
<HmsTranscodingConfig version="2.19">
  <TranscoderList>
    <Transcoder>
      <Name>HMSMPEG</Name>
      <Path>hmsmpeg.exe</Path>
      <HomePage>http://www.ffmpeg.org/</HomePage>
      <Download></Download>
    </Transcoder>
    <Transcoder>
      <Name>HmsMPEG</Name>
      <Path>Hmsmpeg.exe</Path>
      <HomePage>http://www.ffmpeg.org/</HomePage>
      <Download></Download>
    </Transcoder>
    <Transcoder>
      <Name>hmsMPEG</Name>
      <Path>hmsmpeg.exe</Path>
      <HomePage>http://www.ffmpeg.org/</HomePage>
      <Download></Download>
    </Transcoder>
  </TranscoderList>
  <TranscodingProfileList>
    <Profile>
      <TranscoderName>HMSMPEG</TranscoderName>
      <TranscodingCondition></TranscodingCondition>
      <TranscodingConditionSyntaxType>PascalScript</TranscodingConditionSyntaxType>
      <TranscodingComment></TranscodingComment>
      <TranscodingFolder></TranscodingFolder>
      <TranscodingMediaType>3</TranscodingMediaType>
      <TranscodingMimeType></TranscodingMimeType>
      <TranscodingMimeTypeScript>begin
  if SameText(cfgTranscodingFileFormat, &apos;MPEG (DVD)&apos;) then
    FileExt := &apos;mpg&apos;
  else if Pos(&apos;MPEGTS&apos;, cfgTranscodingFileFormat) &gt; 0 then
    FileExt := &apos;ts&apos;
  else if Pos(&apos;ASF&apos;, cfgTranscodingFileFormat) &gt; 0 then
    FileExt := &apos;wmv&apos;
  else if SameText(cfgTranscodingFileFormat, &apos;MP4&apos;) then
    FileExt := &apos;mp4&apos;
  else if SameText(cfgTranscodingFileFormat, &apos;MPEG1&apos;) then
    FileExt := &apos;mpeg&apos;
  else if SameText(cfgTranscodingFileFormat, &apos;FLV&apos;) then
    FileExt := &apos;flv&apos;
  else
    FileExt := &apos;&apos;;    
  if FileExt &lt;&gt; &apos;&apos; then
    MimeType := HmsGetMimeType(FileExt)    
  else            
    MimeType := &apos;&apos;
end.</TranscodingMimeTypeScript>
      <TranscodingMimeTypeSyntaxType>PascalScript</TranscodingMimeTypeSyntaxType>
      <TranscodingMode>1</TranscodingMode>
      <TranscodingParams>const
  csFFMpegVideoParams = &apos; -vcodec %s %s%s -pix_fmt yuv420p&apos;;
  csFFMpegAudioParams = &apos; -acodec %s -ab %d -ar %d -ac %d&apos;;  

procedure GetAudioTranscodingParams(const aAudioCodec: string; 
    var aCodecName, aFileFormat: string; var aCodecID, aAudioBitrate, aAudioChannels: Integer);
begin
  aAudioBitrate := cfgTranscodingAudioBitrate;  
  if (cfgTranscodingAudioChannels &lt;&gt; 0) then  
    aAudioChannels := cfgTranscodingAudioChannels;
  if SameText(aAudioCodec, &apos;AAC&apos;) then begin
    aCodecName  := &apos;libfaac&apos;;    
    aFileFormat := &apos;adts&apos;;
    aCodecID    := CODEC_ID_AAC; 
  end else if SameText(aAudioCodec, &apos;MP3&apos;) then begin
    aCodecName  := &apos;libmp3lame&apos;;    
    aFileFormat := &apos;mp3&apos;;
    aCodecID    := CODEC_ID_MP3;
    if aAudioBitrate &gt; 320000 then
      aAudioBitrate := 320000;
    if aAudioChannels &gt; 2 then
      aAudioChannels := 2;      
  end else if SameText(aAudioCodec, &apos;MP2&apos;) then begin  
    aCodecName  := &apos;mp2&apos;;    
    aFileFormat := &apos;mp2&apos;;
    aCodecID    := CODEC_ID_MP2;
    if aAudioBitrate &gt; 320000 then
      aAudioBitrate := 320000;      
    if aAudioChannels &gt; 2 then
      aAudioChannels := 2;      
  end else if SameText(aAudioCodec, &apos;LPCM&apos;) then begin  
    aCodecName  := &apos;pcm_s16be&apos;;    
    aFileFormat := &apos;s16be&apos;;
    aCodecID    := CODEC_ID_PCM_BLURAY;
  end else if SameText(aAudioCodec, &apos;DTS&apos;) then begin  
    aCodecName  := &apos;dca&apos;;    
    aFileFormat := &apos;dts&apos;;
    aCodecID    := CODEC_ID_DTS;
    aAudioChannels := 6    
  end else if SameText(aAudioCodec, &apos;WMA&apos;) then begin  
    aCodecName  := &apos;wmav2&apos;;    
    aFileFormat := &apos;asf&apos;;
    aCodecID    := CODEC_ID_WMAV2;    
    if aAudioChannels &gt; 2 then
      aAudioChannels := 2;      
  end else begin
    aCodecName  := &apos;ac3&apos;;    
    aFileFormat := &apos;ac3&apos;;    
    if SameText(aAudioCodec, &apos;AC3&apos;) then
      aCodecID := CODEC_ID_AC3
    else                          
      aCodecID := CODEC_ID_NONE;
  end  
end;

function GetFileFormat(const aFileFormat: string): string;
begin
  if (aFileFormat = &apos;&apos;) or SameText(aFileFormat, &apos;MPEG (DVD)&apos;) then
    Result := &apos;dvd&apos;
  else if Pos(&apos;MPEGTS&apos;, aFileFormat) &gt; 0 then
    Result := &apos;mpegts&apos;
  else if Pos(&apos;ASF&apos;, aFileFormat) &gt; 0 then
    Result := &apos;asf&apos;
  else if SameText(aFileFormat, &apos;MP4&apos;) then
    Result := &apos;ipod&apos;    
  else if SameText(aFileFormat, &apos;FLV&apos;) then
    Result := &apos;flv&apos;
  else if SameText(aFileFormat, &apos;MPEG1&apos;) then
    Result := &apos;mpeg&apos;
  else
    Result := aFileFormat
end;

function GetVideoCodec(const aVideoCodec: string): string;
begin
  if (aVideoCodec = &apos;&apos;) or SameText(aVideoCodec, &apos;MPEG2&apos;) then
    Result := &apos;mpeg2video&apos;
  else if SameText(aVideoCodec, &apos;MPEG1&apos;) then
    Result := &apos;mpeg1video&apos;    
  else if SameText(aVideoCodec, &apos;FLV&apos;) then
    Result := &apos;flv&apos;
  else if SameText(aVideoCodec, &apos;WMV&apos;) then
    Result := &apos;wmv2&apos;
  else if SameText(aVideoCodec, &apos;MPEG4&apos;) then
    Result := &apos;mpeg4&apos;
  else if SameText(aVideoCodec, &apos;X264&apos;) then
    Result := &apos;libx264 -x264opts "fast-pskip=1:rc-lookahead=0:aq_mode=0" -partitions none -sc_threshold 0 -trellis 0 -me_method dia -refs 1 -subq 0 -vprofile baseline -level 30 -bufsize 10000000 &apos;
  else
    Result := aVideoCodec
end;

function GetMultiThreadSupported(const aVideoCodec: string): Boolean;
begin
  Result := not MatchText(aVideoCodec, [&apos;WMV&apos;, &apos;MPEG1&apos;, &apos;FLV&apos;])
end;

function GetAudioBitrate(const aAudioCodec: string; aAudioBitrate: Integer): Integer;
begin
  if MatchText(aAudioCodec, [&apos;MP2&apos;, &apos;MP3&apos;]) and (aAudioBitrate &gt; 320000) then
    Result := 320000
  else
    Result := aAudioBitrate
end;

function GetAudioSampleRate(const aFileFormat, aAudioCodec: string): Integer;
begin
  if MatchText(aFileFormat, [&apos;FLV&apos;]) and not SameText(aAudioCodec, &apos;AAC&apos;) then  
    Result := 44100
  else
    Result := 48000
end;

function GetAudioChannels(const aAudioCodec: string; aConfigAudioChannels, aStreamAudioChannels: Integer): Integer;
begin
  if aConfigAudioChannels &gt; 0 then
    Result := aConfigAudioChannels
  else
    Result := aStreamAudioChannels;
  if (Result &gt; 2) and MatchText(aAudioCodec, [&apos;MP2&apos;, &apos;MP3&apos;]) then
    Result := 2
  else if (Result = 1) and MatchText(aAudioCodec, [&apos;AAC&apos;, &apos;AC3&apos;]) then
    Result := 2
  else if Result &gt; 6 then
    Result := 6
end;

function VideoCodecCompatible: Boolean;
begin
  if (cfgTranscodingFileFormat = &apos;&apos;) or SameText(cfgTranscodingFileFormat, &apos;MPEG (DVD)&apos;) then
    Result := MatchText(mpVideoCodec, [&apos;MPEG2VIDEO&apos;, &apos;MPEG1VIDEO&apos;])
  else if Pos(&apos;MPEGTS&apos;, cfgTranscodingFileFormat) &gt; 0 then
    Result := MatchText(mpVideoCodec, [&apos;H264&apos;, &apos;MPEG2VIDEO&apos;, &apos;MPEG1VIDEO&apos;, &apos;MPEG4&apos;])
  else if Pos(&apos;ASF&apos;, cfgTranscodingFileFormat) &gt; 0 then
    Result := MatchText(mpVideoCodec, [&apos;H264&apos;, &apos;MPEG4&apos;, &apos;WMV2&apos;])
  else if SameText(cfgTranscodingFileFormat, &apos;MP4&apos;) then
    Result := MatchText(mpVideoCodec, [&apos;H264&apos;, &apos;MPEG4&apos;])    
  else if SameText(cfgTranscodingFileFormat, &apos;FLV&apos;) then
    Result := MatchText(mpVideoCodec, [&apos;H264&apos;, &apos;FLV&apos;])
  else if SameText(cfgTranscodingFileFormat, &apos;MPEG1&apos;) then
    Result := MatchText(mpVideoCodec, [&apos;MPEG2VIDEO&apos;, &apos;MPEG1VIDEO&apos;])
  else
    Result := False
end;

procedure AddFilterParams(var aFilterParams: string; const aAddParams: string);
begin
  if aFilterParams &lt;&gt; &apos;&apos; then
    aFilterParams := aFilterParams + &apos;,&apos;;
  aFilterParams := aFilterParams + aAddParams
end;
  
var
  bMapStreams, bDeinterlace, bPipe, bSuccess, bAudioTranscoding, bVideoTranscoding: Boolean;
  iAudioBitrate, iAudioChannels, iAudioCfgBitrate, iAudioCfgCodecID, iAudioStreamNo, 
  iCodecID, iFrameWidth, iFrameHeight, iWidth, iHeight, 
  iPadLeft, iPadTop, iPadRight, iPadBottom, iVideoCodecID, iAudioCodecID: Integer;  
  sVideoTranscodingParams, sAudioTranscodingParams, sTranscodingParams,
  sAudioCfgCodecName, sAudioCfgFileFormat, sInputAudioFileName, 
  sInputVideoFileName, sFrameRate, sResourcePipe, sSoxTranscodingParams, 
  sVideoBitrate, sVideoMinMaxRate, sFilterParams, sPadParams: string;
begin
  if HmsGetStreamCount = 0 then  
    HmsRetrieveProperties;
  bPipe := Pos(&apos;\\.\pipe\&apos;, InputFileName) &gt; 0;    
  bDeinterlace := SameText(HmsGetVideoSettings(vstDeinterlace), &apos;on&apos;);                                
  if bPipe then                 
            
  else if (mpIsoItem or mpDvdItem or mpBdItem) and HmsCreateResourcePipe(sResourcePipe) then begin
    InputFileName := sResourcePipe;      
    bPipe := True;      
  end else if mpPodcastItem then begin
    InputFileName := HmsGetItemProperty(mpiMediaResourceSource);
    bPipe := Pos(&apos;\\.\pipe\&apos;, InputFileName) &gt; 0;
  end;        
  bVideoTranscoding := False;      
  bAudioTranscoding := False;    
  sInputVideoFileName := InputFileName;
  sInputAudioFileName := InputFileName;
  iAudioStreamNo := mpAudioStreamNo;
  if iAudioStreamNo &lt; 0 then
    iAudioStreamNo := 0;      
  iVideoCodecID  := HmsGetStreamCodecID(stVideo, 0);  
  iAudioCodecID  := HmsGetStreamCodecID(stAudio, iAudioStreamNo);      
  iAudioChannels := HmsGetStreamChannels(iAudioStreamNo);    
  if iAudioChannels &gt; 2 then iAudioChannels := 6;  
  iAudioBitrate  := HmsGetStreamBitrate(stAudio, iAudioStreamNo);
  sTranscodingParams := &apos;&apos;; sSoxTranscodingParams := &apos;&apos;;
  bVideoTranscoding := False;    
  bAudioTranscoding := False;
  if SameText(HmsGetVideoSettings(vstVideoOriginal), &apos;On&apos;) then
    bVideoTranscoding := False    
  else if SameText(HmsGetVideoSettings(vstVideoOriginal), &apos;Off&apos;) then    
    bVideoTranscoding := True 
  else if (mpSubtitleLanguage &lt;&gt; &apos;&apos;) or (HmsGetVideoSettings(vstSubtitle) &lt;&gt; &apos;&apos;) or bDeinterlace then    
    bVideoTranscoding := True     
  else if (mpFrameRate &gt; 0) and (mpFrameRate &lt; 20) then
    bVideoTranscoding := True      
  else if not VideoCodecCompatible then
    bVideoTranscoding := True
  else begin        
    if (mpOriginalWidth &gt; 0) then begin    
      iWidth  := mpOriginalWidth;      
      iHeight := mpOriginalHeight;
    end else begin    
      iWidth  := mpWidth;      
      iHeight := mpHeight;
    end;               
    if (iWidth &gt; cfgMaximumVideoResolutionWidth) or (iHeight &gt; cfgMaximumVideoResolutionHeight) then
      bVideoTranscoding := True  
  end;        
  GetAudioTranscodingParams(cfgTranscodingAudioCodec, sAudioCfgCodecName,
          sAudioCfgFileFormat, iAudioCfgCodecID, iAudioCfgBitrate, iAudioChannels);      
  if SameText(HmsGetVideoSettings(vstAudioOriginal), &apos;On&apos;) then
    bAudioTranscoding := False    
  else if SameText(HmsGetVideoSettings(vstAudioOriginal), &apos;Off&apos;) then    
    bAudioTranscoding := True
  else if (iAudioCodecID &lt;&gt; iAudioCfgCodecID) or 
       ((cfgTranscodingAudioChannels &lt;&gt; 0) and (cfgTranscodingAudioChannels &lt;&gt; iAudioChannels)) or
       ((cfgTranscodingFileFormat = &apos;FLV&apos;) and 
         (GetAudioSampleRate(cfgTranscodingFileFormat, cfgTranscodingAudioCodec) &lt;&gt; mpAudioSampleRate)) then
    bAudioTranscoding := True;              
  if bVideoTranscoding then begin
    sVideoMinMaxRate := &apos;&apos;;         
    if cfgTranscodingVideoBitrate &gt; 0 then begin  
      sVideoBitrate := &apos;-b:v &apos; + IntToStr(cfgTranscodingVideoBitrate);
      if cfgTranscodingVideoMinMaxRate then
        sVideoMinMaxRate := Format(&apos; -minrate %d -maxrate %d -bufsize %d&apos;,
                    [cfgTranscodingVideoBitrate, cfgTranscodingVideoBitrate, 
                     HmsTranscodingBufferSize(cfgTranscodingVideoBitrate)])
    end else
      sVideoBitrate := &apos;-sameq&apos;;
    sVideoTranscodingParams := Format(csFFMPegVideoParams, 
            [GetVideoCodec(cfgTranscodingVideoCodec), sVideoBitrate,
                           sVideoMinMaxRate]);
    sFrameRate := HmsGetVideoSettings(vstFrameRate);
    if sFrameRate = &apos;&apos; then    
      sFrameRate := cfgTranscodingFrameRate;
    if sFrameRate = &apos;&apos; then begin
      if SameText(cfgTranscodingVideoCodec, &apos;FLV&apos;) then      
        sFrameRate := FormatFloat(&apos;0&apos;, mpFrameRate)
      else if (mpFrameRate &gt; 0) and (mpFrameRate &lt; 20) then 
        sFrameRate := &apos;25.000&apos;
    end;          
    if sFrameRate &lt;&gt; &apos;&apos; then
      sVideoTranscodingParams := sVideoTranscodingParams + &apos; -r &apos; + sFrameRate;
    iWidth := mpWidth; iHeight := mpHeight;  
    if (iWidth &gt; 0) and (iHeight &gt; 0) then begin
      sFilterParams := &apos;&apos;; sPadParams := &apos;&apos;;    
      if HmsTranscodingFrameParams(iWidth, iHeight, cfgTranscodingScreenFormat,
                         iPadLeft, iPadTop, iPadRight, iPadBottom) then begin                         
        if mp3DVideoType in [1, 2] then begin
          iWidth  := iWidth  + iPadLeft + iPadRight;
          iHeight := iHeight + iPadTop + iPadBottom;                 
          if mp3DVideoType = 1 then
            iWidth  := (iWidth div 4) * 4
          else
            iHeight := (iHeight div 4) * 4          
        end;
        iFrameWidth  := iWidth;
        iFrameHeight := iHeight;
        if (mp3DVideoType = 0) and ((iPadLeft &gt; 0) or (iPadRight &gt; 0) or (iPadTop &gt; 0) or (iPadBottom &gt; 0)) then begin        
          Inc(iFrameWidth,  iPadLeft + iPadRight);
          Inc(iFrameHeight, iPadTop + iPadBottom);
          sPadParams := Format(&apos;pad=%d:%d:%d:%d:0x%s&apos;,
                        [iFrameWidth, iFrameHeight, iPadLeft, iPadTop, HmsConvertColor(cfgTranscodingPadColor)]);
          if cfgTranscodingFrameExists then
            sVideoTranscodingParams := sVideoTranscodingParams + cfgTranscodingFrameParams;
        end
      end else begin
        iFrameWidth  := iWidth;
        iFrameHeight := iHeight;
      end;
      AddFilterParams(sFilterParams, Format(&apos;scale=%d:%d&apos;, [iWidth, iHeight]));
      if sPadParams &lt;&gt; &apos;&apos; then AddFilterParams(sFilterParams, sPadParams);
      AddFilterParams(sFilterParams, &apos;setdar=&apos; + cfgTranscodingAspectRatio);
      sVideoTranscodingParams := sVideoTranscodingParams + Format(&apos; -vf "%s"&apos;, [sFilterParams]);
      sVideoTranscodingParams := sVideoTranscodingParams + HmsTranscodingSubTitleParams(
         iFrameWidth, iFrameHeight, iWidth, iHeight, iPadLeft, iPadTop);
      if (cfgTranscodingThreadCount &gt; 1) and GetMultiThreadSupported(cfgTranscodingVideoCodec) then
        sVideoTranscodingParams := sVideoTranscodingParams + &apos; -threads &apos; + IntToStr(cfgTranscodingThreadCount);
    end    
  end else begin  
    sVideoTranscodingParams := &apos; -copyinkf -vcodec copy &apos;;        
    if SameText(mpVideoCodec, &apos;H264&apos;) and not SameText(mpFileType, &apos;mpegts&apos;) and not SameText(mpFileType, &apos;wtv&apos;) then
      sVideoTranscodingParams := sVideoTranscodingParams + &apos; -vbsf h264_mp4toannexb&apos;      
  end;                 
  if bAudioTranscoding then  
    sAudioTranscodingParams := Format(csFFMpegAudioParams, [sAudioCfgCodecName, iAudioCfgBitrate, 
        GetAudioSampleRate(cfgTranscodingFileFormat, cfgTranscodingAudioCodec), iAudioChannels])
  else                   
    sAudioTranscodingParams := &apos; -acodec copy&apos;;     
  bMapStreams := HmsGetStreamCount &gt; 0;
  sTranscodingParams := HmsTranscodingProbeParams;
  if mpTimeStart &lt;&gt; &apos;&apos; then
    sTranscodingParams := sTranscodingParams + &apos;-ss &apos; + mpTimeStart + &apos; &apos;;
  if SameText(mpFileType, &apos;mpeg&apos;) then                            
    sTranscodingParams := sTranscodingParams + &apos;-f mpeg &apos;;    
  sTranscodingParams := sTranscodingParams + Format(&apos;-i "%s" &apos;, [InputFileName]);
  sTranscodingParams := sTranscodingParams + &apos;-f &apos; + GetFileFormat(cfgTranscodingFileFormat);
  sTranscodingParams := sTranscodingParams + sVideoTranscodingParams + sAudioTranscodingParams;                                   
  if bMapStreams then                           
    sTranscodingParams := sTranscodingParams + Format(&apos; -map 0:%d -map 0:%d&apos;, [HmsGetStreamIndex(stVideo, 0), HmsGetStreamIndex(stAudio, iAudioStreamNo)]);
  sTranscodingParams := sTranscodingParams + &apos; "&lt;OUTPUT FILE&gt;"&apos;;  
//  TranscodingParams := sTranscodingParams;
  TranscodingResult := HmsTranscodingExecute(&apos;HMSMPEG&apos;, sTranscodingParams, True, InputFileName, OutputFileName)                       
end.</TranscodingParams>
      <TranscodingParamsSyntaxType>PascalScript</TranscodingParamsSyntaxType>
      <TranscodingProfile>Фильмы (Ремуксирование) (25fps+dl 6)</TranscodingProfile>
      <TranscodingProfileActive>-1</TranscodingProfileActive>
      <TranscodingProfilePriority>2</TranscodingProfilePriority>
      <TranscodingProfileUuid>f9fae6b8-2cc0-4542-890f-a20dd6a58b7e</TranscodingProfileUuid>
    </Profile>
  </TranscodingProfileList>
</HmsTranscodingConfig>
