ShareX/ShareX.MediaLib/Forms/VideoThumbnailerForm.cs

115 lines
3.9 KiB
C#
Raw Normal View History

2015-08-04 19:31:43 +12:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright © 2007-2015 ShareX Developers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
2015-08-04 23:47:34 +12:00
using ShareX.HelpersLib;
2015-08-04 19:31:43 +12:00
using System;
using System.Collections.Generic;
using System.IO;
2015-08-05 23:44:04 +12:00
using System.Threading;
2015-08-04 23:47:34 +12:00
using System.Windows.Forms;
2015-08-04 19:31:43 +12:00
namespace ShareX.MediaLib
{
2015-08-04 23:47:34 +12:00
public partial class VideoThumbnailerForm : Form
2015-08-04 19:31:43 +12:00
{
2015-08-06 21:22:07 +12:00
public event Action<List<VideoThumbnailInfo>> ThumbnailsTaken;
2015-08-05 23:44:04 +12:00
2015-08-05 22:41:37 +12:00
public string FFmpegPath { get; set; }
2015-08-04 23:47:34 +12:00
public VideoThumbnailOptions Options { get; set; }
2015-08-04 19:31:43 +12:00
2015-08-04 23:47:34 +12:00
public VideoThumbnailerForm(string ffmpegPath, VideoThumbnailOptions options)
2015-08-04 19:31:43 +12:00
{
2015-08-04 23:47:34 +12:00
FFmpegPath = ffmpegPath;
Options = options;
InitializeComponent();
Icon = ShareXResources.Icon;
2015-08-06 01:28:32 +12:00
txtMediaPath.Text = Options.LastVideoPath ?? string.Empty;
2015-08-04 23:47:34 +12:00
pgOptions.SelectedObject = Options;
2015-08-04 19:31:43 +12:00
}
2015-08-04 23:47:34 +12:00
private void btnStart_Click(object sender, EventArgs e)
2015-08-04 19:31:43 +12:00
{
2015-08-04 23:47:34 +12:00
string mediaPath = txtMediaPath.Text;
2015-08-05 01:05:14 +12:00
if (File.Exists(mediaPath) && File.Exists(FFmpegPath))
2015-08-04 23:47:34 +12:00
{
2015-08-06 01:28:32 +12:00
Options.LastVideoPath = mediaPath;
2015-08-05 01:05:14 +12:00
pbProgress.Value = 0;
pbProgress.Maximum = Options.ScreenshotCount;
2015-08-05 01:05:14 +12:00
pbProgress.Visible = true;
btnStart.Visible = false;
2015-08-05 23:44:04 +12:00
new Thread(() =>
2015-08-05 01:05:14 +12:00
{
2015-08-06 21:22:07 +12:00
List<VideoThumbnailInfo> thumbnails = null;
2015-08-05 23:44:04 +12:00
2015-08-06 21:22:07 +12:00
try
{
VideoThumbnailer thumbnailer = new VideoThumbnailer(mediaPath, FFmpegPath, Options);
thumbnailer.ProgressChanged += Thumbnailer_ProgressChanged;
thumbnails = thumbnailer.TakeThumbnails();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
2015-08-05 22:41:37 +12:00
{
2015-08-05 23:44:04 +12:00
this.InvokeSafe(() =>
{
2015-08-06 21:22:07 +12:00
if (thumbnails != null)
2015-08-05 23:44:04 +12:00
{
2015-08-06 21:22:07 +12:00
OnThumbnailsTaken(thumbnails);
2015-08-05 23:44:04 +12:00
}
2015-08-06 21:22:07 +12:00
btnStart.Visible = true;
pbProgress.Visible = false;
2015-08-05 23:44:04 +12:00
});
2015-08-05 22:41:37 +12:00
}
2015-08-05 23:44:04 +12:00
}).Start();
2015-08-04 23:47:34 +12:00
}
2015-08-04 19:31:43 +12:00
}
2015-08-05 01:05:14 +12:00
private void Thumbnailer_ProgressChanged(int current, int length)
{
this.InvokeSafe(() => pbProgress.Value = current);
}
2015-08-06 21:22:07 +12:00
protected void OnThumbnailsTaken(List<VideoThumbnailInfo> thumbnails)
2015-08-05 23:44:04 +12:00
{
2015-08-06 21:22:07 +12:00
if (ThumbnailsTaken != null)
2015-08-05 23:44:04 +12:00
{
2015-08-06 21:22:07 +12:00
ThumbnailsTaken(thumbnails);
2015-08-05 23:44:04 +12:00
}
}
2015-08-05 01:05:14 +12:00
private void btnBrowse_Click(object sender, EventArgs e)
{
// TODO: Translate
Helpers.BrowseFile("Browse for media file", txtMediaPath);
}
2015-08-04 19:31:43 +12:00
}
}