/// <summary> /// Creates a stream which binds an input file to a codec configuration. /// The stream is used for muxings later on.<para /> /// /// API endpoint: /// https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsStreamsByEncodingId /// </summary> /// <param name="encoding">The encoding to add the stream onto</param> /// <param name="input">The input that should be used</param> /// <param name="inputPath">The path to the input file</param> /// <param name="configuration">The codec configuration to be applied to the stream</param> private Task <Stream> CreateStream(Models.Encoding encoding, Input input, string inputPath, CodecConfiguration configuration) { var streamInput = new StreamInput() { InputId = input.Id, InputPath = inputPath, SelectionMode = StreamSelectionMode.AUTO }; var stream = new Stream() { InputStreams = new List <StreamInput>() { streamInput }, CodecConfigId = configuration.Id }; return(_bitmovinApi.Encoding.Encodings.Streams.CreateAsync(encoding.Id, stream)); }
/// <summary> /// Initializes a new instance. /// </summary> private void Initialize() { Log.Debug("BassAudioFileInputSource.Initialize()"); BASSFlag flags = BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT; int handle; ILocalFsResourceAccessor lfra = _accessor as ILocalFsResourceAccessor; if (lfra == null) { // Build stream reading procs for the resource's input stream flags |= BASSFlag.BASS_STREAM_PRESCAN; _streamInput = new StreamInput(_accessor.OpenRead()); handle = Bass.BASS_StreamCreateFileUser( BASSStreamSystem.STREAMFILE_NOBUFFER, flags, _streamInput.FileProcs, IntPtr.Zero); } else // Optimize access to local filesystem resource using (lfra.EnsureLocalFileSystemAccess()) handle = Bass.BASS_StreamCreateFile(lfra.LocalFileSystemPath, 0, 0, flags); if (handle == BassConstants.BassInvalidHandle) throw new BassLibraryException("BASS_StreamCreateFile"); _BassStream = BassStream.Create(handle); }
public void Execute() { Progress(0.0, 1.0); if (string.IsNullOrEmpty(settings.TargetFilename)) { GuiLogMessage("You have to select a target filename before using this plugin as output.", NotificationLevel.Error); return; } if (StreamInput == null) { GuiLogMessage("Received null value for ICryptoolStream.", NotificationLevel.Warning); return; } Progress(0.5, 1.0); using (CStreamReader reader = StreamInput.CreateReader()) { // If target file was selected we have to copy the input to target. # region copyToTarget if (settings.TargetFilename != null) { InputFile = settings.TargetFilename; try { fileOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate { fileOutputPresentation. CloseFileToGetFileStreamForExecution(); }, null); FileStream fs; if (!settings.Append) { fs = new FileStream(settings.TargetFilename, FileMode.Create); } else { fs = new FileStream(settings.TargetFilename, FileMode.Append); for (int i = 0; i < settings.AppendBreaks; i++) { const string nl = "\n"; fs.Write(Encoding.ASCII.GetBytes(nl), 0, Encoding.ASCII.GetByteCount(nl)); } } var byteValues = new byte[1024]; int byteRead; long position = fs.Position; GuiLogMessage("Start writing to target file now: " + settings.TargetFilename, NotificationLevel.Debug); while ((byteRead = reader.Read(byteValues, 0, byteValues.Length)) != 0) { fs.Write(byteValues, 0, byteRead); if (OnPluginProgressChanged != null && reader.Length > 0 && (int)(reader.Position * 100 / reader.Length) > position) { position = (int)(reader.Position * 100 / reader.Length); Progress(reader.Position, reader.Length); } } fs.Flush(); fs.Close(); GuiLogMessage("Finished writing: " + settings.TargetFilename, NotificationLevel.Debug); } catch (Exception ex) { GuiLogMessage(ex.Message, NotificationLevel.Error); settings.TargetFilename = null; } } # endregion copyToTarget
protected override void Dispose(bool isDisposing) { _fileMutex.WaitOne(); try { var fileName = _name; long originalLength = 0; //this can be null in some odd cases so we need to check if (_indexOutput != null) { try { // make sure it's all written out _indexOutput.Flush(); originalLength = _indexOutput.Length; } finally { _indexOutput.Dispose(); } } if (originalLength > 0) { Stream blobStream; // optionally put a compressor around the blob stream if (_azureDirectory.ShouldCompressFile(_name)) { blobStream = CompressStream(fileName, originalLength); } else { blobStream = new StreamInput(CacheDirectory.OpenInput(fileName)); } try { // push the blobStream up to the cloud _blob.UploadFromStream(blobStream); // set the metadata with the original index file properties _blob.Metadata["CachedLength"] = originalLength.ToString(); _blob.Metadata["CachedLastModified"] = CacheDirectory.FileModified(fileName).ToString(); _blob.SetMetadata(); #if FULLDEBUG Trace.WriteLine($"PUT {blobStream.Length} bytes to {_name} in cloud"); #endif } finally { blobStream.Dispose(); } #if FULLDEBUG Trace.WriteLine($"CLOSED WRITESTREAM {_name}"); #endif } // clean up _indexOutput = null; //_blobContainer = null; _blob = null; GC.SuppressFinalize(this); } finally { _fileMutex.ReleaseMutex(); } }