ShareX/ShareX.MediaLib/Forms/VideoThumbnailerForm.cs

109 lines
3.5 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
2024-01-03 12:57:14 +13:00
Copyright (c) 2007-2024 ShareX Team
2015-08-04 19:31:43 +12:00
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;
using ShareX.MediaLib.Properties;
2015-08-04 19:31:43 +12:00
using System;
using System.Collections.Generic;
using System.IO;
2018-08-04 02:24:26 +12:00
using System.Threading.Tasks;
2015-08-04 23:47:34 +12:00
using System.Windows.Forms;
2015-08-04 19:31:43 +12:00
namespace ShareX.MediaLib
{
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;
2015-08-04 23:47:34 +12:00
InitializeComponent();
2023-06-04 10:07:30 +12:00
ShareXResources.ApplyTheme(this, true);
2016-05-25 06:15:45 +12:00
txtMediaPath.Text = Options.LastVideoPath ?? "";
2015-08-04 23:47:34 +12:00
pgOptions.SelectedObject = Options;
2015-08-04 19:31:43 +12:00
}
private async 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;
2015-08-07 21:02:42 +12:00
pbProgress.Maximum = Options.ThumbnailCount;
2015-08-05 01:05:14 +12:00
pbProgress.Visible = true;
btnStart.Visible = false;
2015-08-05 23:44:04 +12:00
List<VideoThumbnailInfo> thumbnails = null;
2015-08-05 23:44:04 +12:00
await Task.Run(() =>
{
2015-08-06 21:22:07 +12:00
try
{
VideoThumbnailer thumbnailer = new VideoThumbnailer(FFmpegPath, Options);
2015-08-06 21:22:07 +12:00
thumbnailer.ProgressChanged += Thumbnailer_ProgressChanged;
thumbnails = thumbnailer.TakeThumbnails(mediaPath);
2015-08-06 21:22:07 +12:00
}
catch (Exception ex)
{
2017-04-22 08:42:52 +12:00
ex.ShowError();
2015-08-06 21:22:07 +12:00
}
2018-08-04 02:24:26 +12:00
});
if (thumbnails != null)
{
OnThumbnailsTaken(thumbnails);
}
btnStart.Visible = true;
pbProgress.Visible = false;
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
{
2021-06-10 10:14:01 +12:00
ThumbnailsTaken?.Invoke(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)
{
FileHelpers.BrowseFile(Resources.VideoThumbnailerForm_btnBrowse_Click_Browse_for_media_file, txtMediaPath);
2015-08-05 01:05:14 +12:00
}
2015-08-04 19:31:43 +12:00
}
}