循环动画时PNG序列到MP4

时间:2016-04-18 22:50:42

标签: bash ffmpeg

所以,我试图将PNG序列转换为MP4并将动画循环大约100次,唯一的问题是我的脚本似乎没有正常工作。

脚本应该做的是获取frames目录中的PNG文件数,并将它们发送到FFMPEG 100次。唯一的问题是我的脚本没有正常工作。这是代码。

#!/bin/bash

loopcode()
{
tmpdir=frames
picext=png
one=$(ls -l ${tmpdir}/*.png  | wc -l)
two=$(echo "${one}+0" | bc -l)
three=0
while [ ! ${loopi} -eq ${looper} ]; do
  while [ ! ${three} -eq ${two} ]; do
    three=$(printf "%09d" ${two})
    echo ${tmpdir}/${three}.${picext}
    two=$(echo "${two}+1" | bc -l)
  done
  two=0
  loopi=$(echo "${loopi}+1" | bc -l)
done
}

looper=100
loopi=0
outfile=output.mp4
fps=5
convert frames/*.png frames/%09d.jpeg
loopcode && sleep 5
cat $(loopcode) | ffmpeg -framerate 1/5 -i - -c:v libx264 -r 30 -pix_fmt yuv420p "${outfile}"

1 个答案:

答案 0 :(得分:3)

您可以跳过脚本中的整个循环部分,并使用ffmpeg,即

using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            // Start the BackgroundWorker.
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 1; i <= 100; i++)
            {
                // Wait 100 milliseconds.
                Thread.Sleep(100);
                // Report progress.
                backgroundWorker1.ReportProgress(i);
            }
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            // Change the value of the ProgressBar to the BackgroundWorker progress.
            progressBar1.Value = e.ProgressPercentage;
            // Set the text.
            this.Text = e.ProgressPercentage.ToString();
        }
    }
} //closing here

这要求PNG图像名称形成连续序列。