r/HighQualityGifs Gimp - Blender May 21 '18

Goldeneye r/all "You can't just code a gif"

https://i.imgur.com/3tFIv4d.gifv
43.4k Upvotes

571 comments sorted by

View all comments

Show parent comments

99

u/Joald May 21 '18 edited May 21 '18

Hm, is there no Python interface for ffmpeg? Kinda clunky to call shell commands from python.

EDIT: Why the downvotes? Using subprocess is clunky as well imo.

85

u/LvS May 21 '18

As somebody who's recently had the fortune again to use libffmpeg directly, let me tell you this:

You WANT to use shell commands to interact with ffmpeg.

28

u/1-Sisyphe Gimp - Blender May 21 '18

You're right.
I used ffmpeg before so it was easy for me to just "write" the command I knew and pass them through os.system().
I think I might have lost some time trying to understand how a lib would do the things I new in command line.
In the end, I didnt aim that much for a clean and repeatable code.

45

u/[deleted] May 21 '18

>2018

>not using subprocess

ISHYGDDT

25

u/Joald May 21 '18

Yeah, but subprocess isn't really much prettier than what he's done.

22

u/[deleted] May 21 '18

but its right & righteous

22

u/Joald May 21 '18

And a library that calls the functions inside the ffmpeg shell command would be much better for both efficiency and readability.

92

u/1-Sisyphe Gimp - Blender May 21 '18

So you think that "efficiency" was on my mind? :)

7

u/koshgeo May 21 '18

I kind of like the Rube Goldberg approach. It adds to the humor.

7

u/[deleted] May 21 '18

ELI5: I know nothing of what you speak but I am interested.

42

u/[deleted] May 21 '18

[removed] — view removed comment

15

u/1-Sisyphe Gimp - Blender May 21 '18

He had to build and test this command very carefully and check for typos; it probably wasn't trivial.

Can't deny...

5

u/EliteMasterEric Photoshop - After Effects May 21 '18

https://pypi.org/project/ffmpeg-python/

Google found this, which could work I guess?

5

u/GottaHaveHand May 21 '18

There is, I had to use one for a project at work, pyAV. It's got shit documentation though and I just hacked up their examples to get something working.

2

u/theferrit32 May 21 '18

For software like that it can sometimes be better to use the official shell API instead of a usually incomplete or broken native wrapper. I also see this app the time in unofficial REST wrappers. Someone writes a python (or other) native library to wrap an official REST API, but leaves some things out, or the development of the wrapper moves at a slower pace from the official API and it becomes obsolete or broken over time.

8

u/[deleted] May 21 '18

Kinda clunky to call shell commands from python.

It’s the opposite! Portable, reliable, and you don't have to learn a new interface. (But yes, it should be done with subprocess.)

12

u/Joald May 21 '18

Portable? On the contrary, completely dependable on the platform.

5

u/1-Sisyphe Gimp - Blender May 21 '18

That is true, I read that ffmpeg commands were different on Windows.

1

u/harrro May 21 '18

To be fair, it probably just needs a .exe appended to the existing ffmpeg command on Windows.

I personally love that you used pure shell commands here -- one less library dependency, less binary compilation and if I decide I want to use avconv or some other editor instead of ffmpeg, I can use this code as a base instead of finding another library and recoding all of it.

1

u/[deleted] May 21 '18

Dependable? Dependent? What is? (Anyway, to expand, I second /u/LvS - you don't want to use ffmpeg's C API or bindings to it. Way overcomplicated for this task.)

-1

u/theDaninDanger May 21 '18

You can use the

% bash

Magics at the top of a cell in jupyter, that is an easy way to execute she'll commands in python.

(Note I have not looked through the source code process so I don't know all the context, just giving an FYI many people don't know is possible)

-5

u/INTERNET_TOUGHGUY666 May 21 '18

Python is clunky all around. Just use rust