Advertisement
Guest User

Untitled

a guest
May 4th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. void RipHttp::run(const char *url) {
  2. AVFormatContext *pFormatCtx;
  3.  
  4. // open input and figure out what file format it is
  5. if(avformat_open_input(&pFormatCtx, url, NULL, NULL) != 0) {
  6. fprintf(stderr, "Could not open %s\n", url);
  7. return;
  8. }
  9.  
  10. // find info about the streams it contains
  11. if(av_find_stream_info(pFormatCtx) < 0) {
  12. av_dump_format(pFormatCtx, 0, url, 0);
  13. return;
  14. }
  15.  
  16. // find audio stream
  17. // int audioStream = 1;
  18. int i = 0;
  19. /* int num_streams = pFormatCtx->nb_streams;
  20.  
  21. std::cout << num_streams;
  22.  
  23. for(i = 0; i < num_streams; i++) {
  24. if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
  25. audioStream = i;
  26. break;
  27. }
  28. }
  29.  
  30. if(audioStream == -1) {
  31. fprintf(stderr, "Could not find audio stream in %s\n", url);
  32. return;
  33. }
  34.  
  35. AVCodecContext *pCodecCtx = NULL;
  36.  
  37. pCodecCtx = pFormatCtx->streams[audioStream]->codec;
  38.  
  39. // find codec
  40. AVCodec *pCodec;
  41.  
  42. pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
  43. if(pCodec == NULL) {
  44. fprintf(stderr, "Codec not found for %s\n", url);
  45. return;
  46. }
  47.  
  48. // open codec
  49. if(avcodec_open(pCodecCtx, pCodec) < 0) {
  50. fprintf(stderr, "Could not open codec for %s\n", url);
  51. return;
  52. }*/
  53.  
  54. std::cout << "Done!\n";
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement