255 lines
7.1 KiB
Python
255 lines
7.1 KiB
Python
|
#!/usr/bin/env python3
|
|||
|
# -*- coding: utf-8 -*-
|
|||
|
|
|||
|
from openai import OpenAI
|
|||
|
import os
|
|||
|
import base64
|
|||
|
import json
|
|||
|
import time
|
|||
|
from datetime import datetime
|
|||
|
|
|||
|
def encode_video(video_path):
|
|||
|
"""编码视频文件为base64"""
|
|||
|
with open(video_path, "rb") as video_file:
|
|||
|
return base64.b64encode(video_file.read()).decode("utf-8")
|
|||
|
|
|||
|
def encode_audio(audio_path):
|
|||
|
"""编码音频文件为base64"""
|
|||
|
with open(audio_path, "rb") as audio_file:
|
|||
|
return base64.b64encode(audio_file.read()).decode("utf-8")
|
|||
|
|
|||
|
def analyze_douyin_template(video_path, audio_path=None, output_file=None):
|
|||
|
"""
|
|||
|
专门分析抖音热门视频模板的函数
|
|||
|
"""
|
|||
|
|
|||
|
STREAM_MODE = True
|
|||
|
|
|||
|
# 编码视频文件
|
|||
|
print("正在编码视频文件...")
|
|||
|
base64_video = encode_video(video_path)
|
|||
|
|
|||
|
# 编码音频文件(如果提供)
|
|||
|
content_list = [
|
|||
|
{
|
|||
|
"type": "video_url",
|
|||
|
"video_url": {"url": f"data:video/mp4;base64,{base64_video}"},
|
|||
|
}
|
|||
|
]
|
|||
|
|
|||
|
if audio_path and os.path.exists(audio_path):
|
|||
|
print("正在编码音频文件...")
|
|||
|
base64_audio = encode_audio(audio_path)
|
|||
|
content_list.append({
|
|||
|
"type": "audio_url",
|
|||
|
"audio_url": {"url": f"data:audio/wav;base64,{base64_audio}"},
|
|||
|
})
|
|||
|
|
|||
|
# 专业的抖音模板分析提示词
|
|||
|
template_analysis_prompt = """🎯 **抖音热门视频模板分析专家**
|
|||
|
|
|||
|
请按照以下专业框架分析这个视频的热门模板和套路:
|
|||
|
|
|||
|
## 📱 一、Hook勾子分析(前3-5秒)
|
|||
|
|
|||
|
### 勾子类型识别:
|
|||
|
1. **好奇类勾子**
|
|||
|
- "**是一种什么体验"
|
|||
|
- "如何不**也能**"
|
|||
|
- "如果你**,你会怎么样"
|
|||
|
|
|||
|
2. **借势类勾子**
|
|||
|
- "曾经被某人**,如今却**"
|
|||
|
- "某**大火,我却关心**"
|
|||
|
- "某明星都在用的**"
|
|||
|
|
|||
|
3. **痛点式勾子**
|
|||
|
- "为什么**,却**"
|
|||
|
- "不知道**?一定要**"
|
|||
|
- "最新**,你不会不知道吧"
|
|||
|
|
|||
|
4. **极限式勾子**
|
|||
|
- "这是全网最**"
|
|||
|
- "**一定要**"
|
|||
|
- "99%的人都不知道的**"
|
|||
|
|
|||
|
5. **恐吓式勾子**
|
|||
|
- "**揭密,千万不要**"
|
|||
|
- "如果你再不**,就会**"
|
|||
|
- "**将迎来**,赶紧**"
|
|||
|
|
|||
|
## 🎵 二、BGM模板分析
|
|||
|
- 是否使用热门音乐
|
|||
|
- 音乐类型和情绪
|
|||
|
- 与内容的匹配度
|
|||
|
|
|||
|
## 🎬 三、视频结构模板
|
|||
|
- **知识类**: 问题→解决方案→效果→引导
|
|||
|
- **剧情类**: 冲突→发展→反转→结局
|
|||
|
- **测评类**: 展示→使用→对比→推荐
|
|||
|
- **生活类**: 日常→亮点→感悟→互动
|
|||
|
|
|||
|
## 📝 四、文案套路
|
|||
|
- 标题党元素
|
|||
|
- 互动引导语
|
|||
|
- 情绪触发词
|
|||
|
|
|||
|
## 🔥 五、爆款元素
|
|||
|
- 反差萌
|
|||
|
- 共鸣点
|
|||
|
- 争议性
|
|||
|
- 实用性
|
|||
|
- 娱乐性
|
|||
|
|
|||
|
请严格按照以下JSON格式输出分析结果,不要添加```json```标记:
|
|||
|
|
|||
|
{
|
|||
|
"hook_analysis": {
|
|||
|
"hook_type": "具体的勾子类型",
|
|||
|
"hook_formula": "使用的具体公式",
|
|||
|
"hook_content": "视频中实际的勾子内容",
|
|||
|
"hook_timing": "勾子出现的时间段",
|
|||
|
"effectiveness_score": 8
|
|||
|
},
|
|||
|
"bgm_analysis": {
|
|||
|
"has_bgm": true,
|
|||
|
"bgm_type": "热门音乐/原创/无音乐",
|
|||
|
"music_style": "音乐风格",
|
|||
|
"emotion_match": "与内容情绪匹配度",
|
|||
|
"trend_alignment": "是否符合当前热门趋势"
|
|||
|
},
|
|||
|
"video_structure": {
|
|||
|
"category": "知识类/剧情类/测评类/生活类",
|
|||
|
"structure_pattern": "具体的结构模板",
|
|||
|
"time_breakdown": {
|
|||
|
"0-3s": "开头内容",
|
|||
|
"3-10s": "主体内容",
|
|||
|
"10-15s": "结尾内容"
|
|||
|
}
|
|||
|
},
|
|||
|
"copywriting_strategy": {
|
|||
|
"title_elements": ["标题中的关键元素"],
|
|||
|
"interaction_guides": ["互动引导语"],
|
|||
|
"emotional_triggers": ["情绪触发词"]
|
|||
|
},
|
|||
|
"viral_elements": {
|
|||
|
"key_factors": ["主要爆款因素"],
|
|||
|
"uniqueness": "独特性分析",
|
|||
|
"shareability": "分享传播价值"
|
|||
|
},
|
|||
|
"template_summary": {
|
|||
|
"main_template": "主要模板类型",
|
|||
|
"success_probability": "85%",
|
|||
|
"replication_difficulty": "复制难度评估",
|
|||
|
"optimization_suggestions": ["具体优化建议"]
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
请开始分析:"""
|
|||
|
|
|||
|
content_list.append({
|
|||
|
"type": "text",
|
|||
|
"text": template_analysis_prompt
|
|||
|
})
|
|||
|
|
|||
|
# 初始化客户端
|
|||
|
client = OpenAI(
|
|||
|
api_key="EMPTY",
|
|||
|
base_url="http://localhost:8000/v1",
|
|||
|
)
|
|||
|
|
|||
|
print(f"\n开始分析抖音视频模板...")
|
|||
|
print(f"Content项目数量: {len(content_list)}")
|
|||
|
print("="*60)
|
|||
|
|
|||
|
start_time = time.time()
|
|||
|
|
|||
|
# 发送请求
|
|||
|
completion = client.chat.completions.create(
|
|||
|
model="/root/autodl-tmp/llm",
|
|||
|
messages=[
|
|||
|
{
|
|||
|
"role": "system",
|
|||
|
"content": [{"type":"text","text": "You are a professional Douyin/TikTok viral video template analyzer."}]
|
|||
|
},
|
|||
|
{
|
|||
|
"role": "user",
|
|||
|
"content": content_list
|
|||
|
}
|
|||
|
],
|
|||
|
stream=STREAM_MODE,
|
|||
|
stream_options={"include_usage": True} if STREAM_MODE else None,
|
|||
|
)
|
|||
|
|
|||
|
# 处理流式响应
|
|||
|
if STREAM_MODE:
|
|||
|
full_response = ""
|
|||
|
usage_info = None
|
|||
|
|
|||
|
print("🎯 抖音模板分析结果:")
|
|||
|
print("-" * 40)
|
|||
|
|
|||
|
for chunk in completion:
|
|||
|
if chunk.choices:
|
|||
|
delta = chunk.choices[0].delta
|
|||
|
if delta.content:
|
|||
|
full_response += delta.content
|
|||
|
print(delta.content, end='', flush=True)
|
|||
|
else:
|
|||
|
usage_info = chunk.usage
|
|||
|
|
|||
|
end_time = time.time()
|
|||
|
|
|||
|
print("\n" + "="*60)
|
|||
|
print("✅ 分析完成!")
|
|||
|
print(f"⏱️ 耗时: {end_time - start_time:.2f} 秒")
|
|||
|
|
|||
|
if usage_info:
|
|||
|
print(f"📊 Token使用: {usage_info}")
|
|||
|
|
|||
|
# 保存结果
|
|||
|
if output_file:
|
|||
|
result_data = {
|
|||
|
"timestamp": datetime.now().isoformat(),
|
|||
|
"video_path": video_path,
|
|||
|
"analysis_result": full_response,
|
|||
|
"usage": str(usage_info) if usage_info else None,
|
|||
|
"processing_time": end_time - start_time
|
|||
|
}
|
|||
|
|
|||
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|||
|
json.dump(result_data, f, ensure_ascii=False, indent=2)
|
|||
|
|
|||
|
print(f"💾 结果已保存到: {output_file}")
|
|||
|
|
|||
|
return full_response
|
|||
|
|
|||
|
else:
|
|||
|
result = completion.choices[0].message.content
|
|||
|
print("🎯 抖音模板分析结果:")
|
|||
|
print("="*50)
|
|||
|
print(result)
|
|||
|
return result
|
|||
|
|
|||
|
def main():
|
|||
|
"""主函数"""
|
|||
|
|
|||
|
# 配置文件路径
|
|||
|
video_path = "/root/autodl-tmp/hot_video_analyse/source/sample_demo_2.mp4"
|
|||
|
audio_path = "/root/autodl-tmp/hot_video_analyse/source/transcription/sample_demo_1_audio.wav"
|
|||
|
|
|||
|
# 输出文件
|
|||
|
output_file = f"douyin_template_analysis_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
|
|||
|
|
|||
|
# 执行分析
|
|||
|
result = analyze_douyin_template(
|
|||
|
video_path=video_path,
|
|||
|
audio_path=audio_path,
|
|||
|
output_file=output_file
|
|||
|
)
|
|||
|
|
|||
|
print(f"\n{'='*60}")
|
|||
|
print("🎉 抖音热门视频模板分析完成!")
|
|||
|
|
|||
|
if __name__ == "__main__":
|
|||
|
main()
|