protected virtual void CreateDestMediaIfNotExists()
 {
     lock (_destMediaLock)
     {
         if (Dest == null)
         {
             Dest = (MediaBase)DestDirectory.CreateMedia(DestProperties ?? Source);
         }
     }
 }
Beispiel #2
0
 protected void CreateDestMediaIfNotExists()
 {
     lock (_destMediaLock)
     {
         if (_destMedia == null)
         {
             DestMedia = DestDirectory.CreateMedia(DestMediaProperties != null? DestMediaProperties: SourceMedia);
         }
     }
 }
 private IngestMedia _createDestMedia(IngestDirectory destDirectory)
 {
     if (destDirectory.Kind == TIngestDirectoryKind.XDCAM)
     {
         var existingFiles = DestDirectory.GetFiles().Where(f => f.FileName.StartsWith("C", true, System.Globalization.CultureInfo.InvariantCulture)).ToArray();
         int maxFile       = existingFiles.Length == 0 ? 1 : existingFiles.Max(m => int.Parse(m.FileName.Substring(1, 4))) + 1;
         return(new XdcamMedia(destDirectory)
         {
             MediaName = $"C{maxFile:D4}", FileName = $"C{maxFile:D4}.MXF", Folder = "Clip", MediaStatus = TMediaStatus.Copying
         });
     }
     return(new IngestMedia(destDirectory)
     {
         MediaName = DestMediaName,
         FileName = FileUtils.GetUniqueFileName(DestDirectory.Folder,
                                                $"{FileUtils.SanitizeFileName(DestMediaName)}.{destDirectory.ExportContainerFormat}"),
         MediaStatus = TMediaStatus.Copying
     });
 }
Beispiel #4
0
        internal string GetCmdLineParams(string sourceDirectory = null, string destDirectory = null)
        {
            StringBuilder cmdText = new StringBuilder();

            if (!sourceDirectory.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" \"{0}\"", DirSafeguard(sourceDirectory));
            }
            else if (!SourceDirectory.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" \"{0}\"", DirSafeguard(SourceDirectory));
            }

            if (!destDirectory.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" \"{0}\"", DirSafeguard(destDirectory));
            }
            else if (!DestDirectory.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" \"{0}\"", DirSafeguard(DestDirectory));
            }

            if (!Files.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" {0}", Files);
            }
            else
            {
                cmdText.Append("*.*");
            }

            //Copy Options
            if (CopyNoEmptySubDirectories)
            {
                cmdText.Append(" /S");
            }
            if (CopySubDirectories)
            {
                cmdText.Append(" /E");
            }
            if (OnlyCopyNLevels > 0)
            {
                cmdText.AppendFormat(" /LEV:{0}", OnlyCopyNLevels);
            }
            if (CopyFilesRestartableMode)
            {
                cmdText.Append(" /Z");
            }
            if (CopyFilesBackupMode)
            {
                cmdText.Append(" /B");
            }
            if (FallbackCopyFilesMode)
            {
                cmdText.Append(" /ZB");
            }
            if (UnbufferredIOCopy)
            {
                cmdText.Append(" /J");
            }

            if (EncrptFileEFSRawMode)
            {
                cmdText.Append(" /EFSRAW");
            }
            if (!CopyFlags.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /COPY:{0}", (from f in CopyFlags.SplitNTrim()
                                                    where !f.IsNullOrWhiteSpace()
                                                    select((ChoCopyFlags)Enum.Parse(typeof(ChoCopyFlags), f)).ToDescription()).Join(""));
            }
            if (CopyDirTimestamp)
            {
                cmdText.Append(" /DCOPY:T");
            }
            if (CopyFilesWithSecurity)
            {
                cmdText.Append(" /SEC");
            }

            if (CopyFilesWithFileInfo)
            {
                cmdText.Append(" /COPYALL");
            }
            if (CopyFilesWithNoFileInfo)
            {
                cmdText.Append(" /NOCOPY");
            }
            if (FixFileSecurityOnFiles)
            {
                cmdText.Append(" /SECFIX");
            }
            if (FixFileTimeOnFiles)
            {
                cmdText.Append(" /TIMFIX");
            }

            if (DelDestFileDirIfNotExistsInSource)
            {
                cmdText.Append(" /PURGE");
            }
            if (MirrorDirTree)
            {
                cmdText.Append(" /MIR");
            }
            if (MoveFiles)
            {
                cmdText.Append(" /MOV");
            }
            if (MoveFilesNDirs)
            {
                cmdText.Append(" /MOVE");
            }
            if (!AddFileAttributes.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /A+:{0}", (from f in AddFileAttributes.SplitNTrim()
                                                  where !f.IsNullOrWhiteSpace()
                                                  select((ChoFileAttributes)Enum.Parse(typeof(ChoFileAttributes), f)).ToDescription()).Join(""));
            }
            if (!RemoveFileAttributes.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /A-:{0}", (from f in RemoveFileAttributes.SplitNTrim()
                                                  where !f.IsNullOrWhiteSpace()
                                                  select((ChoFileAttributes)Enum.Parse(typeof(ChoFileAttributes), f)).ToDescription()).Join(""));
            }
            if (CreateDirTree)
            {
                cmdText.Append(" /CREATE");
            }
            if (CreateFATFileNames)
            {
                cmdText.Append(" /FAT");
            }
            if (TurnOffLongPath)
            {
                cmdText.Append(" /256");
            }

            if (RunAgainWithNoChangesSeen > 0)
            {
                cmdText.AppendFormat(" /MON:{0}", RunAgainWithNoChangesSeen);
            }
            if (RunAgainWithChangesSeenInMin > 0)
            {
                cmdText.AppendFormat(" /MOT:{0}", RunAgainWithChangesSeenInMin);
            }
            if (RunHourStartTime != TimeSpan.Zero &&
                RunHourEndTime != TimeSpan.Zero &&
                RunHourStartTime < RunHourEndTime)
            {
                cmdText.AppendFormat(" /RH:{0}-{1}", RunHourStartTime.ToString("hhmm"), RunHourEndTime.ToString("hhmm"));
            }
            if (CheckRunHourPerFileBasis)
            {
                cmdText.Append(" /PF");
            }
            if (InterPacketGapInMS > 0)
            {
                cmdText.AppendFormat(" /IPG:{0}", InterPacketGapInMS);
            }
            if (CopySymbolicLinks)
            {
                cmdText.Append(" /SL");
            }
            if (MultithreadCopy > 0)
            {
                cmdText.AppendFormat(" /MT:{0}", MultithreadCopy);
            }
            if (CopyNODirInfo)
            {
                cmdText.Append(" /NODCOPY");
            }
            if (CopyWithoutWindowsCopyOffload)
            {
                cmdText.Append(" /NOOFFLOAD");
            }

            //File Selection Options
            if (CopyOnlyFilesWithArchiveAttributes)
            {
                cmdText.Append(" /A");
            }
            if (CopyOnlyFilesWithArchiveAttributesAndReset)
            {
                cmdText.Append(" /M");
            }
            if (!IncludeFilesWithGivenAttributes.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /IA:{0}", (from f in IncludeFilesWithGivenAttributes.SplitNTrim()
                                                  where !f.IsNullOrWhiteSpace()
                                                  select((ChoFileSelectionAttributes)Enum.Parse(typeof(ChoFileSelectionAttributes), f)).ToDescription()).Join(""));
            }
            if (!ExcludeFilesWithGivenAttributes.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /XA:{0}", (from f in ExcludeFilesWithGivenAttributes.SplitNTrim()
                                                  where !f.IsNullOrWhiteSpace()
                                                  select((ChoFileSelectionAttributes)Enum.Parse(typeof(ChoFileSelectionAttributes), f)).ToDescription()).Join(""));
            }
            if (!ExcludeFilesWithGivenNames.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(@" /XF {0}", String.Join(" ", ExcludeFilesWithGivenNames.Split(";").Select(f => f).Select(f => f.Contains(" ") ? String.Format(@"""{0}""", f) : f)));
            }
            if (!ExcludeDirsWithGivenNames.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(@" /XD {0}", String.Join(" ", ExcludeDirsWithGivenNames.Split(";").Select(f => f).Select(f => f.Contains(" ") ? String.Format(@"""{0}""", f) : f)));
            }
            if (ExcludeChangedFiles)
            {
                cmdText.Append(" /XC");
            }
            if (ExcludeNewerFiles)
            {
                cmdText.Append(" /XN");
            }
            if (ExcludeOlderFiles)
            {
                cmdText.Append(" /XO");
            }
            if (ExcludeExtraFilesAndDirs)
            {
                cmdText.Append(" /XX");
            }
            if (ExcludeLonelyFilesAndDirs)
            {
                cmdText.Append(" /XL");
            }
            if (IncludeSameFiles)
            {
                cmdText.Append(" /IS");
            }
            if (IncludeTweakedFiles)
            {
                cmdText.Append(" /IT");
            }

            if (ExcludeFilesBiggerThanNBytes > 0)
            {
                cmdText.AppendFormat(" /MAX:{0}", ExcludeFilesBiggerThanNBytes);
            }
            if (ExcludeFilesSmallerThanNBytes > 0)
            {
                cmdText.AppendFormat(" /MIN:{0}", ExcludeFilesSmallerThanNBytes);
            }

            if (ExcludeFilesOlderThanNDays > 0)
            {
                cmdText.AppendFormat(" /MAXAGE:{0}", ExcludeFilesOlderThanNDays);
            }
            if (ExcludeFilesNewerThanNDays > 0)
            {
                cmdText.AppendFormat(" /MINAGE:{0}", ExcludeFilesNewerThanNDays);
            }
            if (ExcludeFilesUnusedSinceNDays > 0)
            {
                cmdText.AppendFormat(" /MAXLAD:{0}", ExcludeFilesUnusedSinceNDays);
            }
            if (ExcludeFilesUsedSinceNDays > 0)
            {
                cmdText.AppendFormat(" /MINLAD:{0}", ExcludeFilesUsedSinceNDays);
            }

            if (ExcludeJunctionPoints)
            {
                cmdText.Append(" /XJ");
            }
            if (AssumeFATFileTimes)
            {
                cmdText.Append(" /FFT");
            }
            if (CompensateOneHourDSTTimeDiff)
            {
                cmdText.Append(" /DST");
            }
            if (ExcludeJunctionPointsForDirs)
            {
                cmdText.Append(" /XJD");
            }
            if (ExcludeJunctionPointsForFiles)
            {
                cmdText.Append(" /XJF");
            }

            //Retry Options
            if (NoOfRetries.ToString() != DefaultNoOfRetries && NoOfRetries >= 0)
            {
                cmdText.AppendFormat(" /R:{0}", NoOfRetries);
            }
            if (WaitTimeBetweenRetries.ToString() != DefaultWaitTimeBetweenRetries && WaitTimeBetweenRetries >= 0)
            {
                cmdText.AppendFormat(" /W:{0}", WaitTimeBetweenRetries);
            }
            if (SaveRetrySettingsToRegistry)
            {
                cmdText.Append(" /REG");
            }
            if (WaitForSharenames)
            {
                cmdText.Append(" /TBD");
            }

            //Logging Options
            if (ListOnly)
            {
                cmdText.Append(" /L");
            }
            if (ReportExtraFiles)
            {
                cmdText.Append(" /X");
            }
            if (VerboseOutput)
            {
                cmdText.Append(" /V");
            }
            if (IncludeSourceFileTimestamp)
            {
                cmdText.Append(" /TS");
            }
            if (IncludeFullPathName)
            {
                cmdText.Append(" /FP");
            }
            if (PrintByteSizes)
            {
                cmdText.Append(" /BYTES");
            }
            if (NoFileSizeLog)
            {
                cmdText.Append(" /NS");
            }
            if (NoFileClassLog)
            {
                cmdText.Append(" /NC");
            }
            if (NoFileNameLog)
            {
                cmdText.Append(" /NFL");
            }
            if (NoDirListLog)
            {
                cmdText.Append(" /NDL");
            }
            if (NoProgress)
            {
                cmdText.Append(" /NP");
            }
            if (ShowEstTimeOfArrival)
            {
                cmdText.Append(" /ETA");
            }
            if (!OutputLogFilePath.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /LOG:\"{0}\"", OutputLogFilePath);
            }
            if (!AppendOutputLogFilePath.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /LOG+:\"{0}\"", AppendOutputLogFilePath);
            }
            if (!UnicodeOutputLogFilePath.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /UNILOG:\"{0}\"", UnicodeOutputLogFilePath);
            }
            if (!AppendUnicodeOutputLogFilePath.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /UNILOG+:\"{0}\"", AppendUnicodeOutputLogFilePath);
            }
            if (NoJobHeader)
            {
                cmdText.Append(" /NJH");
            }
            if (NoJobSummary)
            {
                cmdText.Append(" /NJS");
            }

            if (!AdditionalParams.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" {0}", AdditionalParams);
            }

            return(cmdText.ToString());
        }
Beispiel #5
0
        IngestMedia _createDestMedia(IngestDirectory destDirectory)
        {
            if (destDirectory.IsXDCAM)
            {
                var existingFiles = DestDirectory.GetFiles().Where(f => f.FileName.StartsWith("C", true, System.Globalization.CultureInfo.InvariantCulture));
                int maxFile       = existingFiles.Count() == 0 ? 1 : existingFiles.Max(m => int.Parse(m.FileName.Substring(1, 4))) + 1;
                return(new XDCAMMedia(destDirectory)
                {
                    MediaName = string.Format("C{0:D4}", maxFile), FileName = string.Format("C{0:D4}.MXF", maxFile), Folder = "Clip", MediaStatus = TMediaStatus.Copying
                });
            }
            else
            {
                return new IngestMedia(destDirectory)
                       {
                           MediaName   = DestMediaName,
                           FileName    = Common.FileUtils.GetUniqueFileName(DestDirectory.Folder, string.Format("{0}.{1}", DestMediaName, destDirectory.ExportContainerFormat)),
                           MediaStatus = TMediaStatus.Copying
                       }
            };
        }

        void destMedia_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(IMedia.FileSize))
            {
                ulong fs = _progressFileSize;

                if (fs > 0 && sender is Media)
                {
                    Progress = (int)(((sender as Media).FileSize * 100ul) / fs);
                }
            }
        }

        bool _encode(IngestDirectory directory, string outFile)
        {
            Debug.WriteLine(this, "Export encode started");
            AddOutputMessage($"Encode started to file {outFile}");
            StringBuilder          files = new StringBuilder();
            int                    index = 0;
            List <string>          complexFilterElements = new List <string>();
            List <string>          volumeFilterElements  = new List <string>();
            StringBuilder          overlayOutputs        = new StringBuilder();
            List <ExportMedia>     exportMedia           = _exportMediaList.ToList();
            TimeSpan               startTimecode         = exportMedia.First().StartTC;
            VideoFormatDescription outputFormatDesc      = VideoFormatDescription.Descriptions[directory.IsXDCAM || directory.ExportContainerFormat == TMovieContainerFormat.mxf ? TVideoFormat.PAL : directory.ExportVideoFormat];
            string                 scaleFilter           = $"scale={outputFormatDesc.ImageSize.Width}:{outputFormatDesc.ImageSize.Height}:interl=-1";

            foreach (var e in exportMedia)
            {
                Media media = e.Media as Media;
                if (media != null)
                {
                    files.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, " -ss {0} -t {1} -i \"{2}\"", (e.StartTC - media.TcStart).TotalSeconds, e.Duration.TotalSeconds, media.FullPath);
                    string        videoOutputName  = $"[v{index}]";
                    List <string> itemVideoFilters = new List <string>();
                    if (((Media)media).HasExtraLines)
                    {
                        itemVideoFilters.Add("crop=720:576:0:32");
                    }
                    itemVideoFilters.Add(media.FormatDescription().IsWideScreen ? "setdar=dar=16/9" : "setdar=dar=4/3");
                    itemVideoFilters.Add(scaleFilter);
                    complexFilterElements.Add($"[{index}]{string.Join(",", itemVideoFilters)}{videoOutputName}");
                    int audioIndex = index;
                    complexFilterElements.Add(string.Format(System.Globalization.CultureInfo.InvariantCulture, "[{0}]volume={1:F3}dB[a{0}]", audioIndex, e.AudioVolume));
                    index++;
                    for (int i = 0; i < e.Logos.Length; i++)
                    {
                        Media logo = e.Logos[i] as Media;
                        if (logo != null)
                        {
                            files.Append($" -i \"{logo.FullPath}\"");
                            string newOutputName = $"[v{index}]";
                            complexFilterElements.Add($"{videoOutputName}[{index}]overlay{newOutputName}");
                            videoOutputName = newOutputName;
                            index++;
                        }
                    }
                    overlayOutputs.AppendFormat("{0}[a{1}]", videoOutputName, audioIndex);
                }
            }
            if (directory.IsXDCAM || directory.ExportContainerFormat == TMovieContainerFormat.mxf)
            {
                if (MXFVideoExportFormat == TmXFVideoExportFormat.DV25)
                {
                    complexFilterElements.Add(string.Format("{0}concat=n={1}:v=1:a=1[v][p]", string.Join(string.Empty, overlayOutputs), exportMedia.Count));
                }
                else
                {
                    complexFilterElements.Add(string.Format("{0}concat=n={1}:v=1:a=1[vr][p], [vr]{2}[v]", string.Join(string.Empty, overlayOutputs), exportMedia.Count, D10_PAD_FILTER));
                }
            }
            else
            {
                complexFilterElements.Add(string.Format("{0}concat=n={1}:v=1:a=1[v][p]", string.Join(string.Empty, overlayOutputs), exportMedia.Count));
            }
            complexFilterElements.Add("[p]apad=pad_len=1024[a]");
            string complexFilter = complexFilterElements.Count > 0 ?
                                   string.Format(" -filter_complex \"{0}\"", string.Join(", ", complexFilterElements)) :
                                   string.Empty;
            string command = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                           "{0}{1} -map \"[v]\" -map \"[a]\" {2} -timecode {3}{4} -shortest -f {5} -y \"{6}\"",
                                           //0
                                           files.ToString(),
                                           //1
                                           complexFilter,
                                           //2
                                           directory.IsXDCAM || directory.ExportContainerFormat == TMovieContainerFormat.mxf ?
                                           String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} {1}",
                                                         MXFVideoExportFormat == TmXFVideoExportFormat.DV25 ? D10_PAL_DV25
                            : MXFVideoExportFormat == TmXFVideoExportFormat.IMX30 ? D10_PAL_IMX30
                            : MXFVideoExportFormat == TmXFVideoExportFormat.IMX40 ? D10_PAL_IMX40
                            : D10_PAL_IMX50
                                                         ,
                                                         MXFAudioExportFormat == TmXFAudioExportFormat.Channels4Bits24 ? PCM24LE4CH
                            : MXFAudioExportFormat == TmXFAudioExportFormat.Channels4Bits16 ? PCM16LE4CH
                            : PCM16LE8CH)
                    :
                                           directory.ExportParams,
                                           //3
                                           startTimecode.ToSMPTETimecodeString(VideoFormatDescription.Descriptions[DestMedia.VideoFormat].FrameRate),
                                           //4
                                           directory.IsXDCAM || directory.ExportContainerFormat == TMovieContainerFormat.mxf ? $" -metadata creation_time=\"{DateTime.UtcNow.ToString("o")}\"" : string.Empty,
                                           //5
                                           (directory.IsXDCAM || directory.ExportContainerFormat == TMovieContainerFormat.mxf) && MXFVideoExportFormat != TmXFVideoExportFormat.DV25 ? "mxf_d10" : directory.ExportContainerFormat.ToString(),
                                           outFile);

            if (RunProcess(command))
            {
                Debug.WriteLine(this, "Export encode succeed");
                AddOutputMessage("Encode finished successfully");
                return(true);
            }
            Debug.WriteLine("FFmpeg _encode(): Failed for {0}", outFile);
            return(false);
        }