|
1 | 1 | #include "xav_encoder.h" |
| 2 | +#include "channel_layout.h" |
2 | 3 |
|
3 | 4 | ErlNifResourceType *xav_encoder_resource_type; |
4 | 5 |
|
@@ -132,10 +133,16 @@ ERL_NIF_TERM new (ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { |
132 | 133 | if (encoder_config.codec->type == AVMEDIA_TYPE_AUDIO) { |
133 | 134 | xav_encoder->frame->format = encoder_config.format; |
134 | 135 | xav_encoder->frame->nb_samples = xav_encoder->encoder->c->frame_size; |
| 136 | + // For encoder that accepts dynamic frame size, we set it to 1024. |
| 137 | + if (xav_encoder->frame->nb_samples == 0) { |
| 138 | + xav_encoder->frame->nb_samples = 1024; |
| 139 | + } |
| 140 | + |
135 | 141 | if (xav_set_frame_channel_layout(xav_encoder->frame, &encoder_config.channel_layout) < 0) { |
136 | 142 | ret = xav_nif_raise(env, "failed_to_set_channel_layout"); |
137 | 143 | goto clean; |
138 | 144 | } |
| 145 | + |
139 | 146 | if (av_frame_get_buffer(xav_encoder->frame, 0) < 0) { |
140 | 147 | ret = xav_nif_raise(env, "failed_to_get_buffer"); |
141 | 148 | goto clean; |
@@ -197,6 +204,8 @@ ERL_NIF_TERM encode(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { |
197 | 204 | } |
198 | 205 | } else { |
199 | 206 | frame->pts = pts; |
| 207 | + frame->nb_samples = input.size / av_get_bytes_per_sample(xav_encoder->encoder->c->sample_fmt); |
| 208 | + |
200 | 209 | int nb_channels = xav_get_nb_channels(frame); |
201 | 210 | ret = av_samples_fill_arrays(frame->data, frame->linesize, input.data, nb_channels, |
202 | 211 | frame->nb_samples, xav_encoder->encoder->c->sample_fmt, 1); |
|
0 commit comments