HowTo: Generate d.tube Video Sprites

in #dtube6 years ago

What are sprites?

dtube-sprites.png

Sprites are small preview pictures which pop-up whenever you're hovering with your mouse above the player's time-line / seek-line.
If you upload your videos manually via IPFS you'll have to generate those sprites by yourself.


Requirements

You'll have to install on your computer:

  • FFmpeg
  • ImageMagick

TL;DR

I've created a shell script for that task. I've linked that at the bottom of this post. The script is Linux-only. If you need a Windows version please let me know in the comments.

Sprite Format

A d.tube video may have up to 100 sprites. Each sprite has a size of 210 x 118 pixel. The sprites are stored in a large JPEG image file, attached vertically to each other. Example.
When a video is shorter than 100 seconds, each second of the video is a separate sprite. A 40 second long video only has 40 sprite images.

Sprite Generation

First you'll have to calculate your jumps in the video. For a video longer than 99 seconds you'll need 100 frames from the video distributed evenly.
I'm using FFmpeg to extract a specific frame and store that frame as a bitmap image file.

ffmpeg -accurate_seek -ss 150 -i myvideo.mp4 -s 210x118 -frames:v 1 sprite_second150.bmp

FFmpeg accepts on parameters:

  • ss: the timestamp of a specific frame in seconds or in the format of HH:MM:SS
  • i: path to source video file
  • output path

You'll have to loop that command multiple times to get the desired number of sprite-fragments.
Then I'm using ImageMagick's "montage" tool to combine the fragments into one file.

montage sprite_*.bmp -mode Concatenate -tile 1x100 myvideo-sprite.jpg

Montage's parameters explained:

  • input file(s): with an asterisk to catch all sprite-fragments
  • mode Concatenate: just put the images next to each other leaving no space bewteen
  • tile: how to order the fragments on a grid. d.tube wants ab straight vertical line so 1x[number of fragments] would do the trick
  • output path: where to store the sprite-image. Don't forget the .jpg file extension.

Assertions

The script requires an index on the video's container (which is the case on most video files with MPEG 4 containers with H.264 content) and an aspect ratio of 16:9. Other aspect ratios may lead to a unproportional sprite-image.

Shell Script

I've made a shell script for calculating the sprite image for a specific video.
Just call:

./dtube-sprite.sh /path/to/myvideo.mp4 myvideo-sprite.jpg
Download

via gist.github.com
via pastebin.com

License

The script is licensed under CC0 / public domain.

Sort:  

So, how about that Windows version? I'm actually using Adobe Premiere. Is it possible?

Coin Marketplace

STEEM 0.28
TRX 0.13
JST 0.032
BTC 60725.43
ETH 2900.91
USDT 1.00
SBD 3.59