Spaces:
Paused
Paused
Update zh.py
Browse files
zh.py
CHANGED
|
@@ -245,7 +245,7 @@ async def main():
|
|
| 245 |
with av.open('output.mp4', mode='w') as writer:
|
| 246 |
video = writer.add_stream('h264', rate=8)
|
| 247 |
video.height = reader.shape[1]
|
| 248 |
-
video.width = reader.
|
| 249 |
video.pix_fmt = 'yuv420p'
|
| 250 |
with av.open(io.BytesIO(await sys.modules.get(__name__).google(scripts[0].get('narration'))), format='mp3') as container:
|
| 251 |
audio = writer.add_stream('aac', rate=container.streams.audio[0].rate)
|
|
@@ -269,7 +269,7 @@ async def main():
|
|
| 269 |
pathlib.Path(__file__).resolve().parent.joinpath('subtitle.ass').write_text(pathlib.Path(__file__).resolve().parent.joinpath('subtitle').read_text().replace('prompt', scripts[0].get('narration').replace(',', ', ')))
|
| 270 |
graph.link_nodes(graph.add_buffer(height=video.height, width=video.width, format='rgb24'), graph.add('subtitles', 'subtitle.ass'), graph.add('buffersink')).configure()
|
| 271 |
frames = []
|
| 272 |
-
for frame in reader
|
| 273 |
graph.push(av.VideoFrame.from_ndarray(frame))
|
| 274 |
while True:
|
| 275 |
try: frames += graph.pull(),
|
|
@@ -288,7 +288,7 @@ async def main():
|
|
| 288 |
with aiohttp.MultipartWriter('form-data') as mpwriter:
|
| 289 |
mpwriter.append(script.get('prompt')).set_content_disposition('form-data', name='prompt')
|
| 290 |
mpwriter.append(negative).set_content_disposition('form-data', name='negative')
|
| 291 |
-
mpwriter.append(buffer.getvalue(), {'Content-Type':'
|
| 292 |
tail = 'https://chaowenguo-zh.ms.show/'
|
| 293 |
async with client.post(urllib.parse.urljoin(tail, 'start'), data=mpwriter) as _: pass
|
| 294 |
while True:
|
|
@@ -299,38 +299,37 @@ async def main():
|
|
| 299 |
case 404: await asyncio.sleep(60)
|
| 300 |
case 500 | 429: break
|
| 301 |
case 200:
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
writer.mux(video.encode(frame))
|
| 334 |
outer = True
|
| 335 |
break
|
| 336 |
except aiohttp.ClientConnectionError: pass
|
|
|
|
| 245 |
with av.open('output.mp4', mode='w') as writer:
|
| 246 |
video = writer.add_stream('h264', rate=8)
|
| 247 |
video.height = reader.shape[1]
|
| 248 |
+
video.width = reader.shape[2]
|
| 249 |
video.pix_fmt = 'yuv420p'
|
| 250 |
with av.open(io.BytesIO(await sys.modules.get(__name__).google(scripts[0].get('narration'))), format='mp3') as container:
|
| 251 |
audio = writer.add_stream('aac', rate=container.streams.audio[0].rate)
|
|
|
|
| 269 |
pathlib.Path(__file__).resolve().parent.joinpath('subtitle.ass').write_text(pathlib.Path(__file__).resolve().parent.joinpath('subtitle').read_text().replace('prompt', scripts[0].get('narration').replace(',', ', ')))
|
| 270 |
graph.link_nodes(graph.add_buffer(height=video.height, width=video.width, format='rgb24'), graph.add('subtitles', 'subtitle.ass'), graph.add('buffersink')).configure()
|
| 271 |
frames = []
|
| 272 |
+
for frame in reader:
|
| 273 |
graph.push(av.VideoFrame.from_ndarray(frame))
|
| 274 |
while True:
|
| 275 |
try: frames += graph.pull(),
|
|
|
|
| 288 |
with aiohttp.MultipartWriter('form-data') as mpwriter:
|
| 289 |
mpwriter.append(script.get('prompt')).set_content_disposition('form-data', name='prompt')
|
| 290 |
mpwriter.append(negative).set_content_disposition('form-data', name='negative')
|
| 291 |
+
mpwriter.append(buffer.getvalue(), {'Content-Type':'application/octet-stream'}).set_content_disposition('form-data', name='image', filename='image.pyz')
|
| 292 |
tail = 'https://chaowenguo-zh.ms.show/'
|
| 293 |
async with client.post(urllib.parse.urljoin(tail, 'start'), data=mpwriter) as _: pass
|
| 294 |
while True:
|
|
|
|
| 299 |
case 404: await asyncio.sleep(60)
|
| 300 |
case 500 | 429: break
|
| 301 |
case 200:
|
| 302 |
+
reader = numpy.load(io.BytesIO(await get.content.read())).get('arr_0')
|
| 303 |
+
with av.open(io.BytesIO(await sys.modules.get(__name__).google(script.get('narration'))), format='mp3') as container:
|
| 304 |
+
speed = builtins.float(container.streams.audio[0].duration * container.streams.audio[0].time_base) / 10
|
| 305 |
+
print(speed)
|
| 306 |
+
graph = av.filter.Graph()
|
| 307 |
+
graph.link_nodes(graph.add_abuffer(template=container.streams.audio[0]), graph.add('atempo', builtins.str(speed)), graph.add('apad', 'whole_dur=10'), graph.add('atrim', '0:10'), graph.add('abuffersink')).configure()
|
| 308 |
+
frames = []
|
| 309 |
+
for frame in container.decode():
|
| 310 |
+
graph.push(frame)
|
| 311 |
+
while True:
|
| 312 |
+
try: frames += graph.pull(),
|
| 313 |
+
except (av.BlockingIOError, av.EOFError): break
|
| 314 |
+
for frame in frames:
|
| 315 |
+
frame.time_base = audio.codec_context.time_base
|
| 316 |
+
frame.pts = audioPts
|
| 317 |
+
audioPts += frame.samples
|
| 318 |
+
writer.mux(audio.encode(frame))
|
| 319 |
+
graph = av.filter.Graph()
|
| 320 |
+
pathlib.Path(__file__).resolve().parent.joinpath('subtitle.ass').write_text(pathlib.Path(__file__).resolve().parent.joinpath('subtitle').read_text().replace('prompt', script.get('narration').replace(',', ', ')))
|
| 321 |
+
graph.link_nodes(graph.add_buffer(height=video.height, width=video.width, format='rgb24'), graph.add('subtitles', 'subtitle.ass'), graph.add('buffersink')).configure()
|
| 322 |
+
frames = []
|
| 323 |
+
for frame in reader:
|
| 324 |
+
graph.push(av.VideoFrame.from_ndarray(frame))
|
| 325 |
+
while True:
|
| 326 |
+
try: frames += graph.pull(),
|
| 327 |
+
except (av.BlockingIOError, av.EOFError): break
|
| 328 |
+
for frame in frames:
|
| 329 |
+
frame.time_base = video.codec_context.time_base
|
| 330 |
+
frame.pts = videoPts
|
| 331 |
+
videoPts += video.codec_context.time_base.denominator / reader.streams.video[0].average_rate
|
| 332 |
+
writer.mux(video.encode(frame))
|
|
|
|
| 333 |
outer = True
|
| 334 |
break
|
| 335 |
except aiohttp.ClientConnectionError: pass
|