Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
prongbang committed Nov 5, 2016
1 parent 5912607 commit ec4142e
Show file tree
Hide file tree
Showing 20 changed files with 2,782 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/Mp4ToGif/bin/
/Mp4ToGif/obj/
20 changes: 20 additions & 0 deletions Mp4ToGif.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Windows Desktop
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mp4ToGif", "Mp4ToGif\Mp4ToGif.csproj", "{2E4BA835-90ED-4710-824F-CD14AE819223}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E4BA835-90ED-4710-824F-CD14AE819223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E4BA835-90ED-4710-824F-CD14AE819223}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E4BA835-90ED-4710-824F-CD14AE819223}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E4BA835-90ED-4710-824F-CD14AE819223}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added Mp4ToGif.v11.suo
Binary file not shown.
Binary file added Mp4ToGif/4Gifs.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions Mp4ToGif/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
165 changes: 165 additions & 0 deletions Mp4ToGif/Form1.Designer.cs

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

185 changes: 185 additions & 0 deletions Mp4ToGif/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
using Mp4ToGif.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;

namespace Mp4ToGif
{
public partial class Form1 : Form
{

private System.Timers.Timer aTimer;

private Thread workThread;

delegate void StringParameterDelegate(string status);

public Form1()
{
InitializeComponent();

this.Text = "Convert MP4 TO GIF 1.0.0";

// Center at initilization
this.StartPosition = FormStartPosition.CenterScreen;

rdBtnScaleDefault.Text = ConfigUtil.FFMPEG_SCALE + "";
rdBtnScaleDefault.Checked = true;
btnConvert.Enabled = tbMp4Path.Enabled = false;

this.MinimumSize = new Size(this.Width, this.Height);
this.MaximumSize = new Size(this.Width, this.Height);

}

private void btnBrowse_Click(object sender, EventArgs e)
{

// Show the dialog and get result.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
tbMp4Path.Text = openFileDialog1.FileName;
Regex re = new Regex("\\d*" + ConfigUtil.MP4);
Match m = re.Match(tbMp4Path.Text);
if (m.Success)
{
string videoInfo = VideoUtil.getVideoInfo(tbMp4Path.Text);
ConfigUtil.FFMPEG_SCALE = VideoUtil.getWidth(videoInfo);
rdBtnScaleWidth.Text = ConfigUtil.FFMPEG_SCALE + "";
btnConvert.Enabled = true;
}
else
{
MessageBox.Show("Can't Support File " + openFileDialog1.FileName);
}
}

}

private void startTimer()
{
aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 1000;
aTimer.Enabled = true;
}

private void OnTimedEvent(object source, ElapsedEventArgs e)
{
string fileGif = ConfigUtil.INPUT_PATH.Replace(ConfigUtil.MP4, ConfigUtil.GIF);
if (File.Exists(fileGif))
{
if (!SystemUtil.checkProcess(ConfigUtil.FFMPEG))
{
updateStatus(ConfigUtil.COMPLETE);
aTimer.Stop();
workThread.Abort();
}
}
}

private void updateStatus(string status)
{
if (InvokeRequired)
{
// We're not in the UI thread
BeginInvoke(new StringParameterDelegate(updateStatus), new object[] { status });
return;
}
lbStatus.Text = status;
}

private void convertToGif()
{
ConfigUtil.INPUT_PATH = tbMp4Path.Text;

string fileGif = ConfigUtil.INPUT_PATH.Replace(ConfigUtil.MP4, ConfigUtil.GIF);

ConfigUtil.FFMPEG_PALETTE_PNG = FileUtil.getPath(ConfigUtil.INPUT_PATH) + @"\" + ConfigUtil.FFMPEG_PALETTE_PNG;

if (!File.Exists(fileGif))
{

updateStatus(ConfigUtil.CONVERTING);

startTimer();

string generateAPalette = string.Format(
ConfigUtil.FFMPEG_GENERATE_PALETTE,
ConfigUtil.FFMPEG_START_AT_SECOND,
ConfigUtil.FFMPEG_LENGTH_OF_GIF_VIDEO,
ConfigUtil.INPUT_PATH,
ConfigUtil.FFMPEG_SCALE,
ConfigUtil.FFMPEG_PALETTE_PNG
);

string outputGifUsingPalette = string.Format(
ConfigUtil.FFMPEG_OUTPUT_GIF_USING_PALETTE,
ConfigUtil.FFMPEG_START_AT_SECOND,
ConfigUtil.FFMPEG_LENGTH_OF_GIF_VIDEO,
ConfigUtil.INPUT_PATH,
ConfigUtil.FFMPEG_PALETTE_PNG,
ConfigUtil.FFMPEG_SCALE,
ConfigUtil.INPUT_PATH.Replace(ConfigUtil.MP4, "")
);

String genPalette = string.Format("{0} {1}", ConfigUtil.FFMPEG, generateAPalette);

String convGif = string.Format("{0} {1}", ConfigUtil.FFMPEG, outputGifUsingPalette);

String delPalett = string.Format(ConfigUtil.DELETE_FILE, ConfigUtil.FFMPEG_PALETTE_PNG);

String options = string.Format("{0} & {1} & {2} & exit", genPalette, convGif, delPalett);

String command = string.Format("/c start {0} /k \"{1}\"", ConfigUtil.CMD, options);

CmdUtil.RunProcess(ConfigUtil.CMD, command);

}
else
{
MessageBox.Show("File already exists, " + fileGif);
workThread.Abort();
}
}

private void btnConvert_Click(object sender, EventArgs e)
{

workThread = new Thread(new ThreadStart(convertToGif));
workThread.IsBackground = true;
workThread.Start();

}

private void rdBtnScaleDefault_CheckedChanged(object sender, EventArgs e)
{
ConfigUtil.FFMPEG_SCALE = ConfigUtil.FFMPEG_SCALE_CONST;
}

private void rdBtnScaleWidth_CheckedChanged(object sender, EventArgs e)
{
if (tbMp4Path.Text != null && tbMp4Path.Text != "")
{
if (rdBtnScaleWidth.Text != null && rdBtnScaleWidth.Text != ConfigUtil.UNDERLINE)
{
ConfigUtil.FFMPEG_SCALE = Int32.Parse(rdBtnScaleWidth.Text);
}
}
}

}
}
Loading

0 comments on commit ec4142e

Please sign in to comment.