Guest User

vlctest.c

a guest
Jan 19th, 2015
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <vlc/vlc.h>
  4. #include <pthread.h>
  5.  
  6. FILE * myfile;
  7. pthread_mutex_t count_mutex;
  8.  
  9.  
  10. void prepareRender (void* p_video_data, uint8_t** pp_pcm_buffer , size_t size)
  11. {
  12. printf("\ngot the pre call\n ");
  13. pthread_mutex_lock(&count_mutex);
  14. *pp_pcm_buffer = (uint8_t *) malloc(size);
  15. }
  16.  
  17. void handleStream( void* p_video_data, uint8_t* p_pixel_buffer, int width, int height, int pixel_pitch, int size, int64_t pts ){
  18.  
  19. printf("\ngot the post call \n");
  20. int i_line, i_line_size, i_size ;
  21.  
  22. if( pixel_pitch > 0 )
  23. {
  24. i_line = height;
  25. i_line_size = width;
  26. i_size = i_line * i_line_size;
  27. uint8_t *p_in = p_pixel_buffer;
  28. uint8_t *p_out;
  29.  
  30. int line =0;
  31. while(line < i_line)
  32. {
  33. fwrite (p_in, sizeof(char), i_line_size, myfile);
  34. p_out += i_line_size;
  35. p_in += i_line_size;
  36. line++;
  37. }
  38. }
  39. else
  40. {
  41. i_size = size;
  42. fwrite (p_pixel_buffer, sizeof(char), i_size, myfile);
  43. }
  44.  
  45. free(p_pixel_buffer);
  46. pthread_mutex_unlock(&count_mutex);
  47. }
  48.  
  49.  
  50. int main(int argc, char **argv) {
  51. myfile = fopen ("vlc_ouput.ogg", "w");
  52.  
  53. printf("\nhere 0");
  54. libvlc_instance_t *vlcInstance;
  55. libvlc_media_player_t *mp;
  56. libvlc_media_t *media;
  57.  
  58.  
  59. char smem_options[256];
  60.  
  61.  
  62. //sprintf(smem_options, "#transcode{vcodec=theo,vb=800,acodec=vorb,ab=128,channels=2,samplerate=44100}:file{dst=stream-output.ogg}");
  63.  
  64.  
  65. sprintf(smem_options, "#transcode{vcodec=RV32}:smem{video-postrender-callback=%lld,video-prerender-callback=%lld}",
  66. // We are using transcode because smem only support raw audio and video formats
  67. (long long int)(intptr_t)(void*)&handleStream, (long long int)(intptr_t)(void*)&prepareRender);
  68.  
  69.  
  70.  
  71.  
  72. const char * const vlc_args[] = {
  73. "-I", "dummy", // Don't use any interface
  74. "--ignore-config", // Don't use VLC's config
  75. "--extraintf=logger", // Log anything
  76. "--verbose=3", // Be much more verbose then normal for debugging purpose
  77. "--sout", smem_options // Stream to memory
  78. };
  79.  
  80. printf("\nhere 1");
  81.  
  82. // We launch VLC
  83. vlcInstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
  84. printf("\nhere 2");
  85.  
  86. media = libvlc_media_new_path(vlcInstance,"sample.mkv");
  87.  
  88. if(!media){
  89. printf("\n no media");
  90. }else{
  91. printf("\n yes media");
  92. }
  93. printf("\nhere 3");
  94.  
  95.  
  96. mp = libvlc_media_player_new_from_media(media);
  97.  
  98. printf("\nhere 4");
  99.  
  100. // To be continued.
  101. libvlc_media_player_play(mp);
  102.  
  103.  
  104. while(true){sleep(120);break;}
  105.  
  106.  
  107. libvlc_media_player_stop(mp);
  108. libvlc_media_player_release(mp);
  109. libvlc_release(vlcInstance);
  110. libvlc_media_release(media);
  111.  
  112.  
  113. fclose(myfile);
  114. return 0;
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment