Skip to content

Instantly share code, notes, and snippets.

@artificialsoph
Last active July 4, 2019 14:49
Show Gist options
  • Select an option

  • Save artificialsoph/16fca07a56c7d902eda00e67ab37efea to your computer and use it in GitHub Desktop.

Select an option

Save artificialsoph/16fca07a56c7d902eda00e67ab37efea to your computer and use it in GitHub Desktop.

Revisions

  1. artificialsoph revised this gist Apr 12, 2019. 1 changed file with 216 additions and 21 deletions.
    237 changes: 216 additions & 21 deletions gif-demo.ipynb
    216 additions, 21 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
  2. artificialsoph revised this gist Apr 12, 2019. 1 changed file with 196 additions and 233 deletions.
    429 changes: 196 additions & 233 deletions gif-demo.ipynb
    196 additions, 233 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
  3. artificialsoph revised this gist Apr 12, 2019. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions gif-demo.ipynb
    Original file line number Diff line number Diff line change
    @@ -77,7 +77,7 @@
    "source": [
    "!apt install imagemagick -q"
    ],
    "execution_count": 8,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -134,7 +134,7 @@
    "!pip install youtube-dl -U\n",
    "!youtube-dl https://www.youtube.com/watch?v=_cz-wwxmmto -o mitski.mkv"
    ],
    "execution_count": 3,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -199,7 +199,7 @@
    "\n",
    "clip.ipython_display()"
    ],
    "execution_count": 9,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -259,7 +259,7 @@
    "source": [
    "clip.duration"
    ],
    "execution_count": 10,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "execute_result",
    @@ -307,7 +307,7 @@
    "\n",
    "Path(\"mitski.srt\").write_text(SRT)"
    ],
    "execution_count": 11,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "execute_result",
    @@ -356,7 +356,7 @@
    "new_policy = orig_policy.replace('<policy domain=\"path\" rights=\"none\" pattern=\"@*\"/>', '<policy domain=\"path\" rights=\"read|write\" pattern=\"@*\"/>')\n",
    "policy_path.write_text(new_policy)"
    ],
    "execution_count": 12,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "execute_result",
    @@ -430,7 +430,7 @@
    "\n",
    "clip_sub.ipython_display()"
    ],
    "execution_count": 13,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -491,7 +491,7 @@
    "\n",
    "files.download(\"mitski_subtitle.mp4\")"
    ],
    "execution_count": 7,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
  4. artificialsoph revised this gist Apr 12, 2019. 1 changed file with 25 additions and 25 deletions.
    50 changes: 25 additions & 25 deletions gif-demo.ipynb
    25 additions, 25 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
  5. artificialsoph revised this gist Apr 12, 2019. 1 changed file with 203 additions and 198 deletions.
    401 changes: 203 additions & 198 deletions gif-demo.ipynb
    203 additions, 198 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
  6. artificialsoph revised this gist Apr 10, 2019. 1 changed file with 30 additions and 28 deletions.
    58 changes: 30 additions & 28 deletions gif-demo.ipynb
    Original file line number Diff line number Diff line change
    @@ -32,25 +32,27 @@
    },
    "cell_type": "markdown",
    "source": [
    "Install a bunch of stuff!"
    "Big shoutout to [Zuklo](https://github.com/Zulko) for this [blog post](https://zulko.github.io/blog/2014/01/23/making-animated-gifs-from-video-files-with-python/) that was the basis for much of this notebook.\n",
    "\n",
    "First let's start by installing a bunch of stuff!"
    ]
    },
    {
    "metadata": {
    "id": "k5Yup9gOti_F",
    "colab_type": "code",
    "outputId": "035618cf-7c30-482a-afc3-0e293b9b4088",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 435
    },
    "outputId": "035618cf-7c30-482a-afc3-0e293b9b4088"
    }
    },
    "cell_type": "code",
    "source": [
    "!pip install -U youtube-dl moviepy\n",
    "!apt install imagemagick"
    ],
    "execution_count": 1,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -101,11 +103,11 @@
    "metadata": {
    "id": "B1okZpYX3DqT",
    "colab_type": "code",
    "outputId": "130513d1-282a-4c18-feea-be8decb2e46a",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 35
    },
    "outputId": "130513d1-282a-4c18-feea-be8decb2e46a"
    }
    },
    "cell_type": "code",
    "source": [
    @@ -116,7 +118,7 @@
    "new_policy = orig_policy.replace('<policy domain=\"path\" rights=\"none\" pattern=\"@*\"/>', '<policy domain=\"path\" rights=\"read|write\" pattern=\"@*\"/>')\n",
    "policy_path.write_text(new_policy)"
    ],
    "execution_count": 3,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "execute_result",
    @@ -146,17 +148,17 @@
    "metadata": {
    "id": "L3PeYsQgt23h",
    "colab_type": "code",
    "outputId": "e1da1bc3-dc9f-45cc-d65b-416e74fdc397",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 190
    },
    "outputId": "e1da1bc3-dc9f-45cc-d65b-416e74fdc397"
    }
    },
    "cell_type": "code",
    "source": [
    "!youtube-dl _cz-wwxmmto -o mitski.mp4"
    ],
    "execution_count": 2,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -190,11 +192,11 @@
    "metadata": {
    "id": "JPsLpusYuJaq",
    "colab_type": "code",
    "outputId": "9375fa2b-a655-4e09-d610-a07ff80d6bf4",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 293
    },
    "outputId": "9375fa2b-a655-4e09-d610-a07ff80d6bf4"
    }
    },
    "cell_type": "code",
    "source": [
    @@ -208,7 +210,7 @@
    "\n",
    "clip.ipython_display()"
    ],
    "execution_count": 38,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -289,17 +291,17 @@
    "metadata": {
    "id": "keRqDM0MA-Or",
    "colab_type": "code",
    "outputId": "2a71b121-7672-44f7-d77c-8eaceba3ff4c",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 35
    },
    "outputId": "2a71b121-7672-44f7-d77c-8eaceba3ff4c"
    }
    },
    "cell_type": "code",
    "source": [
    "clip.duration"
    ],
    "execution_count": 39,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "execute_result",
    @@ -319,11 +321,11 @@
    "metadata": {
    "id": "hzq9qflyyEo4",
    "colab_type": "code",
    "outputId": "fa569d80-921e-44aa-df1c-17b6eef87ffc",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 35
    },
    "outputId": "fa569d80-921e-44aa-df1c-17b6eef87ffc"
    }
    },
    "cell_type": "code",
    "source": [
    @@ -347,7 +349,7 @@
    "\n",
    "Path(\"mitski.srt\").write_text(SRT)"
    ],
    "execution_count": 51,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "execute_result",
    @@ -377,11 +379,11 @@
    "metadata": {
    "id": "RIQJ6zSPy3e9",
    "colab_type": "code",
    "outputId": "d867b2c3-4e91-464a-f3f3-3eae11796b1b",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 623
    },
    "outputId": "d867b2c3-4e91-464a-f3f3-3eae11796b1b"
    }
    },
    "cell_type": "code",
    "source": [
    @@ -396,7 +398,7 @@
    "\n",
    "clip_sub.ipython_display()"
    ],
    "execution_count": 52,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -475,11 +477,11 @@
    "metadata": {
    "id": "BtdWzstzwXaZ",
    "colab_type": "code",
    "outputId": "85ab2d20-69ac-40e0-d388-32ad132d4d94",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 138
    },
    "outputId": "85ab2d20-69ac-40e0-d388-32ad132d4d94"
    }
    },
    "cell_type": "code",
    "source": [
    @@ -490,7 +492,7 @@
    "\n",
    "files.download(\"mitski_subtitle.mp4\")"
    ],
    "execution_count": 53,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
    @@ -554,18 +556,18 @@
    "metadata": {
    "id": "d-tPwyt6FSOc",
    "colab_type": "code",
    "outputId": "5d110f7e-62af-4aed-ba21-4ffd40924ac7",
    "colab": {
    "base_uri": "https://localhost:8080/",
    "height": 797
    },
    "outputId": "5d110f7e-62af-4aed-ba21-4ffd40924ac7"
    }
    },
    "cell_type": "code",
    "source": [
    "!ffmpeg -v warning -i mitski_subtitle.mp4 -vf \"fps=15,scale=320:-1:flags=lanczos,palettegen=stats_mode=diff\" -y /tmp/palette.png\n",
    "!ffmpeg -i mitski_subtitle.mp4 -i /tmp/palette.png -lavfi \"fps=15,scale=320:-1:flags=lanczos,paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle\" -y mitski_subtitle.gif"
    ],
    "execution_count": 54,
    "execution_count": 0,
    "outputs": [
    {
    "output_type": "stream",
  7. artificialsoph revised this gist Apr 10, 2019. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion gif-demo.ipynb
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,25 @@
    "name": "Gif demo",
    "version": "0.3.2",
    "provenance": [],
    "collapsed_sections": []
    "collapsed_sections": [],
    "include_colab_link": true
    },
    "kernelspec": {
    "name": "python3",
    "display_name": "Python 3"
    }
    },
    "cells": [
    {
    "cell_type": "markdown",
    "metadata": {
    "id": "view-in-github",
    "colab_type": "text"
    },
    "source": [
    "<a href=\"https://colab.research.google.com/gist/artificialsoph/16fca07a56c7d902eda00e67ab37efea/gif-demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
    ]
    },
    {
    "metadata": {
    "id": "ESWiNLw4G8V9",
  8. artificialsoph created this gist Apr 10, 2019.
    638 changes: 638 additions & 0 deletions gif-demo.ipynb
    638 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.