Posted: . At: 7:14 AM. This was 2 weeks ago. Post ID: 19508
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.



Sponsored



Encode a webm file with a simple script that will shrink over time.


Encoding a webm file is a useful way to share a video clip online. But this is also a good way to use various tricks.

Encoding a webm that will shrink over time is a fun trick.

Get this script.

╭──(john㉿DESKTOP-PF01IEE)───╮
╰───────────────────────────╾╯(/mnt/c/Users/Intel i5/Videos)-(172.26.110.105)git clone https://github.com/hlischt/webm-resizer.git
Cloning into 'webm-resizer'...
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 64 (delta 23), reused 62 (delta 21), pack-reused 0
Receiving objects: 100% (64/64), 12.05 KiB | 771.00 KiB/s, done.
Resolving deltas: 100% (23/23), done.

Then, use the script like this to encode a nice webm that will shrink as it plays. This is done by extracting all frames as PNG images in a temporary location shrinking them, and finally reencoding a nice webm file from the frames.

╭──(john㉿DESKTOP-PF01IEE)───╮
╰───────────────────────────╾╯(/mnt/c/Users/Intel i5/Videos/webm-resizer)-(172.26.110.105)┋ python3 webm_resizer.py ../P1140727.MOV dunes.webm
vid_path = ../P1140727.MOV, out_path = dunes.webm
Getting resolution/framerate from ../P1140727.MOV...
Creating PNG sequence as /tmp/tmp3ko_5v4b/%05d.png...
Converting PNG images to webm...
Processing frame 30 of 30
Input #0, concat, from '/tmp/tmp3ko_5v4b/list.txt':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: vp9 (Profile 1), gbrp(pc, gbr/unknown/unknown, progressive), 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn
    Metadata:
      ENCODER         : Lavc60.3.100 libvpx-vp9
      DURATION        : 00:00:00.033000000
Guessed Channel Layout for Input Stream #1.1 : mono
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '../P1140727.MOV':
  Metadata:
    creation_time   : 2012-04-18T17:01:10.000000Z
  Duration: 00:00:01.00, start: 0.000000, bitrate: 5432 kb/s
  Stream #1:0[0x1](eng): Video: mjpeg (Baseline) (jpeg / 0x6765706A), yuvj420p(pc, bt470bg/unknown/unknown), 640x480, 5355 kb/s, 30 fps, 30 tbr, 30 tbn (default)
    Metadata:
      creation_time   : 2012-04-18T17:01:10.000000Z
      vendor_id       : pana
      encoder         : Photo - JPEG
  Stream #1:1[0x2](eng): Audio: pcm_u8 (raw  / 0x20776172), 8000 Hz, 1 channels, u8, 64 kb/s (default)
    Metadata:
      creation_time   : 2012-04-18T17:01:10.000000Z
      vendor_id       : pana
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:1 -> #0:1 (pcm_u8 (native) -> opus (libopus))
Press [q] to stop, [?] for help
Output #0, webm, to 'dunes.webm':
  Metadata:
    encoder         : Lavf60.3.100
  Stream #0:0: Video: vp9 (Profile 1), gbrp(pc, gbr/unknown/unknown, progressive), 640x480 [SAR 1:1 DAR 4:3], q=2-31, 30 fps, 30 tbr, 1k tbn
    Metadata:
      ENCODER         : Lavc60.3.100 libvpx-vp9
      DURATION        : 00:00:00.033000000
  Stream #0:1(eng): Audio: opus, 8000 Hz, mono, s16, 96 kb/s (default)
    Metadata:
      creation_time   : 2012-04-18T17:01:10.000000Z
      vendor_id       : pana
      encoder         : Lavc60.3.100 libopus
frame=   30 fps=0.0 q=-1.0 Lsize=     346kB time=00:00:00.99 bitrate=2852.1kbits/s speed=9.49x    
video:329kB audio:15kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.606694%
Deleting temporary files...
Successfully encoded dunes.webm

This works very well indeed, this is a very neat webm encoding trick.

See an example here: https://securitronlinux.com/webp/dunes.webm

To create a WebM file with alpha transparency, you can follow these steps:

Ensure your video has an alpha transparency channel, which can be checked in software like Adobe Premiere. If your video is in .mov format and has alpha transparency, you can convert it to WebM using a tool like Shutter Encoder. If your video is in another format, you may need to use editing software like DaVinci Resolve to export the video in RGB-16 bit GoPro CineForm with the “Export alpha” option checked. Then, re-encode the video with Shutter Encoder in VP9 .webm format to maintain transparency. Remember to check the compatibility of your video with the desired browser and ensure that the transparency is preserved during the conversion process.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.