Skip to content

Commit

Permalink
removed vide frames generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraflame4 committed Apr 20, 2023
1 parent c8e3438 commit 45019ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
4 changes: 3 additions & 1 deletion CliRenderer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import concurrent.futures
import os

from PIL import Image
from rich.progress import track
from rich.text import Text

import numpy.typing as npt
from CliRenderer.chartools import PixelsPerChar, split_to_char, pixels2Char
from CliRenderer.colorer import color_twotone, color_char
from CliRenderer.core import Flags
Expand Down
40 changes: 10 additions & 30 deletions CliRenderer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import imageio as iio
from rich.progress import track
from io import StringIO
from CliRenderer import render, Flags
from CliRenderer import render, Flags, render_frames


def cli_main(source: Path = typer.Argument(..., help="The path to source image."),
Expand All @@ -17,10 +17,9 @@ def cli_main(source: Path = typer.Argument(..., help="The path to source image."
height: int = typer.Option(50, "--height", "-h", min=1, help="The height of the output in no. of lines"),
autosize: bool = typer.Option(False,
help="Automatically sets the output size to fit the terminal. Overrides --width and --height. Only works on supported terminals."),
video: bool = typer.Option(False, "--video", "-v", help="Set this flag if source is a video."),

output: Path = typer.Option(None, "--out", "-o",
help="Saves the output to a file. Compulsory if --video is set."),
playback: bool = typer.Option(False, "--playback", "-p",help="Set this flag to playback the source if it is an output (--out) from this program."),
help="Saves the output to a file."),
debug: bool = typer.Option(False,
help="Enables debug mode. This will save the intermediate images to the build folder."),
bg_intensity: float = typer.Option(1.0, "--bg-intensity", "-bgi", min=0.0, max=1.0,
Expand All @@ -37,41 +36,22 @@ def cli_main(source: Path = typer.Argument(..., help="The path to source image."
import shutil
width, height = shutil.get_terminal_size()

if video:

if output is None:
typer.echo("--out must be set if source is a video.")
raise typer.Exit(code=1)

texts = []
metadata = iio.v3.immeta(source, plugin="pyav")

total_frames = metadata["duration"] * metadata["fps"] + 10
typer.echo("Total estimated frames count: "+str(total_frames))
for frame in track(iio.imiter(source, plugin="pyav"), description="Processing...",total=total_frames):
source_image = Image.fromarray(frame)
text = render(source_image, (width, height), bg_intensity)
console.print(text)
texts.append(console.export_text(styles=True))


output.parent.mkdir(parents=True, exist_ok=True)
typer.echo(f"Saving to {output}...")
with open(output, "w") as f:
json.dump({"meta":{
"fps":metadata["fps"],
},"frames":texts}, f)

return

source_image = Image.fromarray(iio.v3.imread(source))
text = render(source_image, (width, height), bg_intensity)

console.print(text)
string = console.export_text(styles=True)
print(string)


if output is not None:
typer.echo(f"Saving output to {output}...")
output.parent.mkdir(parents=True, exist_ok=True)
with open(output, "w") as f:
f.write(string)

print(string)
def main():
typer.run(cli_main)

Expand Down

0 comments on commit 45019ad

Please sign in to comment.