How to pre-transcode files?

Post Reply
pavel
Posts: 3
Joined: Sun Mar 14, 2010 9:52 am

How to pre-transcode files?

Post by pavel »

Hi!
I try to pre-transcode a file with Shift+F5, but I get an error every time (screenshot).
screen.png
screen.png (6.84 KiB) Viewed 7957 times
How to make pre-transcoding work?

TV = Sony W5500

Script text:

Code: Select all

const
  csDestDirectory   = 'D:\video\_transcoded';                                  // directory transcoded files
  csTranscodingProfileName = 'Фильмы (основной)';           // transcoding profile name (Movies (primary)) 
  
  mpiTranscodingFinish = 100000;  // Id properties "Sign complete transcoding"
                                  // Properties less than 100000 are used by the program
                               
procedure ProcessFile(const aSourceFileName, aDestDirectory: string; aCheckTranscodingFinish: Boolean);
var
  bExecuteTranscoding: Boolean;
  MediaItem: TWmsScriptMediaItem;
  sDestDirectory, sDestFileName, sDestFileExt, sLogMessage: string;
begin
  if WmsFileMediaType(aSourceFileName) = mtVideo then begin 
    if not WmsFileLocked(aSourceFileName) then begin
      sDestFileExt := WmsGetTranscodingFileExt(csTranscodingProfileName); 
      sDestFileName := IncludeTrailingBackslash(aDestDirectory) + 
               ChangeFileExt(ExtractFileName(aSourceFileName), sDestFileExt);               
      if not WmsFileLocked(sDestFileName) then begin
        bExecuteTranscoding := True;
        if aCheckTranscodingFinish then begin
          MediaItem := WmsFindMediaItemByFileName(sDestFileName);
          if (MediaItem <> nil) and (MediaItem.Properties[mpiTranscodingFinish] = '1') then begin
            if FileExists(sDestFileName) then
              bExecuteTranscoding := False              
            else begin 
              MediaItem.Properties[mpiTranscodingFinish] := '0';
              WmsDatabaseAutoSave
            end  
          end
        end;
        if bExecuteTranscoding then begin
          sLogMessage := 'Processing media resources: %s transcoding file "' + aSourceFileName + '" to file "' + sDestFileName + '"';
          WmsLogMessage(mtiInfo, Format(sLogMessage, ['Start']));          
          if WmsFileTranscoding(aSourceFileName, sDestFileName, csTranscodingProfileName) then begin
            MediaItem := WmsFindMediaItemByFileName(sDestFileName);
            if MediaItem = nil then
              MediaItem := WmsCreateMediaItem(sDestFileName);
            if MediaItem <> nil then
              MediaItem.Properties[mpiTranscodingFinish] := '1';
            WmsDatabaseAutoSave;
            WmsLogMessage(mtiInfo, Format(sLogMessage, ['Finish']), True);
          end else
            WmsLogMessage(mtiError, Format(sLogMessage, ['Error']))
        end   
      end    
    end
  end 
end;

var
  MediaItem: TWmsScriptMediaItem;
begin
  ProcessMediaResult := False;
  if csDestDirectory = '' then 
    RaiseException('Not specified directory transcoded files.')
  else if csTranscodingProfileName = '' then
    RaiseException('Not specified transcoding profile name.')
  else begin  
    MediaItem := WmsCurrentMediaListItem;
    if MediaItem <> nil then begin
      ProcessFile(MediaItem.Properties[mpiFilePath], csDestDirectory, False);
      ProcessMediaResult := True
    end else
      RaiseException('No current media resource')  
  end    
end.
Eugene
Posts: 2940
Joined: Tue Nov 17, 2009 8:05 pm

Re: How to pre-transcode files?

Post by Eugene »

Hi,
pavel wrote: I try to pre-transcode a file with Shift+F5, but I get an error every time (screenshot).
screen.png
How to make pre-transcoding work?

TV = Sony W5500

Script text:

Code: Select all

const
  csDestDirectory   = 'D:\video\_transcoded';                                  // directory transcoded files
  csTranscodingProfileName = 'Фильмы (основной)';           // transcoding profile name (Movies (primary)) 
  
  mpiTranscodingFinish = 100000;  // Id properties "Sign complete transcoding"
                                  // Properties less than 100000 are used by the program
                               
procedure ProcessFile(const aSourceFileName, aDestDirectory: string; aCheckTranscodingFinish: Boolean);
var
  bExecuteTranscoding: Boolean;
  MediaItem: TWmsScriptMediaItem;
  sDestDirectory, sDestFileName, sDestFileExt, sLogMessage: string;
begin
  if WmsFileMediaType(aSourceFileName) = mtVideo then begin 
    if not WmsFileLocked(aSourceFileName) then begin
      sDestFileExt := WmsGetTranscodingFileExt(csTranscodingProfileName); 
      sDestFileName := IncludeTrailingBackslash(aDestDirectory) + 
               ChangeFileExt(ExtractFileName(aSourceFileName), sDestFileExt);               
      if not WmsFileLocked(sDestFileName) then begin
        bExecuteTranscoding := True;
        if aCheckTranscodingFinish then begin
          MediaItem := WmsFindMediaItemByFileName(sDestFileName);
          if (MediaItem <> nil) and (MediaItem.Properties[mpiTranscodingFinish] = '1') then begin
            if FileExists(sDestFileName) then
              bExecuteTranscoding := False              
            else begin 
              MediaItem.Properties[mpiTranscodingFinish] := '0';
              WmsDatabaseAutoSave
            end  
          end
        end;
        if bExecuteTranscoding then begin
          sLogMessage := 'Processing media resources: %s transcoding file "' + aSourceFileName + '" to file "' + sDestFileName + '"';
          WmsLogMessage(mtiInfo, Format(sLogMessage, ['Start']));          
          if WmsFileTranscoding(aSourceFileName, sDestFileName, csTranscodingProfileName) then begin
            MediaItem := WmsFindMediaItemByFileName(sDestFileName);
            if MediaItem = nil then
              MediaItem := WmsCreateMediaItem(sDestFileName);
            if MediaItem <> nil then
              MediaItem.Properties[mpiTranscodingFinish] := '1';
            WmsDatabaseAutoSave;
            WmsLogMessage(mtiInfo, Format(sLogMessage, ['Finish']), True);
          end else
            WmsLogMessage(mtiError, Format(sLogMessage, ['Error']))
        end   
      end    
    end
  end 
end;

var
  MediaItem: TWmsScriptMediaItem;
begin
  ProcessMediaResult := False;
  if csDestDirectory = '' then 
    RaiseException('Not specified directory transcoded files.')
  else if csTranscodingProfileName = '' then
    RaiseException('Not specified transcoding profile name.')
  else begin  
    MediaItem := WmsCurrentMediaListItem;
    if MediaItem <> nil then begin
      ProcessFile(MediaItem.Properties[mpiFilePath], csDestDirectory, False);
      ProcessMediaResult := True
    end else
      RaiseException('No current media resource')  
  end    
end.
Test transcoding is working with the selected profile for the problematic file?
pavel
Posts: 3
Joined: Sun Mar 14, 2010 9:52 am

Re: How to pre-transcode files?

Post by pavel »

Yes, test transcoding works perfectly ok.
The file is not problematic, I can't decode any file in my collection. At the same time, there is no problems when I watch these files on TV using WMS.
Eugene
Posts: 2940
Joined: Tue Nov 17, 2009 8:05 pm

Re: How to pre-transcode files?

Post by Eugene »

pavel wrote:Yes, test transcoding works perfectly ok.
The file is not problematic, I can't decode any file in my collection. At the same time, there is no problems when I watch these files on TV using WMS.
In editing the script can be done step by step execution.
pavel
Posts: 3
Joined: Sun Mar 14, 2010 9:52 am

Re: How to pre-transcode files?

Post by pavel »

Step-by-step execution doesn't help. I can't set the "WmsCurrentMediaListItem" in steb-by-step mode. See attachment.
screen1.PNG
screen1.PNG (10.83 KiB) Viewed 7915 times
Anyway, this standard script doesn't work for me - the "WmsFileTranscoding(aSourceFileName, sDestFileName, csTranscodingProfileName)" returns "False" without any comment.
Post Reply