hudl / HudlFfmpeg

Hudl.Ffmpeg framework
Apache License 2.0
113 stars 32 forks source link

Raw data as InputStream #59

Closed seijikun closed 5 years ago

seijikun commented 8 years ago

Is it possible to use raw data without a container (like pcm for raw audio) as input at the moment? What I got:

var commandFactory = CommandFactory.Create();
var cmd = commandFactory.CreateOutputCommand();
var inSettings = SettingsCollection.ForInput(new FormatInput("u16le"), new SampleRate(44100));
var mp3Settings = SettingsCollection.ForOutput(new BitRateAudio(Hudl.FFmpeg.Enums.AudioBitRateType.Mp3Cd));

cmd.AddInput("input.raw", inSettings);
cmd.To<Mp3>(mp3Settings);
commandFactory.Render();

But, obviously, since the file extension is not registered, I get a:

System.InvalidOperationException: Cannot derive resource type from path provided.
  at Hudl.FFmpeg.Resources.Resource.From (System.String filePath, System.String fileName) [0x0007d] in HudlFfmpeg/Hudl.Ffmpeg/Resources/Resource.cs:95 
  at Hudl.FFmpeg.Resources.Resource.From (System.String fullPath) [0x00011] in HudlFfmpeg/Hudl.Ffmpeg/Resources/Resource.cs:75 
  at Hudl.FFmpeg.Sugar.FFmpegCommandExtensions.AddInput (Hudl.FFmpeg.Command.FFmpegCommand command, System.String fileName, Hudl.FFmpeg.Settings.BaseTypes.SettingsCollection settings) [0x00009] in HudlFfmpeg/Hudl.Ffmpeg/Sugar/FfmpegCommandExtensions.cs:42
Casey-Bateman commented 8 years ago

@seijikun it's not currently possible with the containers available. However if you were to implement a Raw container it would allow you to as long as ffmpeg supports it. implimentation would look like the following:

    [ContainsStream(Type = typeof(AudioStream))]
    [ContainsStream(Type = typeof(VideoStream))]
    public class Raw : BaseContainer
    {
        private const string FileFormat = ".raw";

        public Raw()
            : base(FileFormat)
        {
        }

        protected override IContainer Clone()
        {
            return new Raw();
        }
    }
Casey-Bateman commented 8 years ago

As a side note, if you would like to contribute to the ffmpeg project and add this in, I would not be opposed to merging in the next release

seijikun commented 8 years ago

The system as it is at the moment has not been designed with the possibility of working indipendently of the file-extension at the moment, right?

Casey-Bateman commented 8 years ago

@seijikun correct