Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100% of GIF does not convert to MP4, gets cut short. #802

Closed
PeskyWabbit opened this issue May 24, 2018 · 1 comment
Closed

100% of GIF does not convert to MP4, gets cut short. #802

PeskyWabbit opened this issue May 24, 2018 · 1 comment

Comments

@PeskyWabbit
Copy link

Hello! when I execute the following code:

import requests
import moviepy.editor as mp

url = "https://i.imgur.com/VaTidQA.gif"
with open('temp.gif', 'wb') as f:
    f.write(requests.get(url).content)
clip = mp.VideoFileClip("temp.gif")
print(clip.duration)
clip.write_videofile("temp.mp4")

I experience loss of frames on the mp4 file. the mp4 will always start from the beginning but will seemingly arbitrarily cut off at some point.

Here is an example:
GIF: https://i.imgur.com/VaTidQA.gif
MP4: https://giphy.com/gifs/pesky-wabbit-5UqQOjkYLuWrvHzvsA

The gif is indeed downloaded in its entirety.

Upon testing, I found that if I change the last line to:

clip.set_duration(clip.duration + X).write_videofile("temp.mp4")

then it will indeed extend the MP4 and cut off less, but this needs to be a variable script as it will be used for many, many gifs. Any suggestions on how I can remedy this?

@PeskyWabbit
Copy link
Author

Fix found.

convert gif to mp4 using:
os.system('echo "y"| ffmpeg -i temp.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" temp.mp4')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant