Opened 8 months ago

#10984 new defect

Dynamic crop & scale filter graph issue

Reported by: myblindy Owned by:
Priority: normal Component: avfilter
Version: 6.1.1 Keywords:
Cc: myblindy Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

When trying to use a filter graph with a crop & scale filter, where I update the crop values every frame, the filter stops providing frames anymore if the crop size changes (the position changing is fine). If it later reaches the same size, the input frame will again be processed, then it will stop processing different sized frames again.

Related SO post with code samples and hack to get it working: https://stackoverflow.com/questions/78396539/dynamic-ffmpeg-crop-scale-encoding-code-seems-to-break-when-the-crop-size-cha/

How to reproduce:

A regular source -> video_size={}x{}:pix_fmt={}:time_base={}/{}:pixel_aspect={}/{} -> sink graph, with a filterspec applied of crop,scale={}:{},setsar=1:1. Every frame the crop parameters get updated as such:

check_av_result(avfilter_graph_send_command(&*filterGraph, "crop", "x", std::to_string(cropRectangle.CenterX() - cropRectangle.Width() / 2).c_str(), nullptr, 0, 0));
check_av_result(avfilter_graph_send_command(&*filterGraph, "crop", "y", std::to_string(cropRectangle.CenterY() - cropRectangle.Height() / 2).c_str(), nullptr, 0, 0));
check_av_result(avfilter_graph_send_command(&*filterGraph, "crop", "w", std::to_string(cropRectangle.Width()).c_str(), nullptr, 0, 0));
check_av_result(avfilter_graph_send_command(&*filterGraph, "crop", "h", std::to_string(cropRectangle.Height()).c_str(), nullptr, 0, 0));

Debugging this issue, I reached the portion in vf_scale.c where it's trying to determine if the "frame" has changed (using the frame_changed variable). However it only checks the input side (which obviously hasn't changed), not the output (which did change). Forcing that variable to 1 fixed my issue, and it's fine for me since every frame requires a new crop rectangle, but an actual fix would be even better for the general case.

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Change History (0)

Note: See TracTickets for help on using tickets.