Jump to content




Mp4 video player [Proof of concept]


8 replies to this topic

#1 Jummit

  • Members
  • 306 posts
  • LocationJulfander Squad Studio

Posted 14 October 2018 - 12:57 PM

This is a project I always wanted to do, and now its finished: a way to convert mp4 files into something I could play in Minecraft. Here is how I did it:
  • Convert the mp4 file to a bunch of downscaled pngs using ffmpeg
  • Use a lua program to convert these pngs into a big text file containing the images with indexed colors
  • Build the biggest monitor, set the text scale to the minimum and change the palette to grayscale.
  • Put the big file into computercraft and play it!
This is something you could do in a computercraft cinema, nothing that is fast and easy to do. I converted the beginning of Coraline because its my favorite movie, just don't tell Focus. This showcase is a bit stuttery because I was recording it. It is nearly two hours long, and it can play it with 5 or so fps.
If you have any interest going through the trouble of creating something like this yourself, just tell me.

Edited by Jummit, 14 October 2018 - 01:02 PM.


#2 Frekvens1

  • Members
  • 6 posts

Posted 16 October 2018 - 08:25 PM

This looks like an amazing project!

I've been thinking for a long time about creating a project like this myself. I just completed a decent note block media player, and my next step was creating a video player with sound support. If you have any guidelines or tips to guide me along my path, that would be highly appreciated.

#3 Jummit

  • Members
  • 306 posts
  • LocationJulfander Squad Studio

Posted 17 October 2018 - 07:36 AM

View PostFrekvens1, on 16 October 2018 - 08:25 PM, said:

This looks like an amazing project!

I've been thinking for a long time about creating a project like this myself. I just completed a decent note block media player, and my next step was creating a video player with sound support. If you have any guidelines or tips to guide me along my path, that would be highly appreciated.
I am thinking of adding sound support if I find software that gives me the information I need (Pitch, volume, maybe sound type). Tips on making something like this? Use third party software for anything you can. I used PngLua to read pngs, ffmpeg to convert the mp4 into images (this takes some time to find out which parameters you need to change) and so on. Just search the things you need. The only thing you need to write is the a png->your movie format converter and something that plays this file. I recommend doing only the movie player in Computercraft, the rest is easier to do in 'real' lua. Don't try to use a binary format for the movie file, because CCs character set is different it wont work (learnt this the hard way). Just use one character for every pixel and you're good. I didn't worry about performance (at first), and I had no issues. Use a screen buffer (the window api is pretty solid at buffering) so it doesn't flicker. Thats pretty much it! Good luck!
EDIT: I think I will be using https://www.sonicvisualiser.org/ to get the pitch and volume of the sound of the movie.

Edited by Jummit, 17 October 2018 - 07:47 AM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 October 2018 - 01:32 AM

There are various programs about the place which can adapt wave-based audio formats (eg WAV, MP3, OGG, etc) to MIDI. From there, it's a relatively simple jump to rudimentary audio playback within ComputerCraft.

Actual wave-based playback isn't possible in the base mod, and I don't believe anyone's made a peripheral mod that could do it, either: closest I can think of would be OpenFM. That sort of thing doesn't really fit in with the style of the mod.

View PostJummit, on 17 October 2018 - 07:36 AM, said:

Don't try to use a binary format for the movie file, because CCs character set is different it wont work (learnt this the hard way).

It sounds a lot like you're using text-mode handles to work with non-text files, in which case you should be using a binary-to-text encoding method such as base64. Note that the only time it's worth doing something like that is when you're dealing with web handles through older versions of the mod (which only support text mode): the rest of the time, you should simply be using binary handles instead.

Edited by Bomb Bloke, 18 October 2018 - 01:34 AM.


#5 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 18 October 2018 - 07:23 AM

View PostBomb Bloke, on 18 October 2018 - 01:32 AM, said:

Actual wave-based playback isn't possible in the base mod, and I don't believe anyone's made a peripheral mod that could do it, either: closest I can think of would be OpenFM. That sort of thing doesn't really fit in with the style of the mod.
Computronics' tape drives use a format called "DFPWM", which you can convert .wav files to. We've used this quite a lot on SwitchCraft to pipe music out.

I believe the speaker/sound card also allow playing arbitrary waves, but the documentation is pretty much only composed of this gist, so that's a much harder route to go down.

#6 Frekvens1

  • Members
  • 6 posts

Posted 18 October 2018 - 09:23 AM

View PostSquidDev, on 18 October 2018 - 07:23 AM, said:

View PostBomb Bloke, on 18 October 2018 - 01:32 AM, said:

Actual wave-based playback isn't possible in the base mod, and I don't believe anyone's made a peripheral mod that could do it, either: closest I can think of would be OpenFM. That sort of thing doesn't really fit in with the style of the mod.
Computronics' tape drives use a format called "DFPWM", which you can convert .wav files to. We've used this quite a lot on SwitchCraft to pipe music out.

I believe the speaker/sound card also allow playing arbitrary waves, but the documentation is pretty much only composed of this gist, so that's a much harder route to go down.

I did a bunch of research about this route yesterday. After a long talk on discord with Justyn he helped me demystify the tape drive.
https://forums.compu...4.msg264#msg264

Sample code for a downloader (Note it downloads in binary, else you get a white noise)

tape = peripheral.find("tape_drive")

url = "http://DirectLinkToFile.dfpwm")
local response = http.get(url, nil, true) -- THIS IS IMPORTANT

tape.seek(-tape.getPosition()) --Rewind to start
tape.write(response.readAll())
response.close()

tape.seek(-tape.getPosition()

How to easily create a good file:
1. Convert ANY type of music to WAV (Sound quality might get decreased depending on format used)
2. Use LionRay Wav Converter for DFPWM file. (Can be downloaded as a binary and have a user friendly UI)
3. Upload file to file provider (Github, Dropbox, Google Drive)
4. Use the code above where the URL is a direct link.
5. Enjoy!

#7 Jummit

  • Members
  • 306 posts
  • LocationJulfander Squad Studio

Posted 23 October 2018 - 09:17 AM

View PostBomb Bloke, on 18 October 2018 - 01:32 AM, said:

There are various programs about the place which can adapt wave-based audio formats (eg WAV, MP3, OGG, etc) to MIDI. From there, it's a relatively simple jump to rudimentary audio playback within ComputerCraft.

Actual wave-based playback isn't possible in the base mod, and I don't believe anyone's made a peripheral mod that could do it, either: closest I can think of would be OpenFM. That sort of thing doesn't really fit in with the style of the mod.

View PostJummit, on 17 October 2018 - 07:36 AM, said:

Don't try to use a binary format for the movie file, because CCs character set is different it wont work (learnt this the hard way).

It sounds a lot like you're using text-mode handles to work with non-text files, in which case you should be using a binary-to-text encoding method such as base64. Note that the only time it's worth doing something like that is when you're dealing with web handles through older versions of the mod (which only support text mode): the rest of the time, you should simply be using binary handles instead.
I tried it in binary mode and it gave me different numbers for the same character. Why is that?

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 October 2018 - 12:38 PM

I don't know, you haven't shown me the input/output/code.

#9 DanyGames2014

  • Members
  • 9 posts
  • LocationCzech Republic , Prague

Posted 12 November 2018 - 12:35 AM

.

Edited by DanyGames2014, 13 August 2021 - 05:32 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users