unused
This commit is contained in:
parent
d69645584a
commit
ec46db38ec
2 changed files with 92 additions and 3 deletions
43
generate.py
43
generate.py
|
|
@ -626,6 +626,49 @@ def kling_v2v_reference(item, character, keep=False):
|
|||
img.add(ai)
|
||||
return ai
|
||||
|
||||
def wan_reference_to_video(foreground, background, keep=False):
|
||||
foreground_url = public_video_url(foreground)
|
||||
background_url = public_video_url(background)
|
||||
prompt = "Use the character from @Video1 and use @Video2 as background"
|
||||
model = "wan/v2.6/reference-to-video"
|
||||
prompt_hash = hashlib.sha1((prompt + foreground_url + background_url).encode()).hexdigest()
|
||||
output = "/srv/pandora/static/power/cache/%s_%s/ai.mp4" % (
|
||||
item.public_id,
|
||||
prompt_hash,
|
||||
)
|
||||
for d in [5, 10]:
|
||||
if d > item.sort.duration:
|
||||
break
|
||||
duration = d
|
||||
|
||||
data = {
|
||||
"prompt": prompt,
|
||||
"video_urls": [
|
||||
foreground_url,
|
||||
background_url,
|
||||
]
|
||||
"aspect_ratio": "16:9",
|
||||
"resolution": "1080p",
|
||||
"enable_prompt_expansion": false,
|
||||
"multi_shots": true,
|
||||
"enable_safety_checker": false
|
||||
}
|
||||
print(data)
|
||||
handler = fal_client.submit(model, arguments=data)
|
||||
request_id = handler.request_id
|
||||
print(request_id)
|
||||
result = fal_wait_for(model, request_id)
|
||||
print(result)
|
||||
output_url = result["video"]["url"]
|
||||
ox.net.save_url(output_url, output, overwrite=True)
|
||||
ai = add_ai_variant(item, output, "ai:foreground-background")
|
||||
ai.data["prompt"] = ox.escape_html(prompt)
|
||||
ai.data["model"] = model
|
||||
ai.save()
|
||||
if not keep:
|
||||
shutil.rmtree(os.path.dirname(output))
|
||||
return ai
|
||||
|
||||
def replace_character_motion_control(item, character, keep=False):
|
||||
if isinstance(item, str):
|
||||
item = Item.objects.get(public_id=item)
|
||||
|
|
|
|||
52
render.py
52
render.py
|
|
@ -155,7 +155,7 @@ def compose(clips, fragment, target=150, base=1024, voice_over=None, options=Non
|
|||
|
||||
scene['front']['V2'].append({
|
||||
'duration': clip_duration,
|
||||
'item': clip['item'],
|
||||
'id': clip['id'],
|
||||
'src': src,
|
||||
"filter": {
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ def compose(clips, fragment, target=150, base=1024, voice_over=None, options=Non
|
|||
}
|
||||
scene['audio-front']['A2'].append({
|
||||
'duration': clip_duration,
|
||||
'item': clip['item'],
|
||||
'id': clip['id'],
|
||||
'src': audio,
|
||||
'filter': audio_filter.copy()
|
||||
})
|
||||
|
|
@ -1039,7 +1039,7 @@ def generate_clips(options):
|
|||
voice_over[fragment][type] = []
|
||||
vo_variant = {
|
||||
"variant": variant,
|
||||
"item": source.public_id,
|
||||
"id": vo.public_id,
|
||||
"src": target,
|
||||
#"duration": format_duration(source.duration, fps, True),
|
||||
"duration": source.duration,
|
||||
|
|
@ -1066,3 +1066,49 @@ def generate_clips(options):
|
|||
voice_over[fragment][type].append(vo_variant)
|
||||
with open(os.path.join(prefix, 'voice_over.json'), 'w') as fd:
|
||||
json.dump(voice_over, fd, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
|
||||
def render_stats(offset):
|
||||
stats = {
|
||||
"source": [],
|
||||
"ai": [],
|
||||
}
|
||||
base_prefix = Path(default_prefix) / 'render' / str(offset)
|
||||
for folder in os.listdir(base_prefix):
|
||||
folder = base_prefix / folder
|
||||
scene_json = folder / "scene.json"
|
||||
if not os.path.exists(scene_json):
|
||||
continue
|
||||
with open(scene_json) as fd:
|
||||
scene = json.load(fd)
|
||||
for timeline, tdata in scene.items():
|
||||
if isinstance(tdata, list):
|
||||
continue
|
||||
for track, clips in tdata.items():
|
||||
for clip in clips:
|
||||
if 'src' in clip:
|
||||
if 'id' not in clip:
|
||||
print(clip)
|
||||
continue
|
||||
if 'ai:' in clip['src']:
|
||||
stats['ai'].append(clip['id'])
|
||||
else:
|
||||
stats['source'].append(clip['id'])
|
||||
return stats
|
||||
|
||||
|
||||
def update_unused():
|
||||
import itemlist.models
|
||||
import item.models
|
||||
l = itemlist.models.List.objects.get(name='Unused Material')
|
||||
used = []
|
||||
for folder in os.listdir(Path(default_prefix) / 'render'):
|
||||
if folder.isdigit():
|
||||
x = render_stats(folder)
|
||||
used += x['source']
|
||||
used += x['ai']
|
||||
for i in Item.objects.all().exclude(public_id__in=set(used)).filter(data__type__icontains='source'):
|
||||
l.add(i)
|
||||
for i in l.items.filter(public_id__in=set(used)):
|
||||
l.remove(i)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue