Exemplo n.º 1
0
 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
     });
 }
Exemplo n.º 2
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);
        }