In ffmpeg
there is a structure AVFrame describing decoded video or audio data.
It has a void pointer opaque
. The documentation claims it is "for some private data of the user".
What does this mean? Can it be used to transport any additional data as per-frame metadata?
It is a field dedicated for user (as opposed to ffmpeg libraries) usage; ffmpeg will not touch this field in any way so you are free to use it as you see fit. There is a caveat though: some ffmpeg functions will make a copy of AVFrame (or maybe move reference from AVFrame to another), which includes copying this field's value. It might be somehow tricky to manage lifetime of a data pointed to by this field.
If you just need to handle some per-frame metadata, you might want to consider existing metadata storage available in AVFrame (see av_frame_get_metadata/av_frame_set_metadata
)
To expand a little on what @Andrey Turkin said, the purpose is to add application-specific object data to the AVFrame structure. The specific use case typically is when the application allocates the memory (using the get_buffer2 callback). This memory might just be a pointer, but it can sometimes be memory in the GPU or something like that. Regardless, if the application owns the data and creates an object associated with the allocated memory / picture buffer, it will typically want access to the associated object when the decoder returns a given AVFrame in the avcodec_decode_video2()
function, and that's what you typically want to use the opaque field for.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.