'Write empty packets into avi file ffmpeg

A task: I have a trusted video event detector. I trust to my event detector for 100% and I want to write an uncompressed frame to my avi containter only if my event detector produces "true" result. For frames, when my event detector is producing "false" I would like to write an empty packet because I want to know that there was a frame without event happening. Is it possible to keep AVI file alive? Or do I need to write my own player in this case?

Another option is to calculate timestamps manually and set dts/pts to that calculated time. Drawback: I will need to recalculate timestamps to understand how many frames were between events.

I am using:

av_write_frame(AVFormatContext, AVPacket);

and

av_interleaved_write_frame(AVFormatContext, AVPacket);

What is your suggestion/idea? Thank you in advance.



Solution 1:[1]

Knowing AVI spec, I don't think there is a such thing as an "empty packet" as AVI stores its frames densely without frame timestamps. If file-size is no issue, you can repeat the same frame to indicate undetected event (undo with freezedetect filter) or insert all-zero frame (undo with blackdetect filter). It, however, appears better to use something like matroska container and variable frame rate paired with a lossless h264 (more inline with your alternate option?). Just my 2 cents.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kesh