MOV export sequence frames and play in Unity
Preface
I have collected a batch of pretty good MG animations. If you want to play them as special effects in Unity, you must first turn the MOV into a sequence frame, then use TexturePacker to make it into an atlas, and finally import it into Unity to create an Animation Clip for playback.
project
Convert MOV into sequence frames
You need to install FFmpeg in advance
Create a Cut.txt text file, copy the following content into the text file, change Cut.txt to Cut.bat, and you can add the code The set mov video is exported into sequence frames and stored in the same level directory.
@echo off
setlocal enabledelayedexpansion
:: 设置输入视频文件和输出图片文件夹路径
set input_video=Ele.mov
set output_folder=output_images
:: 创建输出文件夹
mkdir %output_folder%
:: 使用FFmpeg抓取视频帧并保存为透明图片
ffmpeg -i %input_video% -vf "select=eq(n\,0)+eq(pict_type\,I)" -vsync vfr -q:v 2 %output_folder%\frame%%04d.png
:: 完成后的消息
echo 透明图片已经生成到 %output_folder% 文件夹中。
:: 按任意键退出
pause
Use TexturePacker to create an atlas
Here I only found the version of TexturePacker3.0.9 (the pj method is to replace the original two exes with the two exes included)
Link: https://pan.baidu.com/s/1C04rikUgbdlstwBJV_Ch7g?pwd=upvu
Extraction code: upvu
But there is a problem here. Version 3.0.9 can only export json format atlas tables. Unity2021 and above can only use sprite sheets in tpsheet format.
So the following steps are required< /span>
Convert Json format sprite sheet to tpsheet format sprite sheet
Create a Python script and write the following content
import json
import os
def convert_texture_packer_to_unity(json_file, output_file):
with open(json_file, 'r') as f:
data = json.load(f)
frames = data['frames']
meta = data['meta']
texture_size = meta['size']
with open(output_file, 'w') as f:
f.write("#\n")
f.write("# Sprite sheet data for Unity.\n")
f.write("#\n")
f.write(f":format=40300\n")
f.write(f":texture={
meta['image']}\n")
f.write(f":size={
texture_size['w']}x{
texture_size['h']}\n")
f.write(":pivotpoints=enabled\n")
f.write(":borders=disabled\n")
f.write(":alphahandling=ClearTransparentPixels\n")
f.write("\n")
for frame_name, frame_data in frames.items():
frame = frame_data['frame']
source_size = frame_data['sourceSize']
sprite_source_size = frame_data['spriteSourceSize']
x = frame['x']
y = texture_size['h'] - frame['y'] - frame['h']
w = frame['w']
h = frame['h']
pivot_x = sprite_source_size['x'] / source_size['w']
pivot_y = 1 - (sprite_source_size['y'] / source_size['h'])
f.write(f"{
frame_name.replace('.png', '')};{
x};{
y};{
w};{
h}; {
pivot_x};{
pivot_y}; 0;0;0;0\n")
if __name__ == "__main__":
json_file = "link.txt" # Replace with your JSON file name
output_file = "link.tpsheet" # Replace with your desired output file name
convert_texture_packer_to_unity(json_file, output_file)
Correctly fill in the names ofjson_file
and output_file
and run to get the converted tpsheet sprite sheet
Import into Unity and play
You need to import the TexturePacker reading tool in advance
and then put the previously converted tpsheet and png format pictures into the project
and then use Animation Clip to play them Just sequence frames
Summarize
The more difficult question is how to convert the Json format sprite sheet to the tpsheet format sprite sheet
You can download it directly from Github
https://github.com/SlowFeather/TransTxt2Tp
Acknowledgments
ChatGPT 4