flat assembler
Message board for the users of flat assembler.

Index > Windows > [Demo] Short MP4 "video" in console screen

Author
Thread Post new topic Reply to topic
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1
Firstly, thanks to bitRAKE for his code snippet to split string (https://board.flatassembler.net/topic.php?t=21996)

This is a simple demo showing short MP4 "video" in Windows command prompt window.

Limitation: Don't know how to resize to bigger window

I am asking for code on how to allocate memory buffer, because I have another 4MB car racing "video" file which is impossible to play with my existing code.

Please let me know what you think about this. (The "video" file is split using "$" character, generated by myself from sample MP4 using FFMPEG)

Code:
format PE console
entry start

include 'win32a.inc'

section '.data' data readable writable

_filename       db      "airplane.mp4.txt",0
_buffer         rb      464728
_handle         dd      ?
_console        dd      ?
_len            dd      ?

section '.code' code readable executable

start:
        push    0
        push    FILE_ATTRIBUTE_NORMAL
        push    OPEN_EXISTING
        push    0
        push    FILE_SHARE_READ
        push    GENERIC_READ
        push    _filename
        call    [CreateFile]
        cmp     eax, INVALID_HANDLE_VALUE
        mov     dword [_handle], eax
        je      .error
        push    STD_OUTPUT_HANDLE
        call    [GetStdHandle]
        mov     dword [_console], eax
        push    0
        push    _len
        push    464728
        push    _buffer
        push    dword [_handle]
        call    [ReadFile]
        test    eax, eax
        jz      .error     

        call    Play

.error:
        push    0
        call    [ExitProcess]

Play:
; String split iterator (bitRAKE)
;
; RDI:  string to scan
; RCX:  length of string in characters, >0
; AX:   character to split on

        lea     edi, [_buffer]
        mov     ecx, dword [_len]     

.scan:
        mov     al, '$'
        mov     esi, edi
        repnz   scasb
        push    edi
        jnz     .last
        sub     edi, 1               ; don't count the split character in length
.last:
        push    ecx
        sub     edi, esi             ; length without terminator
        ;jz skip

        push    0                    ; FUNCTION (address:RSI, length:RDI)
        push    0
        push    edi
        push    esi
        push    dword [_console]
        call    [WriteConsole]
        push    200
        call    [Sleep]

.skip:
        pop     ecx                 ; characters to go
        pop     edi                 ; start
        cmp     ecx, 0
        jz      .done
        jmp     .scan

.done:
        ret

section '.idata' import readable writable

 library kernel32, 'KERNEL32.DLL'

 import kernel32,\
        GetStdHandle, 'GetStdHandle', \
        WriteConsole, 'WriteConsoleA', \
        GetTickCount, 'GetTickCount', \
        Sleep, 'Sleep', \
        CreateFile, 'CreateFileA', \
        ReadFile, 'ReadFile', \
        ExitProcess,'ExitProcess'
    


Description: Demo screen (airplane landing)
Filesize: 19.83 KB
Viewed: 1094 Time(s)

111.png


Description: "Video" file
Download
Filename: airplane.mp4.txt
Filesize: 453.84 KB
Downloaded: 59 Time(s)



Last edited by FlierMate1 on 21 Jun 2022, 14:11; edited 2 times in total
Post 19 Jun 2022, 18:18
View user's profile Send private message Reply with quote
I



Joined: 19 May 2022
Posts: 31
I
For console size need to take care of buffer, maybe something like
Code:
format PE CONSOLE
entry start
include 'win32a.inc'

struct  CONSOLE_SCREEN_BUFFER_INFOEX
  cbSize                        dd ?
  dwSize                        dd ?    ; COORD  low 16bits X, high 16bits Y
  dwCursorPosition              dd ?    ; COORD
  wAttributes                   dw ?
  srWindow                      rd 2    ; SMALL_RECT (16bits) Left,Top,Right,Bottom
  dwMaximumWindowSize           dd ?    ; COORD
  wPopupSttributes              dw ?    ;
  bFullScreenSupported          dd ?    ; BOOL
  ColorTable                    rd 10h  ; COLORREF array
ends

;----------------------------------
section '.text' code readable executable

 SomeText       db 'Hello',10
 .len           = $ - SomeText

  start:
        push    STD_OUTPUT_HANDLE
        call    [GetStdHandle]
        mov     [hStdOut],eax

 ; Set console screen buffer size 128 characters by 40 characters
        mov     [CsbiEx.cbSize],sizeof.CONSOLE_SCREEN_BUFFER_INFOEX             ; Structure size
        push    CsbiEx
        push    [hStdOut]
        call    [GetConsoleScreenBufferInfoEx]                                  ; X,Y are in characters
        mov     [CsbiEx.dwSize],128 or (40 shl 16)                              ; Screen Buffer Size X,Y, increase as required
        mov     [CsbiEx.srWindow],0                                             ; Upper Left Buffer position X,Y
        mov     [CsbiEx.srWindow+4],128 or (40 shl 16)                          ; Lower Right Buffer position X,Y
        mov     [CsbiEx.dwMaximumWindowSize],128 or (40 shl 16)                 ; Max Size of Window X,Y
        invoke  SetConsoleScreenBufferInfoEx,[hStdOut],CsbiEx

 ; Offset position on display, if required
        call    [GetConsoleWindow]
        push    SWP_NOSIZE      ; Flags, dont change size
        push    0               ; Height, ignored with SWP_NOSIZE
        push    0               ; Width, ignored with SWP_NOSIZE
        push    10              ; Y Offset 10
        push    40              ; X Offset 40
        push    -1              ; HWND_TOPMOST (Z Order, change as required)
        push    eax             ; Handle from GetConsoleWindow
        call    [SetWindowPos]  ; Offset Window position and make TOPMOST

; write some text to console
        push    0
        push    BytesRet
        push    SomeText.len
        push    SomeText
        push    [hStdOut]
        call    [WriteFile]

; wait 5 seconds
        push    5000
        call    [Sleep]

; exit
        push    0
        call    [ExitProcess]


;========================================
section '.data' data readable writeable

 hStdOut        dd ?
 BytesRet       dd ?
 CsbiEx         CONSOLE_SCREEN_BUFFER_INFOEX

;-------------------------------------------
section '.idata' import data readable writeable

 library        kernel32,'KERNEL32.DLL',\
                user32,'USER32.DLL'

 import kernel32,\
                GetStdHandle,'GetStdHandle',\
                GetConsoleWindow,'GetConsoleWindow',\
                GetConsoleScreenBufferInfoEx,'GetConsoleScreenBufferInfoEx',\
                SetConsoleScreenBufferInfoEx,'SetConsoleScreenBufferInfoEx',\
                WriteFile,'WriteFile',\
                Sleep,'Sleep',\
                ExitProcess,'ExitProcess'
 import user32,\
                 SetWindowPos,'SetWindowPos'
    


Maybe MapViewOfFile for file?
Post 20 Jun 2022, 07:01
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3489
Location: vpcmipstrm
bitRAKE
With windows 10 MS is pushing towards better VT100 support - so, everything old is new again. I was just thinking the other day of coding a little program to display some of the old terminal animations. There are interesting effects like twinkling stars and stuff that looked cool at 300 baud. The stuff people were able to do in such a constrained environment in quite amazing.

_________________
¯\(°_o)/¯ unlicense.org
Post 20 Jun 2022, 08:16
View user's profile Send private message Visit poster's website Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1
@I, thanks for the code, it works as expected. The default console window size on my Windows is actually big enough, 120x30, to fit my animated ASCII art.

I wrote:
Maybe MapViewOfFile for file?


This sounds like a cool API function. I will study more if I need to cater for large file.

bitRAKE wrote:
I was just thinking the other day of coding a little program to display some of the old terminal animations...The stuff people were able to do in such a constrained environment in quite amazing.


I think you also mean demoscene coders back in the old days.

Like...bad apple ? (
https://en.wikipedia.org/wiki/Bad_Apple!!#Use_as_a_graphical_and_audio_test )

Thanks for your "string split " code again!
Post 20 Jun 2022, 15:48
View user's profile Send private message Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1
The animated ASCII art was converted from this real MP4 using a simple algorithm:

https://www.videvo.net/video/ek-boeing-777-landing/4036/


Description: Side-by-side comparison
Filesize: 640.07 KB
Viewed: 1017 Time(s)

Screenshot 2022-06-21 222547.png




Last edited by FlierMate1 on 21 Jun 2022, 14:26; edited 2 times in total
Post 20 Jun 2022, 16:05
View user's profile Send private message Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1
It is not only that, can also applies color to the ASCII art, hence, ANSI art. But I had tested it before, it is slower when playing the animated ANSI art.

Not just from MP4 video, ASCII art can also be converted from animated GIF frame by frame.

I plan to create a complete ASCII/ANSI art Studio (convert & play), but not sure its usefulness, or if there is any similar tool on GitHub already.


Description: Motion ASCII art converted from animated GIF
Filesize: 50.24 KB
Viewed: 1058 Time(s)

anigif.png


Description: ANSI art converted from real photo
Filesize: 105.52 KB
Viewed: 1058 Time(s)

ansiart.png


Post 21 Jun 2022, 06:12
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3489
Location: vpcmipstrm
bitRAKE
https://www.ansilove.org/ is the one I know of. Back in the BBS days I think most of them were created by hand, with very limited colors/characters.

Have you seen Picnic's Hobby Basic? He's included some ANSI art amongst his example programs. (I haven't tried them on the latest Win10/11, but they should work even better, imho.)

_________________
¯\(°_o)/¯ unlicense.org
Post 21 Jun 2022, 07:11
View user's profile Send private message Visit poster's website Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1
Interestingly, "ansilove" does the opposite, it converts ANSI art to PNG image file.
Yes, I too notice those are created by hand.

I am aware of Picnic's HB, but have never downloaded it before. It is an interpreter and closed-source. From his thread, yes, I too notice ANSI art created by hand.
(I tried to download HB.zip but Windows reported 'Failed - Virus detected', I have disabled the Real-time Virus &Threat Protection before this, but suddenly have no clue where to turn off App & Browser Control Rolling Eyes )

Also, from your String Split Iterator, I forgot to set the ECX to length of string, and it still work, must be based on random value in ECX register. Mad
Post 21 Jun 2022, 14:02
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3489
Location: vpcmipstrm
bitRAKE
FlierMate1 wrote:
I tried to download HB.zip but Windows reported 'Failed - Virus detected', I have disabled the Real-time Virus &Threat Protection before this
If I had to contend with MS's definition of security [beyond disabling it] then I doubt I could use Windows. It's more like a bit religion where some oracle in the sky says, "these bits are bad" and millions of machines echo "these bits are bad". There always needs to be bad bits - how else you going to know how protected you are?

_________________
¯\(°_o)/¯ unlicense.org
Post 21 Jun 2022, 16:34
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1303
Location: Paradise Falls
Picnic
Hello FlierMate1, bitRAKE,

FlierMate1 wrote:
I am aware of Picnic's HB, but have never downloaded it before. It is an interpreter and closed-source. From his thread, yes, I too notice ANSI art created by hand.
(I tried to download HB.zip but Windows reported 'Failed - Virus detected', I have disabled the Real-time Virus &Threat Protection before this, but suddenly have no clue where to turn off App & Browser Control Rolling Eyes )


Sorry to hear that. HB.zip is clean. Still, Windows refuses to run it (or even download it sometimes) unless the the Real-time Virus & Threat Protection is disabled. Nevertheless, if you manage to skip Windows security you'll see that HB runs quite smooth in Windows 10.

bitRAKE wrote:
If I had to contend with MS's definition of security [beyond disabling it] then I doubt I could use Windows. It's more like a bit religion where some oracle in the sky says, "these bits are bad" and millions of machines echo "these bits are bad". There always needs to be bad bits - how else you going to know how protected you are?

Recently i download s suspicious file. I knew it and took my chances. I lost an external disk (it locked and asking me for money to unlock it). Windows 10 didn't complain about anything, my AV the same.
Post 21 Jun 2022, 21:49
View user's profile Send private message Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1
Picnic wrote:

Sorry to hear that. HB.zip is clean. Still, Windows refuses to run it (or even download it sometimes) unless the the Real-time Virus & Threat Protection is disabled. Nevertheless, if you manage to skip Windows security you'll see that HB runs quite smooth in Windows 10.


I understand, my experimental compiler also went through the same issue, falsely detected by Windows (and several other AVs) as malware. I remember must turn off several other settings besides Virus & Threat Protection to successfully download certain .Zip files.
Thank you for the kind message, Picnic.
Post 22 Jun 2022, 08:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18846
Location: In your JS exploiting you and your system
revolution
But how to convince the mainstream users when they fully believe all the AV marketing about how foolproof AVs are?

You upload your code to some place, and then the users demand it be removed because of the dangerous nasty viruses inside. Sad And then your account if banned. And then you get onto a blacklist that the sites share with each other. Sad Sad


Last edited by revolution on 22 Jun 2022, 11:40; edited 2 times in total
Post 22 Jun 2022, 09:04
View user's profile Send private message Visit poster's website Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 526
Ali.Z
a campaign, "AV is PUP"

_________________
Asm For Wise Humans
Post 22 Jun 2022, 11:35
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3489
Location: vpcmipstrm
bitRAKE
Picnic wrote:
Recently i download s suspicious file. I knew it and took my chances. I lost an external disk (it locked and asking me for money to unlock it). Windows 10 didn't complain about anything, my AV the same.
A fresh install of Windows 11 will quarantine my own work - it is the virus and I already paid the ransom, lol.

The process I imagine is boot into BIOS, load image off network. This requires a backup process if work is to persist across images. It makes all local drives disposable. Maybe loose a day of work, but zero down time.

_________________
¯\(°_o)/¯ unlicense.org
Post 24 Jun 2022, 17:51
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.