mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
9773828a62
commit
b0f46bc289
3 changed files with 109 additions and 0 deletions
|
@ -17,6 +17,7 @@ public enum ImageType
|
|||
public static class VideoLibrary
|
||||
{
|
||||
public static readonly FileInfo LocalVideo = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}input.mp4");
|
||||
public static readonly FileInfo LocalVideoWebm = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}input.webm");
|
||||
public static readonly FileInfo LocalVideoAudioOnly = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio_only.mp4");
|
||||
public static readonly FileInfo LocalVideoNoAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}mute.mp4");
|
||||
public static readonly FileInfo LocalAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio.mp3");
|
||||
|
|
|
@ -63,6 +63,61 @@ public bool Convert(VideoType type, bool multithreaded = false, VideoSize size =
|
|||
}
|
||||
}
|
||||
|
||||
private void ConvertFromStreamPipe(VideoType type, ArgumentContainer container)
|
||||
{
|
||||
var output = Input.OutputLocation(type);
|
||||
|
||||
try
|
||||
{
|
||||
var input = VideoInfo.FromFileInfo(VideoLibrary.LocalVideoWebm);
|
||||
using (var inputStream = System.IO.File.OpenRead(input.FullName))
|
||||
{
|
||||
var pipeSource = new StreamPipeSource(inputStream);
|
||||
var arguments = new ArgumentContainer { new InputPipeArgument(pipeSource) };
|
||||
foreach (var arg in container)
|
||||
{
|
||||
arguments.Add(arg.Value);
|
||||
}
|
||||
arguments.Add(new OutputArgument(output));
|
||||
|
||||
var scaling = container.Find<ScaleArgument>();
|
||||
|
||||
Encoder.Convert(arguments);
|
||||
|
||||
var outputVideo = new VideoInfo(output.FullName);
|
||||
|
||||
Assert.IsTrue(File.Exists(output.FullName));
|
||||
Assert.IsTrue(Math.Abs((outputVideo.Duration - input.Duration).TotalMilliseconds) < 1000.0 / input.FrameRate);
|
||||
|
||||
if (scaling == null)
|
||||
{
|
||||
Assert.AreEqual(outputVideo.Width, input.Width);
|
||||
Assert.AreEqual(outputVideo.Height, input.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scaling.Value.Width != -1)
|
||||
{
|
||||
Assert.AreEqual(outputVideo.Width, scaling.Value.Width);
|
||||
}
|
||||
|
||||
if (scaling.Value.Height != -1)
|
||||
{
|
||||
Assert.AreEqual(outputVideo.Height, scaling.Value.Height);
|
||||
}
|
||||
|
||||
Assert.AreNotEqual(outputVideo.Width, input.Width);
|
||||
Assert.AreNotEqual(outputVideo.Height, input.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(output.FullName))
|
||||
File.Delete(output.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
public void Convert(VideoType type, ArgumentContainer container)
|
||||
{
|
||||
var output = Input.OutputLocation(type);
|
||||
|
@ -193,6 +248,13 @@ public void Video_ToMP4_Args_Pipe()
|
|||
ConvertFromPipe(VideoType.Mp4, container);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Video_ToMP4_Args_StreamPipe()
|
||||
{
|
||||
var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) };
|
||||
ConvertFromStreamPipe(VideoType.Mp4, container);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Video_ToTS()
|
||||
{
|
||||
|
|
46
FFMpegCore/FFMPEG/Pipes/StreamPipeSource.cs
Normal file
46
FFMpegCore/FFMPEG/Pipes/StreamPipeSource.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Pipes
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IPipeSource"/> used for stream redirection
|
||||
/// </summary>
|
||||
public class StreamPipeSource : IPipeSource
|
||||
{
|
||||
public System.IO.Stream Source { get; private set; }
|
||||
public int BlockSize { get; set; } = 4096;
|
||||
|
||||
public StreamPipeSource(System.IO.Stream stream)
|
||||
{
|
||||
Source = stream;
|
||||
}
|
||||
|
||||
public void FlushData(System.IO.Stream pipe)
|
||||
{
|
||||
var buffer = new byte[BlockSize];
|
||||
int read;
|
||||
while ((read = Source.Read(buffer, 0, buffer.Length)) != 0)
|
||||
{
|
||||
pipe.Write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task FlushDataAsync(System.IO.Stream pipe)
|
||||
{
|
||||
var buffer = new byte[BlockSize];
|
||||
int read;
|
||||
while ((read = await Source.ReadAsync(buffer, 0, buffer.Length)) != 0)
|
||||
{
|
||||
await pipe.WriteAsync(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetFormat()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue