Advertisement
Guest User

client

a guest
Sep 22nd, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. // Make with:
  2. // g++ -std=c++0x tutorial.cpp $(pkg-config --libs --cflags libavformat) -lstdc++ -o test
  3.  
  4. #include <stdio.h>
  5.  
  6. extern "C" {
  7.   #include <libavcodec/avcodec.h>
  8.   #include <libavformat/avformat.h>
  9.   #include <libavutil/avutil.h>
  10. }
  11. #include <mutex>
  12.  
  13. int main(int argc, char *argv[]) {
  14.   // initialize av decoders
  15.   static std::once_flag initFlag;
  16.   std::call_once(initFlag, []() { av_register_all(); });
  17.  
  18.   // shared_ptr make it exception-safe
  19.   std::shared_ptr<AVFormatContext> avFormat(avformat_alloc_context(),
  20.             &avformat_free_context);
  21.  
  22.   // open and parse header information
  23.   auto avFormatPtr = avFormat.get();
  24.   avformat_network_init();
  25.   if (avformat_open_input( &avFormatPtr, "rtp://localhost:5000",
  26.               nullptr, nullptr) != 0)
  27.     throw std::runtime_error("Error while calling avformat_open_input (probably invalid file format)" );
  28.  
  29.  
  30.   fprintf(stderr, "past\n");
  31.  
  32.   if (avformat_find_stream_info(avFormat.get(), nullptr) < 0)
  33.     throw std::runtime_error("Error while calling avformat_find_stream_info");
  34.  
  35.   fprintf(stderr, "past\n");
  36.  
  37.   return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement