Fundamentals 11 min read

Build a Free Taobao Main Image Video Generator with Python, Tkinter & FFmpeg

This guide walks you through building a free Python Tkinter desktop application that merges multiple PNG or JPG images with background audio into a video using FFmpeg, covering environment setup, GUI design, file handling, log capture, video generation, and preview steps.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Build a Free Taobao Main Image Video Generator with Python, Tkinter & FFmpeg

Introduction

Many e‑commerce sellers use a main‑image video to increase product exposure; this tutorial shows how to build a free desktop tool that assembles images into a video with background music using Python.

Project Preparation

Required tools: Sublime Text 3, FFmpeg, and Python modules tkinter, os, PIL, time.

Project Goal

Combine multiple pictures into a single video and add background audio.

Step 1 – Prepare Images

Collect the pictures you want to include (any PNG or JPG files).

Step 2 – Import Modules

import time</code><code>from tkinter import filedialog</code><code>import tkinter as t</code><code>from PIL import Image</code><code>from tkinter import messagebox</code><code>import os

Step 3 – Build the GUI

Using tkinter we create the main window, text box, and all buttons needed for the workflow.

self.tl=[] # list for images</code><code>self.aa='' # audio path</code><code>self.fg=os.path.join(os.path.expanduser("~"),'Desktop')</code><code>self.root=t.Tk()</code><code>self.root.title('淘宝主图视频生成器v1.0')</code><code>self.root.iconbitmap('1.ico')</code><code>self.root.geometry('700x600')</code><code>self.root.attributes('-alpha',0.9)</code><code>self.root.wm_attributes('-topmost',1)</code><code>self.tt=t.Text(self.root,width=75,height=30)</code><code>self.b1=t.Button(self.root,text='打开图片文件',font=('宋体',13,'bold'),command=self.open_file)</code><code>self.b3=t.Button(self.root,text='打开音频文件',font=('宋体',13,'bold'),command=self.adio)</code><code>self.b7=t.Button(self.root,text='打开文件并批量修改',font=('宋体',13,'bold'),command=self.xg)</code><code>self.b8=t.Button(self.root,text='查看照片',font=('宋体',13,'bold'),command=self.ck)</code><code>self.l1=t.Label(self.root,text='视频文件名:')</code><code>self.e=t.Entry(self.root)</code><code>self.b2=t.Button(self.root,text='生成主图视频',font=('宋体',13,'bold'),command=self.video)</code><code>self.b4=t.Button(self.root,text='播放音频文件',font=('宋体',13,'bold'),command=self.play)</code><code>self.b5=t.Button(self.root,text='清空文本框内容',font=('宋体',13,'bold'),command=self.close)</code><code>self.b6=t.Button(self.root,text='预览视频内容',font=('宋体',13,'bold'),command=self.player)</code><code>self.l2=t.Label(self.root,text='视频分辨率:')</code><code>self.l3=t.Label(self.root,text='长:')</code><code>self.e1=t.Entry(self.root,width=5)</code><code>self.l4=t.Label(self.root,text='宽:')</code><code>self.e2=t.Entry(self.root,width=5)</code><code>self.tt.place(x=10,y=50)</code><code>self.b1.place(x=100,y=10)</code><code>self.l1.place(x=120,y=460)</code><code>self.e.place(x=200,y=460)</code><code>self.b2.place(x=200,y=550)</code><code>self.b3.place(x=240,y=10)</code><code>self.b4.place(x=550,y=120)</code><code>self.b5.place(x=550,y=200)</code><code>self.b6.place(x=550,y=300)</code><code>self.l2.place(x=120,y=500)</code><code>self.l3.place(x=200,y=500)</code><code>self.l4.place(x=280,y=500)</code><code>self.e1.place(x=230,y=500)</code><code>self.e2.place(x=310,y=500)</code><code>self.b7.place(x=380,y=10)</code><code>self.b8.place(x=580,y=10)</code><code>self.root.mainloop()

Step 4 – Implement Core Functions

4.1 Open Image and Audio Files

Use filedialog.askopenfilenames for images (PNG/JPG) and filedialog.askopenfilename for audio (WAV/MP3).

# select images</code><code>aa=filedialog.askopenfilenames(title='选择所有主图文件',filetypes=[('png','PNG'),('jpg','JPG'),('All Files','*')])</code><code># select audio</code><code>filedialog.askopenfilename(title='打开音频文件',filetypes=[('WAV','wav'),('MP3','mp3'),('All Files','*')])

4.2 Capture FFmpeg Log to Text Box

Redirect FFmpeg output to a temporary file, then read it into the GUI text widget.

if os.path.exists('1.txt'):</code><code>    try:</code><code>        f=open(os.path.join(self.fg,'1.txt'),'r',encoding='utf-8')</code><code>    except:</code><code>        messagebox.showinfo(title='提示',message='-----成功生成主图视频文件失败----')</code><code>    finally:</code><code>        self.tt.insert('insert',f.read()+'
')</code><code>        self.tt.insert('insert','
')</code><code>        messagebox.showinfo(title='提示',message='-----成功生成主图视频文件成功----
 文件名为:%s.mp4'%self.e.get())</code><code>        f.close()</code><code>else:</code><code>    af=open(os.path.join(self.fg,'1.txt'),'w')</code><code>    af.close()

4.3 Generate Video with FFmpeg

Run FFmpeg with the chosen images, audio, frame rate, duration, resolution, and output file.

os.popen('ffmpeg -r 0.3 -t 300 -i {}/%d.png -i {} -strict -2 -f mp4 -s {}x{} {} >{} 2>&1'.format(ab,self.aa,str(self.e1.get()),str(self.e2.get()),os.path.join(self.fg,self.e.get()+'.mp4'),os.path.join(self.fg,'1.txt')))

4.4 Preview the Result

os.popen(self.e.get()+'.mp4')

Conclusion

By leveraging FFmpeg and a simple Tkinter interface, you can automatically create a main‑image video for e‑commerce platforms, and the same technique can be adapted for many other multimedia automation tasks.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GUIPythonAutomationVideo GenerationffmpegTkinter
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.