mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-02 21:20:28 +12:00
Added duration support for FFmpegCLI
This commit is contained in:
parent
a7870ee5fc
commit
c97f35aa29
|
@ -61,6 +61,9 @@ public virtual int Open(string path, string args = null)
|
|||
psi.Arguments = args;
|
||||
psi.WorkingDirectory = Path.GetDirectoryName(path);
|
||||
|
||||
Console.WriteLine("Path: " + path);
|
||||
Console.WriteLine("Args: " + psi.Arguments);
|
||||
|
||||
process.EnableRaisingEvents = true;
|
||||
process.OutputDataReceived += cli_OutputDataReceived;
|
||||
process.ErrorDataReceived += cli_ErrorDataReceived;
|
||||
|
|
|
@ -83,25 +83,37 @@ public bool Record(Rectangle captureRectangle)
|
|||
// output FPS
|
||||
args.AppendFormat("-r {0} ", Options.FPS);
|
||||
|
||||
args.Append(string.Format("-c:v {0} ", Options.FFmpegCLI.VideoCodec.ToString()));
|
||||
args.AppendFormat("-c:v {0} ", Options.FFmpegCLI.VideoCodec.ToString());
|
||||
|
||||
// https://trac.ffmpeg.org/wiki/x264EncodingGuide
|
||||
switch (Options.FFmpegCLI.VideoCodec)
|
||||
{
|
||||
case FFmpegVideoCodec.libx264:
|
||||
case FFmpegVideoCodec.libvpx:
|
||||
args.AppendFormat("-crf {0} ", Options.FFmpegCLI.Quantizer);
|
||||
args.AppendFormat("-preset {0} ", Options.FFmpegCLI.Preset.ToString());
|
||||
break;
|
||||
case FFmpegVideoCodec.libvpx:
|
||||
args.AppendFormat("-crf {0} ", Options.FFmpegCLI.Quantizer);
|
||||
break;
|
||||
case FFmpegVideoCodec.libxvid:
|
||||
args.AppendFormat("-qscale:v {0} ", Options.FFmpegCLI.Quantizer);
|
||||
break;
|
||||
case FFmpegVideoCodec.mpeg4:
|
||||
args.Append("-vtag xvid ");
|
||||
args.Append(string.Format("-qscale:v {0} ", Options.FFmpegCLI.Quantizer));
|
||||
args.AppendFormat("-qscale:v {0} ", Options.FFmpegCLI.Quantizer);
|
||||
break;
|
||||
}
|
||||
|
||||
// -pix_fmt yuv420p required otherwise can't stream in Chrome
|
||||
args.Append("-pix_fmt yuv420p ");
|
||||
|
||||
if (Options.Duration > 0)
|
||||
{
|
||||
args.AppendFormat("-t {0} ", Options.Duration);
|
||||
}
|
||||
|
||||
// -y for overwrite file
|
||||
args.AppendFormat("-pix_fmt yuv420p -y \"{0}\"", Path.ChangeExtension(Options.OutputPath, Options.FFmpegCLI.Extension));
|
||||
args.AppendFormat("-y \"{0}\"", Path.ChangeExtension(Options.OutputPath, Options.FFmpegCLI.Extension));
|
||||
|
||||
int result = Open(Options.FFmpegCLI.CLIPath, args.ToString());
|
||||
return result == 0;
|
||||
|
|
|
@ -101,7 +101,7 @@ private set
|
|||
private FFmpegCLIHelper ffMpegCli;
|
||||
private bool stopRequest;
|
||||
|
||||
public ScreenRecorder(ScreencastOptions options, float durationSeconds, Rectangle captureRectangle, ScreenRecordOutput outputType)
|
||||
public ScreenRecorder(ScreencastOptions options, Rectangle captureRectangle, ScreenRecordOutput outputType)
|
||||
{
|
||||
if (string.IsNullOrEmpty(options.OutputPath))
|
||||
{
|
||||
|
@ -109,7 +109,7 @@ public ScreenRecorder(ScreencastOptions options, float durationSeconds, Rectangl
|
|||
}
|
||||
|
||||
FPS = options.FPS;
|
||||
DurationSeconds = durationSeconds;
|
||||
DurationSeconds = options.Duration;
|
||||
CaptureRectangle = captureRectangle;
|
||||
CachePath = options.OutputPath;
|
||||
OutputType = outputType;
|
||||
|
|
|
@ -37,6 +37,7 @@ public class ScreencastOptions
|
|||
public string OutputPath;
|
||||
public int FPS;
|
||||
public Size Size;
|
||||
public float Duration;
|
||||
|
||||
public IntPtr ParentWindow;
|
||||
public bool ShowAVIOptionsDialog;
|
||||
|
|
|
@ -154,19 +154,18 @@ public async void StartRecording(TaskSettings TaskSettings)
|
|||
path = Program.ScreenRecorderCacheFilePath;
|
||||
}
|
||||
|
||||
float duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0;
|
||||
|
||||
ScreencastOptions options = new ScreencastOptions()
|
||||
{
|
||||
Size = CaptureRectangle.Size,
|
||||
FPS = TaskSettings.CaptureSettings.ScreenRecordFPS,
|
||||
OutputPath = path,
|
||||
Duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0,
|
||||
AVI = TaskSettings.CaptureSettings.AVIOptions,
|
||||
FFmpegCLI = TaskSettings.CaptureSettings.FFmpegCLIOptions,
|
||||
FFmpegNet = TaskSettings.CaptureSettings.FFmpegNetOptions
|
||||
};
|
||||
|
||||
screenRecorder = new ScreenRecorder(options, duration, CaptureRectangle, TaskSettings.CaptureSettings.ScreenRecordOutput);
|
||||
screenRecorder = new ScreenRecorder(options, CaptureRectangle, TaskSettings.CaptureSettings.ScreenRecordOutput);
|
||||
|
||||
int delay = (int)(TaskSettings.CaptureSettings.ScreenRecordStartDelay * 1000);
|
||||
|
||||
|
|
Loading…
Reference in a new issue