Daira Emma Hopwood
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # How big is a WebP of an animated QR code, relative to the original file? For this experiment we'll use the [TXQR format](https://github.com/divan/txqr.git), and ``gif2webp`` from the [libwebp](https://chromium.googlesource.com/webm/libwebp.git) library. We use a random file to simulate data that is not further compressible. ## Experiment I'm assuming you are on a Linux (or sufficiently Linux-like) system and have installed typical build tools, Git, and CMake. If they're not installed then your distribution will have them as packages, e.g. `build-essential`, `git`, and `cmake` on Debian. ### Directory hygiene ``` mkdir animatedqr cd animatedqr ``` ### Build txqr ``` git clone https://github.com/divan/txqr.git cd txqr/cmd/txqr-gif go build ./txqr-gif --help ``` ``` Usage of ./txqr-gif: -fps int Animation FPS (default 5) -o string Output animated gif file (default "out.gif") -size int QR code size (default 300) -split int Chunk size for data split per frame (default 100) ``` ### Create a random 10000-byte file and encode it as a TXQR GIF I'm just going to use the defaults for frame rate, QR size, etc. I don't think that matters very much. ``` cd ../../.. head --bytes=10000 /dev/urandom >random txqr/cmd/txqr-gif/txqr-gif -o random.gif random ls -l random* ``` ``` -rw-rw-r-- 1 daira daira 10000 Aug 17 15:28 random -rw-rw---- 1 daira daira 999929 Aug 17 15:28 random.gif ``` So at this size, an animated GIF is about 100 times the size of the original file. It is roughly consistent across runs. For a 1000-byte file the overhead is about 105 times, for larger files slightly less than 100. ### Build libwebp ``` git clone https://chromium.googlesource.com/webm/libwebp.git cd libwebp cmake . make ./gif2webp -h ``` ``` Usage: gif2webp [options] gif_file -o webp_file Options: -h / -help ............. this help -lossy ................. encode image using lossy compression -mixed ................. for each frame in the image, pick lossy or lossless compression heuristically -q <float> ............. quality factor (0:small..100:big) -m <int> ............... compression method (0=fast, 6=slowest) -min_size .............. minimize output size (default:off) lossless compression by default; can be combined with -q, -m, -lossy or -mixed options -kmin <int> ............ min distance between key frames -kmax <int> ............ max distance between key frames -f <int> ............... filter strength (0=off..100) -metadata <string> ..... comma separated list of metadata to copy from the input to the output if present Valid values: all, none, icc, xmp (default) -loop_compatibility .... use compatibility mode for Chrome version prior to M62 (inclusive) -mt .................... use multi-threading if available -version ............... print version number and exit -v ..................... verbose -quiet ................. don't print anything ``` ### Use gif2webp to convert to WebP ``` cd .. libwebp/gif2webp -min_size -metadata none random.gif -o random.webp ls -l random* ``` ``` -rw-rw-r-- 1 daira daira 10000 Aug 17 15:28 random -rw-rw---- 1 daira daira 999929 Aug 17 15:28 random.gif -rw-rw-r-- 1 daira daira 203632 Aug 17 15:28 random.webp ``` Without the `-min_size` option it is around 250000 bytes. Lossy compression doesn't help. ## Addendum: BC-UR The format that Keystone actually uses is [BC-UR](https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2020-005-ur.md), which is widely adopted in the Bitcoin world. Let's repeat the experiment with that instead of TXQR. ``` git clone https://github.com/Foundation-Devices/foundation-ur-py.git cd foundation-ur-py python -m venv venv venv/bin/python -m pip install qrcode webp ``` Now create a file `encode.py` with the following contents: ```python! #!/bin/env python import sys from ur.ur_encoder import UREncoder from ur.ur_decoder import URDecoder from ur.ur import UR import qrcode import webp def encode(ur, max_fragment_len): first_seq_num = 100 encoder = UREncoder(ur, max_fragment_len, first_seq_num) decoder = URDecoder() while True: part = encoder.next_part() decoder.receive_part(part) yield part if decoder.is_complete(): break if decoder.is_success(): assert(decoder.result == ur) else: print('{}'.format(decoder.result)) assert(False) def main(args): if len(args) < 3: print("Usage: encode.py <inputfile> <outputfile-stem>") return inputfile = args[1] outputfile = args[2] with open(args[1], mode='rb') as f: data = f.read() # TODO: assign code for PCZT # I don't know why some fragment lengths don't work. for max_fragment_len in [100, 125, 200, 250, 400, 500, 650, 1000]: ur = UR('pczt', data) print(f"max_fragment_len = {max_fragment_len}") imgs = (qrcode.make(part).convert('RGB') for part in encode(ur, max_fragment_len)) try: webp.save_images(imgs, f"{outputfile}-{max_fragment_len}.webp", fps=5, lossless=True) except AttributeError: print("doesn't work") if __name__ == "__main__": main(sys.argv) ``` and run: ``` venv/bin/python encode.py ../random ../random-ur ls -l ../random* ``` ``` -rw-rw-r-- 1 daira daira 10000 Aug 17 15:28 ../random -rw-rw---- 1 daira daira 999929 Aug 17 15:28 ../random.gif -rw-rw-r-- 1 daira daira 227280 Aug 19 15:11 ../random-ur-1000.webp -rw-rw-r-- 1 daira daira 399558 Aug 19 15:10 ../random-ur-100.webp -rw-rw-r-- 1 daira daira 329692 Aug 19 15:10 ../random-ur-125.webp -rw-rw-r-- 1 daira daira 285868 Aug 19 15:10 ../random-ur-200.webp -rw-rw-r-- 1 daira daira 236648 Aug 19 15:10 ../random-ur-250.webp -rw-rw-r-- 1 daira daira 154786 Aug 19 15:10 ../random-ur-400.webp -rw-rw-r-- 1 daira daira 164376 Aug 19 15:10 ../random-ur-500.webp -rw-rw-r-- 1 daira daira 115544 Aug 19 15:10 ../random-ur-650.webp -rw-rw-r-- 1 daira daira 203632 Aug 17 15:28 ../random.webp ``` Here the optimal fragment size of 650 produces `random-ur-650.webp` which is ~11.6 times larger than the input file. ## Conclusion For an incompressible input file of 10000 bytes, a WebP-encoded TXQR is roughly 20.4 times larger than the original file. This does not change very much across input sizes. Using WebP saves a factor of ~5 relative to animated GIF. A WebP-encoded BC-UR can be roughly 11.6 times larger than the original file if the `max_fragment_size` is chosen optimally.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully