PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label webm. Show all posts
Showing posts with label webm. Show all posts

Monday, July 18, 2022

[FIXED] How to Convert animated .gif into .webm format in Python?

 July 18, 2022     django, gif, python, webm     No comments   

Issue

I have a web application built on Django where images and animated Gif can be uploaded. However GIF takes long time to load. I was thinking of converting all uploaded gif into webm format and show it on the frontend using HTML5 video tag. I searched a lot for doing this in Python but could not find specific solution. I found this solution. But I want to know is it possible to convert gif into webm while uploading in python or is there any library in python from which this conversion can be accomplished?.


Solution

With MoviePy:

import moviepy.editor as mp
clip = mp.VideoFileClip("mygif.gif")
clip.write_videofile("myvideo.webm")

You can also use any other format (mp4, ogv, etc) and add parameters like bitrate='5000k' or any other parameter supported by FFMPEG. You can also use ffmpeg directly for the conversion instead of moviepy, it will be slightly faster.



Answered By - Zulko
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, July 17, 2022

[FIXED] How to play .GIFV and .WEBM on iOS

 July 17, 2022     gif, imgur, ios, objective-c, webm     No comments   

Issue

I am making an reddit client app. So far I have been successfully able to play gif on iOS using FLAnimatedImage library. However for majority of the "gifs" now a days are "gifv" format from imgur and "webm" from gfycat.

Is there any way to play them on iOS? I researched and know that these 2 formats are just fancy videos. However even avplayer won't play them. The official imgur app is able to play them so there has to be a way.

GIF formats are okay but problem arises for bigger files where we need to download the entire file first and that takes time. GIFV plays continuously without having to download the entire file. Hence I need someway to play them in my app.


Solution

@sschale thanks! yes, seems like imgur's gifv is basically mp4 video without audio. So I ended up using avplayer with each URL replaced with mp4 instead of gifv. Same webm replaced with mp4. Added a whole bunch of extra configuration for looping of video etc and got it to work seamlessly. In order for the avplayer to not pause background playing music of other apps, I added:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:0 error:nil];


Answered By - sudoExclaimationExclaimation
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I convert gif to webm preserving alpha channel?

 July 17, 2022     alpha, gif, linux, phaser-framework, webm     No comments   

Issue

To start out with I have this gif I got from Google Images which has a transparent alpha channel.

Here is the original gif (open it in a new tab to see the transparency):

enter image description here

Here is a recording of it playing on my screen in case it doesn't display right in the browser:

enter image description here

Then I run the following script to convert it to webm, which is what I need for the game framework I'm using.

avconv -f gif img.gif img.webm

However it doesn't maintain the transparency. Here is with an overlay of a properly transparent webm (the water, taken from https://phaser.io/examples/v2/video/alpha-webm)

enter image description here

The white box shouldn't be appearing around the gem.


Solution

First convert the gif to png frames:

convert img.gif img%03d.png

Then combine them into a webm with this command (I had to get outside help on this):

ffmpeg -framerate 25 -f image2 -i ./img%03d.png -c:v libvpx -pix_fmt yuva420p img.webm

enter image description here



Answered By - max pleaner
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing