Рендеринг нескольких гифок с помощью ffplay / ffmpeg в Winform - PullRequest
1 голос
/ 17 июня 2019

Я пытаюсь получить x количество анимированных GIF-файлов для рендеринга, таких как Panel или PictureBox, и использую прозрачность, которая есть в каждом GIF-файле.Я пробовал пару подходов, но я не очень знаком с ffmpeg и тому подобным.Ниже приведен код, который я использую для его рендеринга внутри панели, но я не могу понять, как получить 5 гифок, чтобы они накладывались друг на друга и рендерились так, как вы ожидаете.

Мне нужно / хочу, чтобы это отображалось в форме, а не выводилось.Я немного запутался, почему ffplay.exe не использует команду -i, и, возможно, именно поэтому я не могу заставить его отрендериться.какие-нибудь идеи?

Рабочий пример ниже.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Drawing.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using Microsoft.Win32;
using System.Windows.Forms.VisualStyles;

//FOR THIS EXAMPLE CREATE FORM HAVE BUTTON ON IT AND PANEL.
//button: button's click is "button1_Click"
//panel: Needed to output the render on it.
//FILES:
//Test.Gif
//These ff files came from the ffmpeg offical site.
//ffplay.exe //currently using
//ffmpeg.exe //thinking i need to use to get it how I want.
//I most of the code below from https://stackoverflow.com/questions/31465630/ffplay-successfully-moved-inside-my-winform-how-to-set-it-borderless which was a good starting point.

namespace Test_Form
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

        [DllImport("user32.dll")]
        private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);


        //Process ffplay = null;

        public Form1()
        {
            InitializeComponent();
            Application.EnableVisualStyles();
            this.DoubleBuffered = true;
        }



        public Process ffplay = new Process();
        private void FFplay()
        {
            ffplay.StartInfo.FileName = "ffplay.exe";
            ffplay.StartInfo.Arguments = "-noborder Test.gif"; //THIS IS WHERE I INPUT THE GIF FILE
            ffplay.StartInfo.CreateNoWindow = true;
            ffplay.StartInfo.RedirectStandardOutput = true;
            ffplay.StartInfo.UseShellExecute = false;

            ffplay.EnableRaisingEvents = true;
            ffplay.OutputDataReceived += (o, e) => Debug.WriteLine(e.Data ?? "NULL", "ffplay");
            ffplay.ErrorDataReceived += (o, e) => Debug.WriteLine(e.Data ?? "NULL", "ffplay");
            ffplay.Exited += (o, e) => Debug.WriteLine("Exited", "ffplay");
            ffplay.Start();

            Thread.Sleep(1000); // you need to wait/check the process started, then...

            // child, new parent
            // make 'this' the parent of ffmpeg (presuming you are in scope of a Form or Control)
            SetParent(ffplay.MainWindowHandle, this.Handle);

            // window, x, y, width, height, repaint
            // move the ffplayer window to the top-left corner and set the size to 320x280
            MoveWindow(ffplay.MainWindowHandle, 800, 600, 320, 280, true);

            SetParent(ffplay.MainWindowHandle, this.panel1.Handle);
            MoveWindow(ffplay.MainWindowHandle, -5, -30, 320, 280, true);
        }

//runs the FFplay Command
private void button1_Click(object sender, EventArgs e)
        {
            FFplay();

        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            try { ffplay.Kill(); }
            catch { }
        }
    }

Я хотел бы, чтобы кнопка позволяла мне добавлять любое количество картинок (например, 5 или 10) в одну и ту же область и иметь иханимированные с их прозрачным отображением того, что находится под этим gif.

Так, например, у меня могло бы быть изображение круга, затем вращающийся / загружающий прозрачный gif сверху и затем gif, который считает вверх / вниз сверхутот, который даст мне эффект обратного отсчета.

Спасибо за помощь!

...