Skip to content

Fix Packet::write* rejecting zero-sized packets that carry side data#265

Open
axel10 wants to merge 1 commit into
zmwangx:masterfrom
axel10:fix_flac
Open

Fix Packet::write* rejecting zero-sized packets that carry side data#265
axel10 wants to merge 1 commit into
zmwangx:masterfrom
axel10:fix_flac

Conversation

@axel10
Copy link
Copy Markdown

@axel10 axel10 commented May 2, 2026

Packet::write() and Packet::write_interleaved() currently return
Error::InvalidData whenever packet.size == 0.

That is stricter than FFmpeg's own av_write_frame() /
av_interleaved_write_frame() behavior. FFmpeg allows packets with no payload
data as long as they still carry side data. One real example is the FLAC
encoder flush path, which can emit a zero-sized packet containing
AV_PKT_DATA_NEW_EXTRADATA so the muxer can update the final STREAMINFO block.

With the current wrapper behavior, those packets are rejected before they ever
reach FFmpeg, which makes otherwise valid FLAC muxing fail from Rust.

This patch changes the pre-check so only packets that have neither payload nor
side data are rejected. Zero-sized packets with side data are now forwarded to
FFmpeg, matching the underlying C API semantics more closely.

Also included:

  • a small helper to express the new condition
  • unit tests covering:
    • empty packet without side data is still rejected by the wrapper pre-check
    • zero-sized packet with side data is not treated as invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant