Advertisement
Guest User

current encode audio

a guest
Jan 8th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. //Get the data and encode
  2. while (true)
  3. {
  4. pkt.data = NULL; // packet data will be allocated by the encoder
  5. pkt.size = 0;
  6.  
  7. ret = avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt, (const uint8_t*)samples, buffer_size, 0);
  8.  
  9. /* encode the samples */
  10. ret = avcodec_encode_audio2(c, &pkt, frame, &got_output);
  11. if (ret < 0)
  12. {
  13. fprintf(stderr, "error encoding audio frame\n");
  14. exit(1);
  15. }
  16.  
  17. if (got_output) {
  18. fwrite(pkt.data, 1, pkt.size, f);
  19. av_free_packet(&pkt);
  20. }
  21.  
  22. //Refill the sample buffer
  23. if((audio->size() - vectorPosition) < buffer_size)
  24. {
  25. memcpy(samples, &audio->at(vectorPosition), (audio->size() - vectorPosition));
  26. vectorPosition += (audio->size() - vectorPosition);
  27. }
  28. else
  29. {
  30. memcpy(samples, &audio->at(vectorPosition), buffer_size);
  31. vectorPosition += buffer_size;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement