Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. // search video stream
  2. video_stream_index = av_find_best_stream(format_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
  3.  
  4. if (video_stream_index == -1) {
  5. log(LL_ERR, "No video stream in rstp feed");
  6. goto fail;
  7. }
  8.  
  9. av_init_packet(&packet);
  10.  
  11. output_ctx = avformat_alloc_context();
  12.  
  13. av_read_play(format_ctx);
  14.  
  15. ///////
  16. // Get the codec
  17. codec = avcodec_find_decoder(format_ctx->streams[video_stream_index]->codecpar->codec_id);
  18. if (!codec) {
  19. log(LL_ERR, "Decoder not found (rtsp)");
  20. goto fail;
  21. }
  22.  
  23. // Add this to allocate the context by codec
  24. codec_ctx = avcodec_alloc_context3(codec);
  25. avcodec_get_context_defaults3(codec_ctx, codec);
  26. avcodec_parameters_to_context(codec_ctx, format_ctx->streams[video_stream_index]->codecpar);
  27.  
  28. if (avcodec_open2(codec_ctx, codec, NULL) < 0) {
  29. log(LL_ERR, "avcodec_open2 failed");
  30. goto fail;
  31. }
  32. ///////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement