larksuite / rsmpeg

A Rust crate that exposes FFmpeg's power as much as possible.
https://docs.rs/rsmpeg/latest/rsmpeg/
MIT License
677 stars 41 forks source link

cannot assign to data in dereference of `rsmpeg::avutil::AVFrame` #186

Closed aegroto closed 4 months ago

aegroto commented 4 months ago

Is there a way to modify arbitrary fields of the AVFrame struct? For instance, I would like to assign a value to the opaque pointer:

        let mut avframe = rsmpeg::avutil::AVFrame::new();
        avframe.opaque = std::ptr::null_mut();

But the compiler consider this as a dereference and therefore would require DerefMut to be implemented.

What's the most idiomatic way to modify data not considered in the wrapper struct rsmpeg::avutil::AVFrame but that are part of the underlying C struct?

ldm0 commented 4 months ago

You can try UnsafeDerefMut.

aegroto commented 4 months ago

Thanks, that's exactly what I was looking for! I have another doubt, are such data transmitted from the encoder to the decoder? I am facing a weird issue, it seems like any modification I make in the AVFrame I send to the encoding context is then missing in the received AVFrame from the decoding context. Is there any specific rule I have to follow to transmit arbitrary data or am I be doing something wrong maybe?

EDIT: I have realized that libavcodec does not handle the transmission of frame/packet information apart from the packet's data buffer, which does not include information such as pts, dts and the similar. The transmission of such data should be managed by the application and added to the AVPacket to be decoded in an explicit manner in the decoder end. I am closing this issue as the original question has been answered already.