daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Dec 12th, 2018 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. codec = avcodec_find_encoder_by_name(CODEC_NAME);
  2. if (!codec) {
  3.     cerr << "Codec " << codec_name << " not foundn";
  4.     exit(1);
  5. }
  6.  
  7. c = avcodec_alloc_context3(codec);
  8. if (!c) {
  9.     cerr << "Could not allocate video codec contextn";
  10.     exit(1);
  11. }
  12.  
  13. pkt = av_packet_alloc();
  14. if (!pkt)
  15.     exit(1);
  16.  
  17. /* put sample parameters */
  18. c->bit_rate = 400000;
  19. /* resolution must be a multiple of two */
  20. c->width = PIC_HEIGHT;
  21. c->height = PIC_WIDTH;
  22. /* frames per second */
  23. c->time_base = (AVRational){1, FPS};
  24. c->framerate = (AVRational){FPS, 1};
  25. c->gop_size = 10;
  26. c->max_b_frames = 1;
  27. c->pix_fmt = AV_PIX_FMT_YUV420P;
  28. c->rtp_payload_size = 30000;
  29. if (codec->id == AV_CODEC_ID_H264)
  30.     av_opt_set(c->priv_data, "preset", "fast", 0);
  31. av_opt_set_int(c->priv_data, "slice-max-size", 30000, 0);
  32. /* open it */
  33. ret = avcodec_open2(c, codec, NULL);
  34. if (ret < 0) {
  35.     cerr << "Could not open codecn";
  36.     exit(1);
  37. }
  38.    
  39. void DeviceSource::deliverFrame() {
  40.     if (!isCurrentlyAwaitingData()) return; // we're not ready for the data yet
  41.  
  42.     u_int8_t* newFrameDataStart = (u_int8_t*) pkt->data;
  43.     unsigned newFrameSize = pkt->size; //%%% TO BE WRITTEN %%%
  44.     // Deliver the data here:
  45.     if (newFrameSize > fMaxSize) { // Condition becomes true many times
  46.         fFrameSize = fMaxSize;
  47.         fNumTruncatedBytes = newFrameSize - fMaxSize;
  48.     } else {
  49.         fFrameSize = newFrameSize;
  50.     }
  51.     gettimeofday(&fPresentationTime, NULL); // If you have a more accurate time - e.g., from an encoder - then use that instead.
  52.     // If the device is *not* a 'live source' (e.g., it comes instead from a file or buffer), then set "fDurationInMicroseconds" here.
  53.     memmove(fTo, newFrameDataStart, fFrameSize);
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand