Jump to content
Welcome, welcome! Come in and register, and have some developer coffee. 👨‍💻 ×

MP4 to ANSI / ASCII Art Converter


Recommended Posts

Just to convert static image or even animated GIF to ASCII / ANSI art is no fun. Convert and playback characters of MP4 video in console screen or window with fixed-width font will be more exciting.

Either web or desktop app is possible.  Anyone?

I will post an example tonight.

Edited by FlierMate
  • Like 1
Link to post
Share on other sites

MP4TXT.zip is included containing 3 large text files which is animated ASCII art!

Does anyone want to try to animate these large text files? Each frame in the text file is delimited with "$" dollar sign symbol.

Just load the text file, split using "$" dollar sign symbol to array of string buffer, then start animating from first frame to last frame with short interval. It is fun!

 The conversion is done through open-source FFMPEG library.

MP4TXT.png.4c8acfac9d5af6a95a9492433cc85b2c.png

 

MP4TXT.zip

Link to post
Share on other sites

https://7sol1.csb.app/

  • Love 2
Link to post
Share on other sites
24 minutes ago, FlierMate said:

That is very cool! How did you do that? 🤩

It's a website called codesandbox.io. The name of the site kind of explains what it is, and if you look at the left sidebar almost at the top, there is image.png which you can click to see the source.

Basically:

1. Load the 'video' files into a variable

2. Split with the '$' character from number 1

3. Loop through the array from number 2

4. In the loop (from i = 0), set a timeout to change the content of the 'video box' with the current frame (i) content, with the timeout value of i * 50 (milliseconds)

  • Like 1
Link to post
Share on other sites
Posted (edited)
9 minutes ago, Malkuth said:

It's a website called codesandbox.io. The name of the site kind of explains what it is, and if you look at the left sidebar almost at the top, there is image.png which you can click to see the source.

Basically:

1. Load the 'video' files into their own variables

2. Split with the '$' character for each variables

3. Loop through the array from 2

4. In the loop (from i = 0), set a timeout to change the content of the 'video box' with the current frame (i) content, with the timeout value of i * 50 (milliseconds)

Amazing @Malkuth! I am totally new to this kind of sophisticated technology.   I can see that is a lot of coding.

It made me laugh when you named it as YouToob and "Buffering....". 😇

Edited by FlierMate
  • Like 1
Link to post
Share on other sites
4 minutes ago, FlierMate said:

Amazing @Malkuth! I am totally new to this kind of sophisticated technology.   I can see that is a lot of coding.

Yes, CodeSandbox is amazing indeed! Have fun playing around in it. Also thanks for the "video" files. They are really nice. 😄

  • Haha 1
Link to post
Share on other sites
Posted (edited)
25 minutes ago, Malkuth said:

Yes, CodeSandbox is amazing indeed! Have fun playing around in it. Also thanks for the "video" files. They are really nice. 😄

You're most welcomed! Since you already have the online player, I will see how to convert MP4 to animated ASCII art, in quick and easy way. It was quite slow and took many steps to generate each text file last time. 

Generally, these are the steps:

  1. Use FFMPEG command-line utility to extract frames from given MP4 video (from start to end) with the frame rate as optional parameter (i.e. how frequent to extract one frame, 1s, 0.1s....etc)
  2. Convert each and every JPG/PNG image frame (sorted according to sequence numbering) with my IMG2ASCII C# code snippet. Separate each frame with predefined delimiter.

The IMG2ASCII code snippet in C# is as simple as this:

using System;
using System.Drawing;
using System.IO;

namespace BMP2ASCII
{
   class Program
   {
       static void Main(string[] args)
       {
           char[] ascii = new char[] { '#', '#', '*','*','+','+','+',';',';',':',':',',',',','.','.',' ',' ' };
           Bitmap bmp = new Bitmap("C:\\panda.jfif");
           string txt = null;
           
           for (int y = 0; y < bmp.Height; y++)
           {
               for (int x = 0; x < bmp.Width; x++)
               {
                   uint rgb = ((uint)bmp.GetPixel(x, y).ToArgb() & 0xFFFFFF) / 1048576;
                   //Console.Write(ascii[rgb]);
                   txt += ascii[rgb];
               }
               //Console.WriteLine();
               txt += "\n";
           }

           File.WriteAllText(@"C:\Users\khann\Desktop\panda.txt", txt);
           Console.ReadLine();
       }
   }
}

 

Edited by FlierMate
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...