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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ShareX.MediaLib
|
||||
{
|
||||
public partial class VideoThumbnailerForm : Form
|
||||
{
|
||||
public event Action<string> UploadRequested;
|
||||
|
||||
public string FFmpegPath { get; set; }
|
||||
public VideoThumbnailOptions Options { get; set; }
|
||||
|
||||
|
@ -62,17 +65,25 @@ private void btnStart_Click(object sender, EventArgs e)
|
|||
pbProgress.Maximum = Options.ScreenshotCount;
|
||||
pbProgress.Visible = true;
|
||||
btnStart.Visible = false;
|
||||
BackgroundWorker bw = new BackgroundWorker();
|
||||
bw.DoWork += (sender2, e2) => thumbnailer.TakeScreenshots();
|
||||
bw.RunWorkerCompleted += (sender3, e3) =>
|
||||
|
||||
new Thread(() =>
|
||||
{
|
||||
if (!IsDisposed)
|
||||
List<VideoThumbnailInfo> screenshots = thumbnailer.TakeScreenshots();
|
||||
|
||||
if (screenshots != null && screenshots.Count > 0)
|
||||
{
|
||||
this.InvokeSafe(() =>
|
||||
{
|
||||
if (Options.UploadScreenshots)
|
||||
{
|
||||
screenshots.ForEach(x => OnUploadRequested(x.Filepath));
|
||||
}
|
||||
|
||||
btnStart.Visible = true;
|
||||
pbProgress.Visible = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
bw.RunWorkerAsync();
|
||||
}).Start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,6 +92,14 @@ private void Thumbnailer_ProgressChanged(int current, int length)
|
|||
this.InvokeSafe(() => pbProgress.Value = current);
|
||||
}
|
||||
|
||||
protected void OnUploadRequested(string filepath)
|
||||
{
|
||||
if (UploadRequested != null)
|
||||
{
|
||||
UploadRequested(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnBrowse_Click(object sender, EventArgs e)
|
||||
{
|
||||
// TODO: Translate
|
||||
|
|
|
@ -30,16 +30,16 @@ namespace ShareX.MediaLib
|
|||
{
|
||||
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; }
|
||||
|
||||
[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.")]
|
||||
public EImageFormat FFmpegThumbnailExtension { get; set; }
|
||||
[Category("Screenshots"), DefaultValue(EImageFormat.PNG), Description("Thumbnail image format to save.")]
|
||||
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; }
|
||||
|
||||
[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.")]
|
||||
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; }
|
||||
|
||||
[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; }
|
||||
|
||||
[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; }
|
||||
|
||||
[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; }
|
||||
|
||||
[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.")]
|
||||
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; }
|
||||
|
||||
[Category("Screenshots / Combined"), DefaultValue(true), Description("Add movie information to the combined screenshot.")]
|
||||
public bool AddMovieInfo { get; set; }
|
||||
[Category("Screenshots / Combined"), DefaultValue(true), Description("Add video information to the combined screenshot.")]
|
||||
public bool AddVideoInfo { get; set; }
|
||||
|
||||
[Category("Screenshots / Combined"), DefaultValue(true), Description("Add timestamp of screenshot at corner of image.")]
|
||||
public bool AddTimestamp { get; set; }
|
||||
|
|
|
@ -74,7 +74,7 @@ public List<VideoThumbnailInfo> TakeScreenshots()
|
|||
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);
|
||||
|
||||
using (Process p = new Process())
|
||||
|
@ -113,23 +113,16 @@ private List<VideoThumbnailInfo> Finish(List<VideoThumbnailInfo> tempScreenshots
|
|||
{
|
||||
using (Image img = CombineScreenshots(tempScreenshots))
|
||||
{
|
||||
string tempFilepath = Path.Combine(GetOutputDirectory(), Path.GetFileNameWithoutExtension(MediaPath) + "_Thumbnail." + Options.FFmpegThumbnailExtension.GetDescription());
|
||||
|
||||
switch (Options.FFmpegThumbnailExtension)
|
||||
{
|
||||
case EImageFormat.PNG:
|
||||
img.Save(tempFilepath, ImageFormat.Png);
|
||||
break;
|
||||
case EImageFormat.JPEG:
|
||||
img.Save(tempFilepath, ImageFormat.Jpeg);
|
||||
break;
|
||||
}
|
||||
|
||||
string tempFilepath = Path.Combine(GetOutputDirectory(), Path.GetFileNameWithoutExtension(MediaPath) + "_Thumbnail." + Options.ImageFormat.GetDescription());
|
||||
ImageHelpers.SaveImage(img, tempFilepath);
|
||||
screenshots.Add(new VideoThumbnailInfo(tempFilepath));
|
||||
}
|
||||
|
||||
if (!Options.KeepScreenshots)
|
||||
{
|
||||
tempScreenshots.ForEach(x => File.Delete(x.Filepath));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
screenshots.AddRange(tempScreenshots);
|
||||
|
@ -160,7 +153,7 @@ private string GetOutputDirectory()
|
|||
case ThumbnailLocationType.ParentFolder:
|
||||
return Path.GetDirectoryName(MediaPath);
|
||||
case ThumbnailLocationType.CustomFolder:
|
||||
return Options.OutputDirectory;
|
||||
return Options.CustomOutputDirectory;
|
||||
case ThumbnailLocationType.DefaultFolder: // TODO
|
||||
return "";
|
||||
}
|
||||
|
@ -194,7 +187,7 @@ private Image CombineScreenshots(List<VideoThumbnailInfo> screenshots)
|
|||
string infoString = "";
|
||||
int infoStringHeight = 0;
|
||||
|
||||
if (Options.AddMovieInfo)
|
||||
if (Options.AddVideoInfo)
|
||||
{
|
||||
infoString = VideoInfo.ToString();
|
||||
|
||||
|
|
|
@ -626,7 +626,9 @@ public static void OpenVideoThumbnailer(TaskSettings taskSettings = null)
|
|||
{
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue