Video to Amended Animated GIF Slide Preview Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Video to Amended Animated GIF Slide Preview Tutorial

Video to Amended Animated GIF Slide Preview Tutorial

Keeping to the recent theme of interest in (the non-mobile) โ€œonmouseoverโ€ (hover) and โ€œonmouseoutโ€ events, today we improve our inhouse Animated GIF Creator helper PHP web application last talked about with Video to Amended Animated GIF via ffmpeg Tutorial.

The reason we think those non-mobile users will enjoy this functionality, if anything like me, is that we might browse for images in a sorted bunch and assume all is well, but that order may not suit in the animated GIF order structure, and here is a mechanism that might help.

And so take a look at thechanged tutorial_to_animated_gifโšซphp our inhouse Animated GIF Creator helper PHP web application โ€ฆ

<?php echo โ€


function bithis(inthis) {

if (inthis.value.trim() != '') {

if (('' + inthis.getAttribute('data-oh')).replace(/^undefined$/g,'').replace(/^null$/g,'') == '') {

inthis.setAttribute('data-oh', '' + inthis.getBoundingClientRect().height);

}

if (inthis.value.indexOf('data:') == 0) {

inthis.style.backgroundImage='linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL(\"' + inthis.value + '\")';

inthis.style.color='rgba(240,240,240,0.2)';

inthis.style.height='80px';

inthis.style.backgroundSize='contain';

inthis.style.backgroundRepeat='no-repeat';

inthis.style.backgroundPosition='right top';

} else if (inthis.value.indexOf('.') != -1) {

inthis.style.backgroundImage='linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL(\"' + inthis.value + '\")';

inthis.style.height='80px';

inthis.style.backgroundSize='contain';

inthis.style.backgroundRepeat='no-repeat';

inthis.style.backgroundPosition='right top';

}

}

}



function unbithis(inthis) {

if (inthis.value.trim() != '') {

if (('' + inthis.getAttribute('data-oh')).replace(/^undefined$/g,'').replace(/^null$/g,'') != '') {

inthis.style.height='' + inthis.getAttribute('data-oh') + 'px';

}

inthis.style.color='black';

inthis.style.opacity='1.0';

inthis.style.background='';

}

}


โ€œ; ?>

โ€ฆ to accompany the (input type=text) slide textbox onmouseover=bithis(this); onmouseout=unbithis(this); event logic callers, to get a taste for what is involved here.


Previous relevant Video iPad Time Lapse Animated GIF via ffmpeg Tutorial is shown below.

Video iPad Time Lapse Animated GIF via ffmpeg Tutorial

Video iPad Time Lapse Animated GIF via ffmpeg Tutorial

We wanted to try out a small Time Lapse video โ€ฆ

Time-lapse photography is a technique whereby the frequency at which film frames are captured (the frame rate) is much more spread out than the frequency used to view the sequence. When played at normal speed, time appears to be moving faster and thus lapsing. For example, an image of a scene may be captured at 1 frame per second, but then played back at 30 frames per second; the result is an apparent 30 times speed increase. In a similar manner, film can also be played at a much lower rate than it was captured at, slowing down an otherwise fast action, as in slow motion or high-speed photography.

โ€ฆ created with the iPad Camera app โ€œVideo Time Lapseโ€ option. Small being the operative word. So small in fact, that for a few seconds of video, it is possible to email your video off to an emailee receiver, the tradeoff being that when they play it at many speeds it is likely to play in the jerky fashion โ€ฆ like with our Nala Time Lapse (iPad Camera app created) videoโœ‚below โ€ฆ

โ€ฆ which we downloaded to this MacBook Pro that has (the great opensource) ffmpeg installed ready to reconstitute some slides from the video via โ€ฆ



$ ffmpeg -i nala_timelapse.mov -r 5 nala_image-%04d.jpeg

ffmpeg version 4.1.1 Copyright (c) 2000-2019 the FFmpeg developers

built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)

configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr

libavutil 56. 22.100 / 56. 22.100

libavcodec 58. 35.100 / 58. 35.100

libavformat 58. 20.100 / 58. 20.100

libavdevice 58. 5.100 / 58. 5.100

libavfilter 7. 40.101 / 7. 40.101

libavresample 4. 0. 0 / 4. 0. 0

libswscale 5. 3.100 / 5. 3.100

libswresample 3. 3.100 / 3. 3.100

libpostproc 55. 3.100 / 55. 3.100

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'nala_timelapse.mov':

Metadata:

major_brand : qt

minor_version : 0

compatible_brands: qt

creation_time : 2019-03-10T06:32:49.000000Z

com.apple.quicktime.location.ISO6709: -33.9074+151.1764+013.000/

com.apple.quicktime.make: Apple

com.apple.quicktime.model: iPad (5th generation)

com.apple.quicktime.software: 12.1.1

com.apple.quicktime.creationdate: 2019-03-10T17:32:19+1100

Duration: 00:00:01.23, start: 0.000000, bitrate: 20015 kb/s

Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080, 20003 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc (default)

Metadata:

rotate : 180

creation_time : 2019-03-10T06:32:49.000000Z

handler_name : Core Media Video

encoder : H.264

Side data:

displaymatrix: rotation of -180.00 degrees

Stream mapping:

Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))

Press [q] to stop, [?] for help

Output #0, image2, to 'nala_image-%04d.jpeg':

Metadata:

major_brand : qt

minor_version : 0

compatible_brands: qt

com.apple.quicktime.creationdate: 2019-03-10T17:32:19+1100

com.apple.quicktime.location.ISO6709: -33.9074+151.1764+013.000/

com.apple.quicktime.make: Apple

com.apple.quicktime.model: iPad (5th generation)

com.apple.quicktime.software: 12.1.1

encoder : Lavf58.20.100

Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc (default)

Metadata:

encoder : Lavc58.35.100 mjpeg

creation_time : 2019-03-10T06:32:49.000000Z

handler_name : Core Media Video

Side data:

cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1

displaymatrix: rotation of -0.00 degrees

frame= 8 fps=0.0 q=12.5 Lsize=N/A time=00:00:01.60 bitrate=N/A dup=0 drop=29 speed=4.67x

video:974kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

$ ls -l nala_image-*.jpeg

-rw-r--r-- 1 user admin 124191 10 Mar 19:36 nala_image-0001.jpeg

-rw-r--r-- 1 user admin 174070 10 Mar 19:36 nala_image-0002.jpeg

-rw-r--r-- 1 user admin 190966 10 Mar 19:36 nala_image-0003.jpeg

-rw-r--r-- 1 user admin 150169 10 Mar 19:36 nala_image-0004.jpeg

-rw-r--r-- 1 user admin 141476 10 Mar 19:36 nala_image-0005.jpeg

-rw-r--r-- 1 user admin 91377 10 Mar 19:36 nala_image-0006.jpeg

-rw-r--r-- 1 user admin 69113 10 Mar 19:36 nala_image-0007.jpeg

-rw-r--r-- 1 user admin 56253 10 Mar 19:36 nala_image-0008.jpeg

$

And then to generate our Animated GIF animation used in todayโ€™s blog posting image we used the inhouse (with great help as you can read at Animated GIF and Video via PHP Writing PHP Data URI Tutorial) Animated GIF creator โ€ฆ โ€œan animation cycleโ€.

Read more at Video via Slide Images and Back Again via ffmpeg Primer Tutorial below for more information, especially if you need to install ffmpeg yourself.


Previous relevant Video via Slide Images and Back Again via ffmpeg Primer Tutorial is shown below.

Video via Slide Images and Back Again via ffmpeg Primer Tutorial

Video via Slide Images and Back Again via ffmpeg Primer Tutorial

Reading yesterdayโ€™s LibreOffice Spreadsheet via dBase Primer Tutorial you canโ€™t say I didnโ€™t warn you about my interest in ants (and bees)? Glad you asked?

Did you know?

  • the queen ant (often just one per ant colony) is not a leader as such in thinking out strategies โ€ฆ believe it or not โ€ฆ
  • it is believed ant colony strategies are worked by what we might call โ€œgroupthinkโ€
  • ants march in line often and the scent that the ants leave behind is pheromone, that non-leader ants follow off that left behind by the โ€œleader antโ€ โ€ฆ ie. โ€œleaderโ€ of position, rather than โ€œleaderโ€ of hierarchy

So seeing some ants walking in line up a power pole, used an iPhone to capture a very short video (short enough to use the iPhoneโ€™s Photo appโ€™s Share via Mail (attachment) method of emailing to the MacBook Pro, and then (Gmail website) downloading) of this, and later, buck the โ€œantโ€ trend, and โ€œanthropomorphiseโ€ a โ€œstar antโ€, by honing in on an ant in this video and ring it (and its movement) before creating another โ€œStar Ant Videoโ€.

There are video editing approaches you could use, but what got us interested was the thought of โ€ฆ

  • break the video into its component parts โ€ฆ just like animations like โ€œBugs Bunnyโ€ โ€ฆ a series of (slide, or frame) images
  • edit those (slide) images to add the (weโ€™ve decided should be) red ringing of our โ€œStar Antโ€ โ€ฆ who weโ€™ve decided you, the user can call whatever you so desire โ€ฆ aaaaaaarrrrrrr
  • reconstitute a new video from some new (slide) image components

Thatโ€™s where one of our favourite Mac Os X friendly media players, which is also a command line โ€œplayerโ€ (yayyyyyy!) comes to the fore, for us. Itโ€™s the wonderful ffmpeg which weโ€™ve had for a long time now on this MacBook Pro until a disk crash mentioned some weeks back. Could get it back off restore, but decided to reconsitute โ€ฆ

โ€ฆ as a fairly straightforward exercise (given you have Xcode installed already) via a How to install FFmpeg on Mac OS X webpage by Renรฉ Calles, thanks, heaps, we discovered the commands that worked well for us that go โ€ฆ



ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools

โ€ฆ to (re)install ffmpeg so that, then โ€ฆ



ffmpeg -i IMG_0738.MOV -r 1 image-%04d.jpeg

โ€ฆ could create those original 7 (slide) images, though the use of a value bigger than 1 frames per second for the โ€œ-rโ€ switch could be on the cards for your usages.

How to edit those images? We just used the Mac OS X version of PaintBrush and lined a lot of these images side by side across the screen to try to track our โ€œStar Antโ€ and award it the โ€œRed Ellipse PaintBrush Order of Meritโ€ (for individualism โ€ฆ tee hee).

Reconstituting the new slides into a new video we remember was another talent of ffmpeg and found this useful webpage, thanks, on the topic of taking raw (slide) images to create a video via ffmpeg. Actually, though, we also had our previous very useful Animated GIF and Video via PHP Writing PHP Data URI Tutorial (presented below) to turn to to end up with the Mac OS X (Terminal session command line command โ€ฆ



ffmpeg -r 1 -i image-%04d.jpg ants.mp4

There are no worries with video file โ€œworkingsโ€ to do with uppercase and lowercase and names, so we โ€ฆ



cp IMG_0738.MOV ants.mov

โ€ฆ just for some consistency purposes (and could use โ€œmvโ€ to rename instead) so that we can show you โ€ฆ

Before โ€ฆ After โ€ฆ โ€œStar Ant Videoโ€

See a lot of all these goings on at todayโ€™s PDFโœ‚slideshow.


Previous relevant Animated GIF and Video via PHP Writing PHP Data URI Tutorial is shown below.

Animated GIF and Video via PHP Writing PHP Data URI Tutorial

Animated GIF and Video via PHP Writing PHP Data URI Tutorial

There is a great open source command line application called โ€œFFmpegโ€ that can create video (or convert video) from image slides (for instance), and so, if we merge functionality for this into yesterdayโ€™s Animated GIF and Slideshow via PHP Writing PHP Data URI Tutorial some โ€œpresentationโ€ styles that our webโœ‚application can process are now โ€ฆ

  • animated GIF
  • slideshow
  • video

As useful as โ€œFFmpegโ€ is, it is not necessarily a default application existing on web server operating systems like our rjmprogramming.com.auโ€™s CentOS server. But we do have it on our Mac OS X (MacBook Pro) operating systemโ€™s command line, so we write our PHP determining whether to โ€ฆ

  • create the video data there and then via โ€œFFmpegโ€ and PHPโ€™s exec method โ€ฆ or โ€ฆ
  • provide instructions to be able to create the video back at your client computer (that has โ€œFFmpegโ€ perhaps) โ€ฆ to suit the โ€ฆ


    ffmpeg -r 1 -i %03d.jpg video.mp4


    โ€ฆ to create a video called video.mp4 with 1 second delays between (input) slides named 001.jpg then 002.jpg then 003.jpg etcetera โ€ฆ thanks useful webpage for the help โ€ฆ that in the command line can sometimes be played via โ€ฆ


    open video.mp4


    โ€ฆ or used in some HTML as per โ€ฆ


    <video controls id=ivideo type='video/mp4'><source src='video.mp4'></source></video>


    โ€ฆ that we show you, below, the Mac OS X local MAMP (Apache/PHP/MySql) web server running of todayโ€™s PHP to create โ€ฆ

If you are a regular at this blog and โ€œFFmpegโ€ sounds a bit familiar to you, thatโ€™s probably because youโ€™ve read FFmpeg Image Optimization Primer Tutorial on an earlier occasion โ€ฆ by candlelight โ€ฆ with the lights dimmed?!

See this in the context of how this PHP tutorial_to_animated_gifโšซphp code changed for videos in thisway or try it as a liveโœ‚run.


Previous relevant Animated GIF and Slideshow via PHP Writing PHP Data URI Tutorial is shown below.

Animated GIF and Slideshow via PHP Writing PHP Data URI Tutorial

Animated GIF and Slideshow via PHP Writing PHP Data URI Tutorial

To us, there are great similarities between animated GIFs and slideshows, as two forms of โ€œpresentationโ€, and so to extend yesterdayโ€™s Animated GIF via PHP Writing PHP Data URI Tutorial animated GIF creator โ€œPHP Writes PHPโ€ web application that now has the option for data URI โ€œexportsโ€ we add the functionality for โ€ฆ

  • slideshow creation (using our inhouse methods) which defaults to a horizontal (hashtag type of) navigation โ€ฆ as well as adding a โ€ฆ
  • slideshow creation, with Data URI image data, using functionality as if CSS z-index (ie. slides stacked on top of each other in โ€œoverlayโ€ style) was being used, but actually isnโ€™t โ€ฆ

โ€ฆ that little bit different to another โ€œstackedโ€ (or z-index feeling) approach we talked about with Multiple Class Slideshow Details Tutorial, where HTML element โ€œclassโ€ properties were changed so that the last class defined reflects the look of the slideshow slide desired at any given time. We just use an array, and a setTimeout timer to achieve the same ends today, with our work (or โ€œpresentationโ€). If this โ€œhorizontal versus stackโ€ navigation choice interests you, also take a read of HTML Input Element Types Randomized History Tutorial.

Again, with all this added functionality, because it is โ€œhostedโ€ in an HTML iframe element all the existant web browser (Windows right click or Mac OS X two finger gesture) functionality can come into play, and make life quite interesting for your non-mobile users โ€œcollectingโ€ data URIs โ€ฆ there are worse hobbies!

You can see this in the context of how this PHP tutorial_to_animated_gifโšซphp code changed for slideshows in thisway or try it as a liveโœ‚run.


Previous relevant Animated GIF via PHP Writing PHP Data URI Tutorial is shown below.

Animated GIF via PHP Writing PHP Data URI Tutorial

Animated GIF via PHP Writing PHP Data URI Tutorial

The previous relevant โ€œPHP writes PHPโ€ methodology animated GIF creator we talked about, first, with Animated GIF via PHP Writing PHP Primer Tutorial came back to mind yesterday with our Missing Javascript Audio on Unmute Tutorial, where we pondered on whether an animated GIF could be represented on a webpage by a data URI. Why take an interest in this? Data URIs are very important to do with โ€ฆ

  • future mobile development web form navigation benefits from their usage
  • the use of data URIs make your web pages independent of web server location issues, so make your web data more portable, and flexible

โ€ฆ and ideally, animated GIFs are also not just a decorative part of all this web application usage (as they can be a very efficient representation of an animation that could not be a more succinct way to show that animation or presentation), and if they can be made to be like any other GIF or image data file in the ways they can be represented (and used), then that is all for the good.

So we changed the Jeroen van Wissenโ€™s inspired PHP (โ€œPHP writes PHPโ€ methodology) code tutorial_to_animated_gifโšซphp code allow for this extra animated GIF data URI representation in a new additional HTML iframe (containing the animegif.html of code below) that when harnessing existant web browser (Windows right click or Mac OS X two finger gesture) functionality can glean for us, as required, that animated GIFโ€™s data URI representation. But donโ€™t get too excited about this being rocket science, in that with a bit of effort, and PHP, it could have been gleaned from what we already produced, in that (in PHP โ€œlandโ€) โ€ฆ



$lastbitto="\$fp = fopen('animegif.gif', 'w');

\$data = \$gif->GetAnimation();

\$dataUri = 'data:image/gif;base64,' . base64_encode(\$data);

fwrite(\$fp, \$data);

fclose(\$fp);

\$fp = fopen('animegif.html', 'w');

fwrite(\$fp, '<!doctype html><html><body><h1>Data URI version below<h1><br><h4> ... via web browser (Windows right click, Mac OS X two finger gesture ...</h4><br><img src=' . \"\\n\" . \$dataUri . \"\\n\" . ' title=DataURI></img></body></html>');

fclose(\$fp);";


You can see this in the context of how this PHP code changed in thisway or try it as a liveโœ‚run.


Previous relevant Animated GIF via PHP Writing PHP Primer Tutorial is shown below.

Animated GIF via PHP Writing PHP Primer Tutorial

Animated GIF via PHP Writing PHP Primer Tutorial

We find another very useful reason for PHP to write PHP. Today we establish a PHP web application to dynamically create Animated GIF images via some still images, like Gifpal would do.

We have some great open source PHP code to thank for the basis of the functionality we found at Jeroen van Wissenโ€™s very useful link, thanks.

Then we added a more user friendly interface to get the information off the user we need. We present this in an HTML form, which navigates to the same PHP to do the actual assembly of the Animated GIF via techniques where PHP writes PHP โ€ฆ and really needs to, to be useful.

Do you remember, last, when we did some PHP writing PHP functionality โ€ฆ PHP Writes PHP Vertical TextBoxes Primer Tutorial?

And inside the PHP it makes big use of the GD and Image Functions to read and write the image data we assemble via the user information.

This Animated GIF form of animation is the easiest to implement, as it consists of just the one GIF image file, but the user has very little control over the animation settings, such as the delay between stills, one of the settings we ask about in our web application.

Our PHP source code today you could call tutorial_to_animated_gifโšซphp and we redirect you to some live run ideas โ€ฆ

  • normal run with HTML form which posts back to itself โ€ฆ liveโœ‚run
  • example GET parameters run (like our tutorial picture)

Hope you find this tutorial useful.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Tutorials and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *