[FFmpeg-trac] #10984(avfilter:new): Dynamic crop & scale filter graph issue
FFmpeg
trac at avcodec.org
Mon Apr 29 21:15:07 EEST 2024
#10984: Dynamic crop & scale filter graph issue
----------------------------------+----------------------------------
Reporter: myblindy | Type: defect
Status: new | Priority: normal
Component: avfilter | Version: 6.1.1
Keywords: | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
----------------------------------+----------------------------------
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.
--
Ticket URL: <https://trac.ffmpeg.org/ticket/10984>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list