Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Get the data and encode
- while (true)
- {
- pkt.data = NULL; // packet data will be allocated by the encoder
- pkt.size = 0;
- ret = avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt, (const uint8_t*)samples, buffer_size, 0);
- /* encode the samples */
- ret = avcodec_encode_audio2(c, &pkt, frame, &got_output);
- if (ret < 0)
- {
- fprintf(stderr, "error encoding audio frame\n");
- exit(1);
- }
- if (got_output) {
- fwrite(pkt.data, 1, pkt.size, f);
- av_free_packet(&pkt);
- }
- //Refill the sample buffer
- if((audio->size() - vectorPosition) < buffer_size)
- {
- memcpy(samples, &audio->at(vectorPosition), (audio->size() - vectorPosition));
- vectorPosition += (audio->size() - vectorPosition);
- }
- else
- {
- memcpy(samples, &audio->at(vectorPosition), buffer_size);
- vectorPosition += buffer_size;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement