Danbooru

How to upload ugoira, the new pixiv animation system

Posted under General

Maybe it's time for Danbooru to support video formats. Gif is too limited compared to ugoira, and apng is too large compared to an ugoira made of jpegs. Not to mention the lack of apng support.

Somehow, supporting video feels real yucky to me, but that sort of resistance to video is probably what spurred the creation of ugoira in the first place... I don't suppose anyone would advocate adding support for displaying native ugoira.

Between gif, apng, ugoira, and some video format, video seems like the best choice to me.

Toks said:

For the record, I've been writing a ruby script to convert these, here (currently only gif is supported as output). And there has been discussion on it here.

Ooooooh~ shiny! Is there a chance this will be integrated into danbooru? It'd be perfect if you can just upload Ugoira like usual and have them autoconverted to APNG.

Toks said:

FYI:

  • Your script assumes the delay is the same for all frames, so it won't work right if each frame has a different delay.
  • gifs round the delays down to the centisecond, so ugoira with delays exact to the millisecond won't be the correct speed if gif is chosen as output.
  • For some posts, the webm and mp4 ones seem extremely sped up to me. I assume that you're just passing the frames as-is without slowing it down, meaning it will display each image for exactly one frame - way too quick (unless the delay happened to be small to begin with).
  • Converting to mp4 will fail with "height not divisible by 2" if the images have an odd number height.

For the record, I've been writing a ruby script to convert these, here (currently only gif is supported as output). And there has been discussion on it here.

I could possibly fix that for gifs, but not for apng or any of the other formats as they all assume a constant frame rate. I may fix gifs later today.

CureGecko said:

I could possibly fix that for gifs, but not for apng or any of the other formats as they all assume a constant frame rate. I may fix gifs later today.

Is it possible to set a low framerate and display the frames that should appear longer multiple times?

Schrobby said:

Ooooooh~ shiny! Is there a chance this will be integrated into danbooru? It'd be perfect if you can just upload Ugoira like usual and have them autoconverted to APNG.

Integrating it with Danbooru is being discussed in the issue I linked. Not definite yet though.

CureGecko said:

I could possibly fix that for gifs, but not for apng or any of the other formats as they all assume a constant frame rate. I may fix gifs later today.

That's not true for apng. They support different delays for each frame.

As for webm/mp4...

Schrobby said:

Is it possible to set a low framerate and display the frames that should appear longer multiple times?

That's what I was thinking too. Find the greatest common factor among the frame delays and then duplicate each frame by (frame_delay/GCF) times.

Updated

Well, maybe it would be reasonable to build .swf files from .jpgs? Swf format is already supported by danbooru, size difference from ugoiras should be marginal, and there seem to be tools allowing to build swf using ruby (https://rubygems.org/gems/ming-ruby), but I'm "a little" unfamiliar with swf format and its capabilities regarding showing a series of images with varying delays.

Updated

Toks said:

That's what I was thinking too. Find the greatest common factor among the frame delays and then duplicate each frame by (frame_delay/GCF) times.

If the format doesn't support delta compression, that would result in disaster size-wise.

Both MP4 and WebM support variable frame rate (in fact just about any container format does except for AVI), they can show each frame for a different duration, so they would be capable of displaying ugoira at the original speeds without any need to duplicate frames or other hacks.

I'm not aware of any authoring tools that can set timecodes for individual frames like that, though.

Type-kun said:

mp4 uses that compression, webm - I'm not sure.

I tested it on pixiv #44303110.

  • Webm assuming all delays are the same: 301kb
  • Webm duplicating frames with the gcf method: 409kb
  • Gif produced by my ruby script: 1.39mb
  • Original zip size: 1.3mb

So the gcf thing does increase file size compared to not using it, but I don't think this will be a big issue since both of the webms combined are still smaller than the alternatives - including the original ugoira.

piespy said:

Both MP4 and WebM support variable frame rate (in fact just about any container format does except for AVI), they can show each frame for a different duration, so they would be capable of displaying ugoira at the original speeds without any need to duplicate frames or other hacks.

I'm not aware of any authoring tools that can set timecodes for individual frames like that, though.

How does one go about setting variable frame rates then? My google-fu is too weak it seems.

Toks said:

How does one go about setting variable frame rates then? My google-fu is too weak it seems.

One relatively simple way would be using mkvmerge to make the webm with an external timecode file. That way you can specify the timecode for each frame.

mkvmerge -o out.webm --timecodes 0:timecodes.tc in.webm

where the timecodes.tc looks like

# timecode format v2
0
140
279
417
554
602

I got the adjustment for gifs done for my script... https://cure.ninja/pixiv

I will have to research apng, and as for mp4/webm I was thinking setting to 30fps and then making links to each frame to duplicate the correct amount in order to reach the correct number of frames for the delay. Since MP4/WEBM is great at compressing, it shouldn't be a big deal as it will see that they are the same and only make effectively 1 frame worth of data.

piespy said:

One relatively simple way would be using mkvmerge to make the webm with an external timecode file. That way you can specify the timecode for each frame.

where the timecodes.tc looks like

Is WEBM a MKV format? If so, timecode would be best. I could also instead of outputting MP4 for H264, output MKV...

CureGecko said:

Is WEBM a MKV format?

Yeah, it's a Matroska file with extremely limited options regarding video and audio content and other stuff.

You need a recent enough MKV toolkit to generate webms. At least my mkvmerge (6.7.0) autodetects webm file suffixes and adjusts the output format appropriately.

piespy said:

You need a recent enough MKV toolkit to generate webms. At least my mkvmerge (6.7.0) autodetects webm file suffixes and adjusts the output format appropriately.

Is there any kind of ruby API for mkvmerge? There are gems for mkvinfo, and mkvtoolnix itself seems to be written partially in ruby (https://github.com/mbunkus/mkvtoolnix/blob/master/share/ruby/mkvtoolnix/merge.rb), but there's no straightforward wrapper gem for mkvmerge, it seems.

1 2 3 4 5 6 7 8 10