mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Video thumbnailer auto upload support
This commit is contained in:
parent
792e3c59bb
commit
d424277158
4 changed files with 51 additions and 37 deletions
|
@ -32,12 +32,15 @@ You should have received a copy of the GNU General Public License
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.MediaLib
|
namespace ShareX.MediaLib
|
||||||
{
|
{
|
||||||
public partial class VideoThumbnailerForm : Form
|
public partial class VideoThumbnailerForm : Form
|
||||||
{
|
{
|
||||||
|
public event Action<string> UploadRequested;
|
||||||
|
|
||||||
public string FFmpegPath { get; set; }
|
public string FFmpegPath { get; set; }
|
||||||
public VideoThumbnailOptions Options { get; set; }
|
public VideoThumbnailOptions Options { get; set; }
|
||||||
|
|
||||||
|
@ -62,17 +65,25 @@ private void btnStart_Click(object sender, EventArgs e)
|
||||||
pbProgress.Maximum = Options.ScreenshotCount;
|
pbProgress.Maximum = Options.ScreenshotCount;
|
||||||
pbProgress.Visible = true;
|
pbProgress.Visible = true;
|
||||||
btnStart.Visible = false;
|
btnStart.Visible = false;
|
||||||
BackgroundWorker bw = new BackgroundWorker();
|
|
||||||
bw.DoWork += (sender2, e2) => thumbnailer.TakeScreenshots();
|
new Thread(() =>
|
||||||
bw.RunWorkerCompleted += (sender3, e3) =>
|
|
||||||
{
|
{
|
||||||
if (!IsDisposed)
|
List<VideoThumbnailInfo> screenshots = thumbnailer.TakeScreenshots();
|
||||||
|
|
||||||
|
if (screenshots != null && screenshots.Count > 0)
|
||||||
{
|
{
|
||||||
btnStart.Visible = true;
|
this.InvokeSafe(() =>
|
||||||
pbProgress.Visible = false;
|
{
|
||||||
|
if (Options.UploadScreenshots)
|
||||||
|
{
|
||||||
|
screenshots.ForEach(x => OnUploadRequested(x.Filepath));
|
||||||
|
}
|
||||||
|
|
||||||
|
btnStart.Visible = true;
|
||||||
|
pbProgress.Visible = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
}).Start();
|
||||||
bw.RunWorkerAsync();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +92,14 @@ private void Thumbnailer_ProgressChanged(int current, int length)
|
||||||
this.InvokeSafe(() => pbProgress.Value = current);
|
this.InvokeSafe(() => pbProgress.Value = current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void OnUploadRequested(string filepath)
|
||||||
|
{
|
||||||
|
if (UploadRequested != null)
|
||||||
|
{
|
||||||
|
UploadRequested(filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void btnBrowse_Click(object sender, EventArgs e)
|
private void btnBrowse_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// TODO: Translate
|
// TODO: Translate
|
||||||
|
|
|
@ -30,16 +30,16 @@ namespace ShareX.MediaLib
|
||||||
{
|
{
|
||||||
public class VideoThumbnailOptions
|
public class VideoThumbnailOptions
|
||||||
{
|
{
|
||||||
[Category("Screenshots"), DefaultValue(ThumbnailLocationType.ParentFolder), Description("Create screenshots in the same folders as the media file, default torrent folder or in a custom folder.")]
|
[Category("Screenshots"), DefaultValue(ThumbnailLocationType.ParentFolder), Description("Create screenshots in the same folders as the media file, default screenshot folder or in a custom folder.")]
|
||||||
public ThumbnailLocationType OutputLocation { get; set; }
|
public ThumbnailLocationType OutputLocation { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots"), DefaultValue(""), Description("Output folder where screenshots will get saved.")]
|
[Category("Screenshots"), DefaultValue(""), Description("Output folder where screenshots will get saved.")]
|
||||||
public string OutputDirectory { get; set; }
|
public string CustomOutputDirectory { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots"), DefaultValue(EImageFormat.PNG), Description("FFmpeg thumbnail extension e.g. png or jpg.")]
|
[Category("Screenshots"), DefaultValue(EImageFormat.PNG), Description("Thumbnail image format to save.")]
|
||||||
public EImageFormat FFmpegThumbnailExtension { get; set; }
|
public EImageFormat ImageFormat { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots"), DefaultValue(3), Description("Total number of screenshots to take.")]
|
[Category("Screenshots"), DefaultValue(9), Description("Total number of screenshots to take.")]
|
||||||
public int ScreenshotCount { get; set; }
|
public int ScreenshotCount { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots"), DefaultValue(false), Description("Choose random frame each time a media file is processed.")]
|
[Category("Screenshots"), DefaultValue(false), Description("Choose random frame each time a media file is processed.")]
|
||||||
|
@ -48,16 +48,16 @@ public class VideoThumbnailOptions
|
||||||
[Category("Screenshots"), DefaultValue(true), Description("Upload screenshots.")]
|
[Category("Screenshots"), DefaultValue(true), Description("Upload screenshots.")]
|
||||||
public bool UploadScreenshots { get; set; }
|
public bool UploadScreenshots { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots"), DefaultValue(true), Description("Keep or delete screenshots after processing files.")]
|
[Category("Screenshots"), DefaultValue(false), Description("After combine screenshots keep single image files.")]
|
||||||
public bool KeepScreenshots { get; set; }
|
public bool KeepScreenshots { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots"), DefaultValue(true), Description("After all screenshots taken open output directory automatically.")]
|
[Category("Screenshots"), DefaultValue(false), Description("After all screenshots taken open output directory automatically.")]
|
||||||
public bool OpenDirectory { get; set; }
|
public bool OpenDirectory { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots"), DefaultValue(0), Description("Maximum thumbnail width size, 0 means don't resize.")]
|
[Category("Screenshots"), DefaultValue(512), Description("Maximum thumbnail width size, 0 means don't resize.")]
|
||||||
public int MaxThumbnailWidth { get; set; }
|
public int MaxThumbnailWidth { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots / Combined"), DefaultValue(false), Description("Combine all screenshots to one large screenshot.")]
|
[Category("Screenshots / Combined"), DefaultValue(true), Description("Combine all screenshots to one large screenshot.")]
|
||||||
public bool CombineScreenshots { get; set; }
|
public bool CombineScreenshots { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots / Combined"), DefaultValue(20), Description("Space between border and content as pixel.")]
|
[Category("Screenshots / Combined"), DefaultValue(20), Description("Space between border and content as pixel.")]
|
||||||
|
@ -66,11 +66,11 @@ public class VideoThumbnailOptions
|
||||||
[Category("Screenshots / Combined"), DefaultValue(10), Description("Space between screenshots as pixel.")]
|
[Category("Screenshots / Combined"), DefaultValue(10), Description("Space between screenshots as pixel.")]
|
||||||
public int Spacing { get; set; }
|
public int Spacing { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots / Combined"), DefaultValue(1), Description("Number of screenshots per row.")]
|
[Category("Screenshots / Combined"), DefaultValue(3), Description("Number of screenshots per row.")]
|
||||||
public int ColumnCount { get; set; }
|
public int ColumnCount { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots / Combined"), DefaultValue(true), Description("Add movie information to the combined screenshot.")]
|
[Category("Screenshots / Combined"), DefaultValue(true), Description("Add video information to the combined screenshot.")]
|
||||||
public bool AddMovieInfo { get; set; }
|
public bool AddVideoInfo { get; set; }
|
||||||
|
|
||||||
[Category("Screenshots / Combined"), DefaultValue(true), Description("Add timestamp of screenshot at corner of image.")]
|
[Category("Screenshots / Combined"), DefaultValue(true), Description("Add timestamp of screenshot at corner of image.")]
|
||||||
public bool AddTimestamp { get; set; }
|
public bool AddTimestamp { get; set; }
|
||||||
|
|
|
@ -74,7 +74,7 @@ public List<VideoThumbnailInfo> TakeScreenshots()
|
||||||
timeSliceElapsed = GetTimeSlice(Options.ScreenshotCount) * (i + 1);
|
timeSliceElapsed = GetTimeSlice(Options.ScreenshotCount) * (i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
string filename = string.Format("{0}-{1}.{2}", mediaFileName, timeSliceElapsed, Options.FFmpegThumbnailExtension.GetDescription());
|
string filename = string.Format("{0}-{1}.{2}", mediaFileName, timeSliceElapsed, Options.ImageFormat.GetDescription());
|
||||||
string tempScreenshotPath = Path.Combine(GetOutputDirectory(), filename);
|
string tempScreenshotPath = Path.Combine(GetOutputDirectory(), filename);
|
||||||
|
|
||||||
using (Process p = new Process())
|
using (Process p = new Process())
|
||||||
|
@ -113,22 +113,15 @@ private List<VideoThumbnailInfo> Finish(List<VideoThumbnailInfo> tempScreenshots
|
||||||
{
|
{
|
||||||
using (Image img = CombineScreenshots(tempScreenshots))
|
using (Image img = CombineScreenshots(tempScreenshots))
|
||||||
{
|
{
|
||||||
string tempFilepath = Path.Combine(GetOutputDirectory(), Path.GetFileNameWithoutExtension(MediaPath) + "_Thumbnail." + Options.FFmpegThumbnailExtension.GetDescription());
|
string tempFilepath = Path.Combine(GetOutputDirectory(), Path.GetFileNameWithoutExtension(MediaPath) + "_Thumbnail." + Options.ImageFormat.GetDescription());
|
||||||
|
ImageHelpers.SaveImage(img, tempFilepath);
|
||||||
switch (Options.FFmpegThumbnailExtension)
|
|
||||||
{
|
|
||||||
case EImageFormat.PNG:
|
|
||||||
img.Save(tempFilepath, ImageFormat.Png);
|
|
||||||
break;
|
|
||||||
case EImageFormat.JPEG:
|
|
||||||
img.Save(tempFilepath, ImageFormat.Jpeg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
screenshots.Add(new VideoThumbnailInfo(tempFilepath));
|
screenshots.Add(new VideoThumbnailInfo(tempFilepath));
|
||||||
}
|
}
|
||||||
|
|
||||||
tempScreenshots.ForEach(x => File.Delete(x.Filepath));
|
if (!Options.KeepScreenshots)
|
||||||
|
{
|
||||||
|
tempScreenshots.ForEach(x => File.Delete(x.Filepath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -160,7 +153,7 @@ private string GetOutputDirectory()
|
||||||
case ThumbnailLocationType.ParentFolder:
|
case ThumbnailLocationType.ParentFolder:
|
||||||
return Path.GetDirectoryName(MediaPath);
|
return Path.GetDirectoryName(MediaPath);
|
||||||
case ThumbnailLocationType.CustomFolder:
|
case ThumbnailLocationType.CustomFolder:
|
||||||
return Options.OutputDirectory;
|
return Options.CustomOutputDirectory;
|
||||||
case ThumbnailLocationType.DefaultFolder: // TODO
|
case ThumbnailLocationType.DefaultFolder: // TODO
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -194,7 +187,7 @@ private Image CombineScreenshots(List<VideoThumbnailInfo> screenshots)
|
||||||
string infoString = "";
|
string infoString = "";
|
||||||
int infoStringHeight = 0;
|
int infoStringHeight = 0;
|
||||||
|
|
||||||
if (Options.AddMovieInfo)
|
if (Options.AddVideoInfo)
|
||||||
{
|
{
|
||||||
infoString = VideoInfo.ToString();
|
infoString = VideoInfo.ToString();
|
||||||
|
|
||||||
|
|
|
@ -626,7 +626,9 @@ public static void OpenVideoThumbnailer(TaskSettings taskSettings = null)
|
||||||
{
|
{
|
||||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||||
|
|
||||||
new VideoThumbnailerForm(taskSettings.CaptureSettings.FFmpegOptions.CLIPath, Program.Settings.VideoThumbnailOptions).Show();
|
VideoThumbnailerForm thumbnailerForm = new VideoThumbnailerForm(taskSettings.CaptureSettings.FFmpegOptions.CLIPath, Program.Settings.VideoThumbnailOptions);
|
||||||
|
thumbnailerForm.UploadRequested += filepath => UploadManager.UploadFile(filepath, taskSettings);
|
||||||
|
thumbnailerForm.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OpenImageEditor(string filePath = null)
|
public static void OpenImageEditor(string filePath = null)
|
||||||
|
|
Loading…
Reference in a new issue