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.

Filter graph can be constructed in some orders but not others

See original GitHub issue

Given the following example:

file = ffmpeg.input('example.mp4')
video = file['v']
audio = file['a']

# Part A: draw a box over the bottom half of the screen
video = ffmpeg.drawbox(video, 0, t='fill', width='iw', height='ih/2', y='ih/2', color='red')

# Part B: copy a part of the video
partial = ffmpeg.crop(video, 0, 0, 100, 100)
video = ffmpeg.overlay(video, partial, x=200, y=200)

result = ffmpeg.output(video, audio, 'output.mp4')
result = ffmpeg.overwrite_output(result)
result.run()

The following results occur:

  1. When only part A, or part B, is enabled, it works.
  2. If both parts are enabled, it fails with the ValueError shown below.
  3. If you move part B to come before part A, it works.

The specific error:

  File "ffmpeg\_run.py", line 204, in run
    args = compile(stream_spec, cmd, overwrite_output=overwrite_output)
  File "ffmpeg\_run.py", line 183, in compile
    return cmd + get_args(stream_spec, overwrite_output=overwrite_output)
  File "ffmpeg\_run.py", line 156, in get_args
    filter_arg = _get_filter_arg(filter_nodes, outgoing_edge_maps, stream_name_map)
  File "ffmpeg\_run.py", line 103, in _get_filter_arg
    _allocate_filter_stream_names(filter_nodes, outgoing_edge_maps, stream_name_map)
  File "ffmpeg\_run.py", line 97, in _allocate_filter_stream_names
    '`split` filter is probably required'.format(upstream_node, upstream_label))

ValueError: Encountered drawtext(enable='between(t,0,3)', fontcolor='white', fontsize='72',
text='Used to draw a box around text using the background color', x='(w-tw)/2', 
y='(h/10)+(h/33)') <aex> with multiple outgoing edges with same upstream label None;
a `split` filter is probably required

My guess is that it’s confused about how many outputs some filters have? Or perhaps I have an error in my code.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
kkroeningcommented, Sep 5, 2018

That error message is the result of ffmpeg being dumb and needing a split operator in this situation.

But the re-ordering actually changes the shape of the graph. Here’s a comparison of Part A -> Part B vs Part B -> Part A. Notice how the graphs are different:

screen shot 2018-09-05 at 3 53 44 am

The reason Part A -> Part B is failing is that you’re using the same filter in two places, and ffmpeg isn’t smart enough to automatically do the right thing in this situation. It needs to be told with a split operator like this:

screen shot 2018-09-05 at 4 06 27 am

(#douchebag status for pasting screenshots so you can’t copy/paste)

Otherwise ffmpeg loses its shit if you try to send it the filter graph without the split in there, and it blows up with a nasty/confusing error message.

It’s super dumb that ffmpeg explicitly needs to know this because it’s obvious from the shape of the filter graph, but that’s the way ffmpeg is designed, for anyone’s guess as to why. A feature could (and should) probably be added to ffmpeg-python to automatically insert those splits, but for now it doesn’t do anything magic and instead just wraps ffmpeg mostly verbatim. It at least catches this situation and raises an exception with a somewhat explanatory message compared to the nasty ffmpeg error message that would otherwise come out.

In the Part B -> Part A example, you’re referring to an input file in two places (as compared to a filter). This is a different situation to ffmpeg for whatever reason, and ffmpeg usually does the right thing here.

1reaction
kkroeningcommented, Sep 11, 2018

Good idea. Will do. (Keeping this issue open until I get around to it)

I know, I took your “hyper-lazy” solution and went even a step further on the laziness scale haha, but I’m not at my laptop and will hopefully get to it soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter Data from Your Views - Tableau Help
Filtering is an essential part of analyzing data. This article describes the many ways you can filter data from your view. It also...
Read more >
Passive Low Pass Filter - Electronics Tutorials
A Low Pass Filter is a circuit that can be designed to modify, reshape or reject all unwanted high frequencies of an electrical...
Read more >
Format filters in Power BI reports - Microsoft Learn
To build your Filters pane, drag other fields of interest into ... If you lock a filter, your report consumers can see but...
Read more >
Fractional Order Graph Filters: Design and Implementation
Existing graph filters, polynomial or rational, are mainly of integer order forms. However, there are some frequency responses which are not easily achieved ......
Read more >
IIR Filter Design - MATLAB & Simulink - MathWorks
You can easily create a filter of any order with a lowpass, highpass, ... type I filter (and does not approach zero at...
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