Skip to content

Commit

Permalink
2.4.0
Browse files Browse the repository at this point in the history
Update FFmpeg to current latest version.

Fix #51 (Thank you for figuring this one out @altbdoor)
Save as MP4; closes #50 (Thank you @dannyblank)
Save as GIF #49 (Thank you @megapctr)
  • Loading branch information
thetarkus committed Jan 21, 2017
1 parent 70d554d commit 1d3b195
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 19 deletions.
2 changes: 1 addition & 1 deletion FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions FormMain.cs
Expand Up @@ -149,7 +149,10 @@ private void FormMain_MouseClick(object sender, MouseEventArgs e)
private void processFrames(int framesCount)
{
var format = formOptions.getImageFormat().ToString().ToLower();
var formProcess = new FormProcess(recorder.tempPath, framesCount);
var formProcess = new FormProcess(recorder.tempPath, "", framesCount);
string videoCodec = "";

Console.WriteLine(format);

formProcess.ffmpegPath = formOptions.getFFmpegPath();
formProcess.ffmpegArguments = formOptions.getFFmpegArguments();
Expand Down Expand Up @@ -194,11 +197,10 @@ private void buttonToggle_Click(object sender, EventArgs e)
timerTracker.Start();

FormBorderStyle = FormBorderStyle.FixedDialog;
return;
}

// Stop Recording
{
else {
// Stop
recorder.Stop();
timerRecord.Stop();
Expand Down
2 changes: 1 addition & 1 deletion FormOptions.cs
Expand Up @@ -6,7 +6,7 @@ namespace WebMCam
{
public partial class FormOptions : Form
{
private const string defaultArgs = "-framerate {fps:avg} -i {format} {audio} -c:v libvpx -b:v 2M -r {fps:avg} {output}";
private const string defaultArgs = "-framerate {fps:avg} -i {format} {audio} -c:v {codec} -auto-alt-ref 0 -b:v 2M -r {fps:avg} {output}";

private Properties.Settings settings = Properties.Settings.Default;

Expand Down
47 changes: 42 additions & 5 deletions FormProcess.cs
Expand Up @@ -12,18 +12,22 @@ public partial class FormProcess : Form
public string outputLocation = null;

private Process process = new Process();
private string framesPath;
private int framesCount;
private string framesPath;
private string videoCodec;
private string sText;

public FormProcess(string framesPath, int framesCount = -1)

public FormProcess(string framesPath, string videoCodec = "libvpx", int framesCount = -1)
{
this.framesPath = framesPath;
this.framesCount = framesCount;
this.videoCodec = videoCodec;

InitializeComponent();
}


/// <summary>
/// Replace arguments with data from recorder
/// </summary>
Expand All @@ -44,6 +48,7 @@ public void formatArguments(float duration, string frameFormat, float fps, float
.Replace("{audio}", audio);
}


/// <summary>
/// Create SaveFileDialog to find where the user wants to put their file
/// </summary>
Expand All @@ -53,7 +58,7 @@ private string getSaveLocation()
var saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "Choose File Location";
saveFileDialog.FileName = "output.webm";
saveFileDialog.Filter = "Video Formats (*.webm, *.mp4)|*.webm;*.mp4";
saveFileDialog.Filter = "WebM (*.webm)|*.webm|MPEG-4 (*.mp4)|*.mp4|Graphics Interchange Format (*.gif)|*.gif";
saveFileDialog.DefaultExt = "webm";

if (saveFileDialog.ShowDialog() == DialogResult.OK)
Expand All @@ -62,6 +67,33 @@ private string getSaveLocation()
return null;
}


/// <summary>
/// Get video codec to use from output file name.
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
private string getVideoCodec(string fileName)
{
var format = Path.GetExtension(fileName).ToUpper();

// Select codec
switch (format)
{
case ".WEBM":
return "libvpx";

case ".MP4":
return "libx264";

case ".GIF":
return "gif";
}

return "libvpx";
}


private void FormProcess_Load(object sender, EventArgs e)
{
BringToFront();
Expand All @@ -85,8 +117,9 @@ private void FormProcess_Load(object sender, EventArgs e)

info.WorkingDirectory = framesPath;
info.FileName = ffmpegPath;
info.Arguments = ffmpegArguments.Replace("{output}",
string.Format("-y \"{0}\"", outputLocation));
info.Arguments = ffmpegArguments
.Replace("{codec}", getVideoCodec(outputLocation))
.Replace("{output}", string.Format("-y \"{0}\"", outputLocation));

process.StartInfo = info;
process.OutputDataReceived += process_DataReceived;
Expand All @@ -110,6 +143,7 @@ private void FormProcess_Load(object sender, EventArgs e)
BringToFront();
}


/// <summary>
/// Write output from FFmpeg to textBoxData
/// </summary>
Expand All @@ -125,6 +159,7 @@ private void process_DataReceived(object sender, DataReceivedEventArgs e)
}));
}


/// <summary>
/// When the textbox text changes: if it starts with 'frame=' we need to update
/// the progress bar. If it starts with 'video=' then the processing is done. But
Expand Down Expand Up @@ -155,6 +190,7 @@ private void textBoxData_TextChanged(object sender, EventArgs e)
Text = string.Format("{0} [{1}%]", sText, progressBar.Value);
}


/// <summary>
/// Cancel processing
/// </summary>
Expand All @@ -171,6 +207,7 @@ private void buttonCancel_Click(object sender, EventArgs e)
Close();
}


/// <summary>
/// Open output file
/// </summary>
Expand Down
16 changes: 8 additions & 8 deletions Packager.ps1
@@ -1,13 +1,13 @@
$version = Get-Content VERSION;

# Move Resources to Release dir
if(Test-Path -Path "bin/Release/Resources" ) {
move bin/Release/Resources/* bin/Release/
rmdir -r bin/Release/Resources/
if(Test-Path -Path "$PSScriptRoot/bin/Release/Resources" ) {
move $PSScriptRoot/bin/Release/Resources/* $PSScriptRoot/bin/Release/
rmdir -r $PSScriptRoot/bin/Release/Resources/
}

# Create temporary Output dir
mkdir bin/Output
mkdir $PSScriptRoot/bin/Output

# Pt1 Create output.zip
$required_files = @(
Expand All @@ -21,11 +21,11 @@ $required_files = @(
)

foreach ($file in $required_files) {
copy bin/Release/$file bin/Output/$file
copy $PSScriptRoot/bin/Release/$file $PSScriptRoot/bin/Output/$file
}

Add-Type -A System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory("bin/Output", "bin/WebMCam-$version.zip")
[IO.Compression.ZipFile]::CreateFromDirectory("$PSScriptRoot/bin/Output", "$PSScriptRoot/bin/WebMCam-$version.zip")

# Pt2 Create output-ffmpeg.zip
$ffmpeg_files = @(
Expand All @@ -35,10 +35,10 @@ $ffmpeg_files = @(
);

foreach ($file in $ffmpeg_files) {
copy bin/Release/$file bin/Output/$file
copy $PSScriptRoot/bin/Release/$file $PSScriptRoot/bin/Output/$file
}

[IO.Compression.ZipFile]::CreateFromDirectory("bin/Output", "bin/WebMCam-$version-FFmpeg.zip")
[IO.Compression.ZipFile]::CreateFromDirectory("$PSScriptRoot/bin/Output", "$PSScriptRoot/bin/WebMCam-$version-FFmpeg.zip")

# Cleanup
rmdir -r bin/Output
Binary file modified Resources/ffmpeg.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.3.2
2.4.0

0 comments on commit 1d3b195

Please sign in to comment.