-1

Okay this one is a doozy

Let's start with what I have and what I have done then the issues I am having.


First I took a video and extracted the frames with FFMPEG which left me with a ton of frames. As we all know CMD can't do much with jpg files. So I used a program that allowed me to convert them to ASCII. With a little batch magic, I got something working to mass convert all of the images.


Code for that

JPEGCompiler.bat

@echo off
set /p video=Drag Video into Console (Currently Limited to C:/): 
ffmpeg -i %video% -an -f image2 "output_%%05d.jpg"

(This works with the help of FFMPEG )


I then had to create a list of the files for the next batch to grab. This wasn't super difficult.

Jpglist.bat


dir /B *.jpg >> JPEGList.txt

And finally, a way of automating everything with an increasing variable.

JPEGCompiler.bat

@echo off
setlocal enableextensions enabledelayedexpansion
set cycles=0

cd> CD.txt

for /F "delims=" %%i in (CD.txt) do set "CD=%%i"
for /F "delims=" %%i in (CDD.txt) do set "CD=%%i"

type cd.txt | sed "s/C://">> CDD.txt

:startpoint
set "xprvar="
for /F "skip=%cycles% delims=" %%i in (JPEGList.txt) do if not defined xprvar set "xprvar=%%i"

set /a cycles=cycles+1
ascii-image-converter.exe %CDD%%xprvar% --save-txt .

goto startpoint

Using what I learned previously with the increasing variable, I used the same method to grab all of the text files and order them into a list for CMD

Textlist.bat


dir /B *.txt >> TextList.txt

That brings me to this point.

TEXTCompiler.bat


@echo off
color 02
set cycles=0

:startpoint


for /F "skip=%cycles% delims=" %%i in (TextList.txt) do set "xprvar=%%i"&goto nextline
:nextline

set /a cycles=cycles+1

type %xprvar%

call waitfor

goto startpoint

(call waitfor is an attempt at using precise timing but it didn't really make a difference with or without it I get a little more control but the same issues are present)

Output frames

The code runs fine but there are some issues. With the cls command its like it will clear the screen way too fast and the video gets slowly and occasionally eaten from the bottom up. However, without that cls, the ASCII art video scrolls like a boss.

There are also issues with sync from the original video. (bat plays fast or slow depending on how it's feeling?)

So my question is, is there a way to sync fps? What's the best way to go about this?

This playback can be seen here!

Playback without CLS

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • 4
    Instead of [begging us not to down-vote](https://stackoverflow.com/revisions/68452225/4), you should better put in the effort to make your question clearer and on-topic; "what's the best way" is mostly too broad; please consult [ask]… – aschipfl Jul 20 '21 at 09:59

1 Answers1

0

There are two key things you should research:

1) Implement frame rate in Batch.

  • See Dave Benhams Snake.bat for a good example.

2) Update console Display without using CLS

Note also:
Goto and call are inefficient and should be avoided for any application where a fast and consistent framerate is desired. Use instead a codeblock contained within an infinite for /L loop.

An example that generates an animation:

@Echo off & CD /D "%~dp0"
 For /f %%e in ('Echo Prompt $E^|cmd') Do set "\E=%%e"
 <nul Set /P "=%\E%[?25l"
 Cls & Mode 90,40
 Set /A "Files=0","FC=1"

 Echo(Choose Framerate: %= Defaults to 25 fps after 4 seconds =%
 Echo(1] 50fps
 Echo(2] 33fps
 Echo(3] 25fps
 Echo(4] 20fps
 Echo(5] 17fps
 Echo(6] 14fps
 Echo(7] 12.5fps
 Echo(8] 10fps
 Echo(9] 6fps

 For /f "delims=" %%G in ('Choice /T 4 /N /C:123456789 /D 3')Do (
  If %%G LSS 8 Set /A "delay=%%G+1"
  If %%G==8 Set "delay=10"
  If %%G==9 Set "delay=16"
 )

 Cls
 Setlocal EnableExtensions EnableDelayedExpansion

 For %%i in (5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5)Do (
  Set /A Files+=1
  Call :CreateCube %%i "infile!Files!.txt"
 )

 For /L %%i in ()Do (
  %= Calculate time elapsed in centiseconds =%
  for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, tDiff=t2-t1"
  if !tDiff! lss 0 set /a tDiff+=24*60*60*100
  %= update frame if framerate delay expired =%
  if !tDiff! geq !delay! (
   %= use modulus based increment to cycle through file count =%
   Set /A "FC=FC %% Files + 1"
   %= Assign offset based on current filecount =%
   If !FC! GTR 10 (If !Offset! GTR 1 Set /A "Offset-=1")Else Set "offset=!FC!"
   %= affect offset; Clear screen to cursor pos =%
   <nul set /P "=%\E%[!offset!G%\E%[!Offset!d%\E%[1J"
   %= read file; clear line; offset cursor; output line; emit linefeed - Redirecting block to con =%
   (For /f "Delims=" %%G in (infile!FC!.txt)Do <nul set /P "=%\E%[K%\E%[!offset!G%%G%\E%[E") > Con
   %= Clear remainder of screen =%
   <nul Set /P "=%\E%[0J"
   %= Update previous time =%
   set /a t1=t2
  )
 )

:CreateCube <size>
:# golfed script for outputting a shaded multi color cube
:# https://codegolf.stackexchange.com/a/224741/92319
@echo off&Cls&Set $=Set &CHCP 65001 > nul
If "%~1"=="" (Echo(%~n0 Integer Outfile.ext&Exit /B)
If "%~2"=="" (Echo(%~n0 Integer Outfile.ext&Exit /B)
%$%/A x=%1,h=x*2,z=0
%$%F=For /L %%a in (1 1 &%$%P=^<nul set/p &%$%C= If %%y LEQ %1 
((%f:a=y%!h!)Do (%$%/a w=x-z
%F%!w!)Do %P%"=%\E%C"
%F%!z!)Do%C%(%P%"=%\E%[38;2;;120;%%a0m_|")Else %P%=%\E%[4m%\E%[38;2;120;;%%a0m\\%\E%[0m
%F%%1)Do%C%(%P%"=%\E%[38;2;120;;%%a0m▲▼")Else %P%=%\E%[38;2;;120;%%a0m_\
%C:EQ=SS%(%$%/A z+=1)Else%C:If=If not%%$%/A z-=1)&Echo(%\E%[0m))>"%~2"
T3RR0R
  • 2,747
  • 3
  • 10
  • 25