Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

Опции темы Поиск в этой теме Опции просмотра
Старый 20.07.2021, 21:14   #1  
Blog bot is offline
Blog bot
24,415 / 822 (76) +++++++
Регистрация: 28.10.2006
goshoom: Animated GIF thumbnails from a video

This blog post isn’t about Dynamics AX / Dynamics 365, although it may occasionally be useful for some AX/D365 developers as well.

Let’s say I have a 30 minutes long movie that I want to share on a website and I want to give people an idea about the content of the video. Therefore I want to create a slideshow of screenshots taken from the movie at regular intervals. An animated GIF is an obvious choice.

I spent quite some time trying to figure out how to do it, because I had little idea. After some research, I came to a conclusion that a reasonable approach is extracting screenshots with FFmpeg and then combining them to a GIF file with ImageMagick.

Because installing those console applications and dealing with them directly would be quite cumbersome, I also looked for some wrapper libraries available via NuGet. I chose these:
Now let’s build a simple application to show the code. Create a console application for .NET Framework and add those two NuGet packages.

Add using statements for namespaces that we’ll need in a moment:

using System.IO;using ImageMagick;using MediaToolkit;using MediaToolkit.Model;using MediaToolkit.Options;

The structure of your program will be following:

class Program{ static void Main(string[] args) { new Program().Run(); } void Run() { string videoFilePath = @"c:\temp\input.mp4"; List thumbnails = ExtractThumbnails(videoFilePath, 10); if (thumbnails?.Any() == true) { string gifFilePath = Path.Combine( Path.GetDirectoryName(videoFilePath), $"{Path.GetFileName(videoFilePath)}.gif"); CombineThumbnails(gifFilePath, thumbnails); // Delete temporary files thumbnails.ForEach(file => File.Delete(file)); } }}

ExtractThumbnails() takes screenshots from the video as JPG files.

CombineThumbnails() then take these files and put them into an animated GIF.

Finally we delete JPG files, because they aren’t needed anymore.

Here is the implementation of ExtractThumbnails(). The key part is the call of engine.GetThumbnail() at the end.

<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp">List ExtractThumbnails(string inputFilePath, int numOfPics){ MediaFile inputFile = new MediaFile { Filename = inputFilePath }; List thumbnails = new List(numOfPics); using (var engine = new Engine()) { engine.GetMetadata(inputFile); if (inputFile.Metadata == null) { throw new InvalidOperationException("Invalid file"); } int duration = (int)inputFile.Metadata.Duration.TotalSeconds; int picDistance = duration / (numOfPics + 1); for (int i = 1; i <span class="sy0">
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
goshoom: Getting service operations from metadata (D365FO) Blog bot DAX Blogs 0 31.05.2019 10:11
goshoom: Preventing users from changing session date (AX 2012) Blog bot DAX Blogs 0 12.05.2014 19:11
Clausl: Action and Activity Button icons in Microsoft Dynamics NAV 2009Копирование Stream Blog bot Dynamics CRM: Blogs 0 26.11.2008 17:15
Clausl: Action and Activity Button icons in Microsoft Dynamics NAV 2009 Blog bot Dynamics CRM: Blogs 0 29.09.2008 02:02
axcoder: Video: howto drag and drop nodes from XPO to application Blog bot DAX Blogs 1 21.08.2007 11:44
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Часовой пояс GMT +3, время: 23:49.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.