Creating mp4 from vnd.openai.ansivid?


I’d like to create mp4 files from the json’s that get created when doing text base environments.


{"height": 6, "stdout": [[0.5, "\u001b[2J\u001b[1;1H\r\n\u001b[41mS\u001b[0mFFF\r\nFHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Down)\r\n\u001b[41mS\u001b[0mFFF\r\nFHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Left)\r\n\u001b[41mS\u001b[0mFFF\r\nFHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Right)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Up)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Up)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Up)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Down)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Left)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Up)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Left)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Left)\r\nSFFF\r\n\u001b[41mF\u001b[0mHFH\r\nFFFH\r\nHFFG\r\n"], [0.5, "\u001b[2J\u001b[1;1H  (Down)\r\nSFFF\r\nF\u001b[41mH\u001b[0mFH\r\nFFFH\r\nHFFG\r\n"]], "title": "gym VideoRecorder episode", "env": {}, "version": 1, "duration": 6.5, "command": "-", "width": 15}

To something like

Any ideas how to do this?


So far I’m doing it by installing asciinema:

sudo pip3 install asciinema

Then uploading the results as:

from subprocess import check_output

out = check_output(["asciinema", "upload", env.videos[-1][0]])

Then parsing the process output with:

out = out.decode("utf-8").replace('\n', '').replace('\r', '')
castid = out.split('/')[-1]

Finally inserting into the Notebook with:

from IPython.display import HTML

html_tag = """
<script type="text/javascript" 
    async data-autoplay="true" data-size="big">
html_tag = html_tag.format(castid)

If there is another way of doing this, please let me know.


could you mind explaining more?


What questions exactly do you have?


So arguably there are a finite set of positions on the board, you can make a png of each of the ‘possible positions’ and then just copy and name the ones that match the json in order, then ffmpeg to convert list of pngs to mp4. Only dependency there is ffmpeg.

Ohhh also you can write ‘text’ on an image using pillow, so you could just write the json values to a png and ffmpeg, instead of hand create like I mentioned in my previous paragraph


I don’t have another way, but wanted to say thanks for posting this solution. As a newbie, I just wanted anything to show the animation, and this helped a lot.