[FFmpeg-devel] Global variables in FFmpeg command expressions?

Joan Lluch joan.lluch at icloud.com
Mon May 15 21:45:25 EEST 2023


Hi all,

I recently made a feature request to one of the community members. I was ready to pay a reasonable amount for it, but as it was a relatively quick fix, he was kind enough to implement it on his own, and I made a donation to the community instead. The feature I refer to is the “keep” parameter on the mpdecimate filter, which was implemented by Thilo Borgmann.

I am a retired software developer and although I embraced some really complex projects in the past (including occasional code contributions to the LLVM compiler project) I am not currently in the disposition to do it anymore due to several reasons mostly related to age.

So, I just joined this mailing list because I want to suggest a further improvement to FFmpeg, or otherwise ask for workarounds. 

The problem I want to solve is to trim duplicated frames of a video clip, in the same exact way that the mpdecimate does, but preserving the corresponding audio sections of the preserved video frames in correct sync on the output video. Or in other words, trim duplicated frames from a video input, while also trimming the corresponding audio, in sync.

To accomplish this, I attempted commands such as this one: 

ffmpeg -i $INPUT -vf "select='if( gt(scene,0.00001), (st(1,t);st(2,1)), if(lte(t-ld(1),${KEEP}),st(2,1),st(2,0)) )', setpts=N/FRAME_RATE/TB" -af "aselect='ld(2)', asetpts=N/SR/TB”  $OUTPUT 

The trick here is (or would be) to use variable number 2 from the video section to tell the audio section which frames to select (based on what the video section is selecting).  However, this won't work because ‘variable’ number 2 from the first ‘select’ expression is out of scope on the ‘aselect’ expression. Therefore it always evaluates to 0 in the ‘aselect’ expression and the output goes with no audio.

I think that having a way to specify ‘global’ variables, with valid scope through the entire ffmpeg command, featuring 'store global' and 'load global’ semantics, would be very helpful and would enormously increase the use cases for this library. So it would be nice if somebody would look at implementing it. I understand this is far from straightforward, but It would be game changing if done in my opinion.

As said, my current use case is trimming the audio stream in sync with the video stream as described above. So alternatively, I would appreciate any hints on how to accomplish this if this is /already/ possible.

Thanks

John LLuch




More information about the ffmpeg-devel mailing list