There is also a “hacky” solution you could use.
You could use a fixed batch size and initialize the whole batch with zeros.
Then you add the input data to the first few indices of the batch and process it.
Finally, you only use the indices of the batch which are valid.