question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Poor use of syntax

See original GitHub issue

No offence but this

import ffmpeg

in_file = ffmpeg.input('input.mp4')
overlay_file = ffmpeg.input('overlay.png')
(
    ffmpeg
    .concat(
        in_file.trim(start_frame=10, end_frame=20),
        in_file.trim(start_frame=30, end_frame=40),
    )
    .overlay(overlay_file.hflip())
    .drawbox(50, 50, 120, 120, color='red', thickness=5)
    .output('out.mp4')
    .run()
)

looks ugly you should rewrite your library so it works like a type method for example to add an element to a list type you do this some_list.append(new_item) well your example code should work like this

from ffmpeg import media, media_write
# media is a type
with open("input.mp4",  'rb') as media_file:
    input_media = media(media_file)
with open("overlay.png",  'rb') as media_file:
    overlay_media = media(media_file)
new_media = media.concat(
    input_media.trim(start_frame = 10, end_frame = 20),
    input_media.trim(start_frame = 30, end_frame = 40),
)
new_media.overlay(overlay_media.hflip())
new_media.drawbox(50, 50, 120, 120, color='red', thickness=5)
with open("out.mp4", 'wb') as media_file:
    media_write(media_file, new_media)
new_media.run()

please don’t use return self everywhere so you can make non-pythonic code. take a leaf out of list, str, int, float, dict, set, etc the built-in python data-types as ffmpeg media is just creating a new data type really. A data-type which you should be able to do comparisions, I will add that media comparison is a complex thing but you should still implement an easy way to check for “exact & precise” comparrision then allow the end user to built upon it to make more complex comparison tools. Adding frames together? why can’t you utalize __add__() so the end user can just do +, or subtract info from frames. I hope this helps

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
duhaimecommented, Mar 31, 2021

I agree that the syntax of this library would benefit from another pass / rewrite.

1reaction
Bananamancommented, May 7, 2021

Someone DID a full rewrite with great syntax, but I can’t find their source code (no “homepage”) link and it’s brand new, so I’m a bit worried:

https://pypi.org/project/ffmpeg-generator/#description

“This project is based on ffmpeg-python. But rewrite all.”

Edit: Found their repo: https://github.com/fujiawei-dev/ffmpeg-generator

Edit 2: I see that they actually support every ffmpeg filter, unlike ffmpeg-python. Wow. The new project looks very good but needs code review/testing/etc since it’s brand new.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is Syntax? Why and How to Avoid This Grammatical ...
In short, syntax is the order or arrangement of words. Bad syntax can lead to embarrassing or incorrect statements. Case in point:.
Read more >
Syntax Error - an overview
Syntax errors are mistakes in the source code, such as spelling and punctuation errors, incorrect labels, and so on, which cause an error...
Read more >
Syntax Errors: What They Are and Why They're a Problem
Computer languages impose strict rules. A syntax error means one of those rules is broken. Syntax exists in ordinary language. It's the way ......
Read more >
Syntax Errors in Coding and What You Can Do to Fix Them
A syntax error occurs when a programmer writes an incorrect line of code. Most syntax errors involve missing punctuation or a misspelled name....
Read more >
What are some examples of sentences with bad syntax?
In short, poor sentence structure is when a writer uses run-on sentences and/or sentence fragments, or does not vary the length of their...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found