fixed #244: Video source can be "None" which allows to only record sound

This commit is contained in:
Jaex 2014-08-29 11:22:51 +03:00
parent 6b5eb462ab
commit e2627e149a
4 changed files with 64 additions and 51 deletions

View file

@ -38,7 +38,8 @@ namespace ScreenCaptureLib
public class FFmpegHelper : ExternalCLIManager
{
public static readonly int libmp3lame_qscale_end = 9;
public static readonly string GDIgrab = "GDI grab";
public static readonly string SourceNone = "None";
public static readonly string SourceGDIGrab = "GDI grab";
public StringBuilder Output { get; private set; }
public ScreencastOptions Options { get; private set; }

View file

@ -59,8 +59,8 @@ public class FFmpegOptions
public FFmpegOptions()
{
// General
VideoSource = FFmpegHelper.GDIgrab;
AudioSource = "None";
VideoSource = FFmpegHelper.SourceGDIGrab;
AudioSource = FFmpegHelper.SourceNone;
VideoCodec = FFmpegVideoCodec.libx264;
AudioCodec = FFmpegAudioCodec.libvoaacenc;
Extension = "mp4";
@ -84,9 +84,14 @@ public FFmpegOptions()
MP3_qscale = 4;
}
public bool IsVideoSourceSelected()
{
return !string.IsNullOrEmpty(VideoSource) && !VideoSource.Equals(FFmpegHelper.SourceNone, StringComparison.InvariantCultureIgnoreCase);
}
public bool IsAudioSourceSelected()
{
return !string.IsNullOrEmpty(AudioSource) && !AudioSource.Equals("None", StringComparison.InvariantCultureIgnoreCase);
return !string.IsNullOrEmpty(AudioSource) && !AudioSource.Equals(FFmpegHelper.SourceNone, StringComparison.InvariantCultureIgnoreCase);
}
}
}

View file

@ -121,9 +121,10 @@ private void RefreshSourcesAsync()
() =>
{
cboVideoSource.Items.Clear();
cboVideoSource.Items.Add(FFmpegHelper.GDIgrab);
cboVideoSource.Items.Add(FFmpegHelper.SourceNone);
cboVideoSource.Items.Add(FFmpegHelper.SourceGDIGrab);
cboAudioSource.Items.Clear();
cboAudioSource.Items.Add("None");
cboAudioSource.Items.Add(FFmpegHelper.SourceNone);
if (devices != null)
{
cboVideoSource.Items.AddRange(devices.VideoDevices.ToArray());

View file

@ -85,69 +85,76 @@ public string GetFFmpegCommands()
public string GetFFmpegArgs(bool isCustom = false)
{
if (!FFmpeg.IsVideoSourceSelected() && !FFmpeg.IsAudioSourceSelected())
{
return null;
}
StringBuilder args = new StringBuilder();
// -y for overwrite file
args.Append("-y ");
// default real time buffer size was 3041280 (3M)
args.Append("-rtbufsize 100M ");
args.Append("-y "); // -y for overwrite file
args.Append("-rtbufsize 100M "); // default real time buffer size was 3041280 (3M)
string fps = isCustom ? "$fps$" : ScreenRecordFPS.ToString();
if (string.IsNullOrEmpty(FFmpeg.VideoSource) || FFmpeg.VideoSource.Equals(FFmpegHelper.GDIgrab, StringComparison.InvariantCultureIgnoreCase))
if (FFmpeg.IsVideoSourceSelected())
{
// http://ffmpeg.org/ffmpeg-devices.html#gdigrab
args.AppendFormat("-f gdigrab -framerate {0} -offset_x {1} -offset_y {2} -video_size {3}x{4} -draw_mouse {5} -i desktop ",
fps, isCustom ? "$area_x$" : CaptureArea.X.ToString(), isCustom ? "$area_y$" : CaptureArea.Y.ToString(),
isCustom ? "$area_width$" : CaptureArea.Width.ToString(), isCustom ? "$area_height$" : CaptureArea.Height.ToString(),
isCustom ? "$cursor$" : DrawCursor ? "1" : "0");
if (FFmpeg.IsAudioSourceSelected())
if (FFmpeg.VideoSource.Equals(FFmpegHelper.SourceGDIGrab, StringComparison.InvariantCultureIgnoreCase))
{
args.AppendFormat("-f dshow -i audio=\"{0}\" ", FFmpeg.AudioSource);
}
}
else
{
args.AppendFormat("-f dshow -framerate {0} -i video=\"{1}\"", fps, FFmpeg.VideoSource);
// http://ffmpeg.org/ffmpeg-devices.html#gdigrab
args.AppendFormat("-f gdigrab -framerate {0} -offset_x {1} -offset_y {2} -video_size {3}x{4} -draw_mouse {5} -i desktop ",
fps, isCustom ? "$area_x$" : CaptureArea.X.ToString(), isCustom ? "$area_y$" : CaptureArea.Y.ToString(),
isCustom ? "$area_width$" : CaptureArea.Width.ToString(), isCustom ? "$area_height$" : CaptureArea.Height.ToString(),
isCustom ? "$cursor$" : DrawCursor ? "1" : "0");
if (FFmpeg.IsAudioSourceSelected())
{
args.AppendFormat(":audio=\"{0}\" ", FFmpeg.AudioSource);
if (FFmpeg.IsAudioSourceSelected())
{
args.AppendFormat("-f dshow -i audio=\"{0}\" ", FFmpeg.AudioSource);
}
}
else
{
args.Append(" ");
args.AppendFormat("-f dshow -framerate {0} -i video=\"{1}\"", fps, FFmpeg.VideoSource);
if (FFmpeg.IsAudioSourceSelected())
{
args.AppendFormat(":audio=\"{0}\" ", FFmpeg.AudioSource);
}
else
{
args.Append(" ");
}
}
}
else if (FFmpeg.IsAudioSourceSelected())
{
args.AppendFormat("-f dshow -i audio=\"{0}\" ", FFmpeg.AudioSource);
}
if (!string.IsNullOrEmpty(FFmpeg.UserArgs))
{
args.Append(FFmpeg.UserArgs + " ");
}
args.AppendFormat("-c:v {0} ", FFmpeg.VideoCodec.ToString());
// output FPS
args.AppendFormat("-r {0} ", fps);
switch (FFmpeg.VideoCodec)
if (FFmpeg.IsVideoSourceSelected())
{
case FFmpegVideoCodec.libx264: // https://trac.ffmpeg.org/wiki/x264EncodingGuide
args.AppendFormat("-crf {0} ", FFmpeg.x264_CRF);
args.AppendFormat("-preset {0} ", FFmpeg.Preset.ToString());
args.AppendFormat("-tune {0} ", "zerolatency");
args.AppendFormat("-c:v {0} ", FFmpeg.VideoCodec.ToString());
args.AppendFormat("-r {0} ", fps); // output FPS
// -pix_fmt yuv420p required otherwise can't stream in Chrome
args.Append("-pix_fmt yuv420p ");
break;
case FFmpegVideoCodec.libvpx: // https://trac.ffmpeg.org/wiki/vpxEncodingGuide
args.AppendFormat("-crf {0} ", FFmpeg.VPx_CRF);
break;
case FFmpegVideoCodec.libxvid: // https://trac.ffmpeg.org/wiki/How%20to%20encode%20Xvid%20/%20DivX%20video%20with%20ffmpeg
args.AppendFormat("-qscale:v {0} ", FFmpeg.XviD_qscale);
break;
switch (FFmpeg.VideoCodec)
{
case FFmpegVideoCodec.libx264: // https://trac.ffmpeg.org/wiki/x264EncodingGuide
args.AppendFormat("-crf {0} ", FFmpeg.x264_CRF);
args.AppendFormat("-preset {0} ", FFmpeg.Preset.ToString());
args.AppendFormat("-tune {0} ", "zerolatency");
args.Append("-pix_fmt yuv420p "); // -pix_fmt yuv420p required otherwise can't stream in Chrome
break;
case FFmpegVideoCodec.libvpx: // https://trac.ffmpeg.org/wiki/vpxEncodingGuide
args.AppendFormat("-crf {0} ", FFmpeg.VPx_CRF);
break;
case FFmpegVideoCodec.libxvid: // https://trac.ffmpeg.org/wiki/How%20to%20encode%20Xvid%20/%20DivX%20video%20with%20ffmpeg
args.AppendFormat("-qscale:v {0} ", FFmpeg.XviD_qscale);
break;
}
}
if (FFmpeg.IsAudioSourceSelected())
@ -168,8 +175,7 @@ public string GetFFmpegArgs(bool isCustom = false)
if (Duration > 0)
{
// duration limit
args.AppendFormat("-t {0} ", isCustom ? "$duration$" : Duration.ToString("0.0", CultureInfo.InvariantCulture));
args.AppendFormat("-t {0} ", isCustom ? "$duration$" : Duration.ToString("0.0", CultureInfo.InvariantCulture)); // duration limit
}
args.AppendFormat("\"{0}\"", isCustom ? "$output$" : Path.ChangeExtension(OutputPath, FFmpeg.Extension));