Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- codec = avcodec_find_encoder_by_name(CODEC_NAME);
- if (!codec) {
- cerr << "Codec " << codec_name << " not foundn";
- exit(1);
- }
- c = avcodec_alloc_context3(codec);
- if (!c) {
- cerr << "Could not allocate video codec contextn";
- exit(1);
- }
- pkt = av_packet_alloc();
- if (!pkt)
- exit(1);
- /* put sample parameters */
- c->bit_rate = 400000;
- /* resolution must be a multiple of two */
- c->width = PIC_HEIGHT;
- c->height = PIC_WIDTH;
- /* frames per second */
- c->time_base = (AVRational){1, FPS};
- c->framerate = (AVRational){FPS, 1};
- c->gop_size = 10;
- c->max_b_frames = 1;
- c->pix_fmt = AV_PIX_FMT_YUV420P;
- c->rtp_payload_size = 30000;
- if (codec->id == AV_CODEC_ID_H264)
- av_opt_set(c->priv_data, "preset", "fast", 0);
- av_opt_set_int(c->priv_data, "slice-max-size", 30000, 0);
- /* open it */
- ret = avcodec_open2(c, codec, NULL);
- if (ret < 0) {
- cerr << "Could not open codecn";
- exit(1);
- }
- void DeviceSource::deliverFrame() {
- if (!isCurrentlyAwaitingData()) return; // we're not ready for the data yet
- u_int8_t* newFrameDataStart = (u_int8_t*) pkt->data;
- unsigned newFrameSize = pkt->size; //%%% TO BE WRITTEN %%%
- // Deliver the data here:
- if (newFrameSize > fMaxSize) { // Condition becomes true many times
- fFrameSize = fMaxSize;
- fNumTruncatedBytes = newFrameSize - fMaxSize;
- } else {
- fFrameSize = newFrameSize;
- }
- gettimeofday(&fPresentationTime, NULL); // If you have a more accurate time - e.g., from an encoder - then use that instead.
- // If the device is *not* a 'live source' (e.g., it comes instead from a file or buffer), then set "fDurationInMicroseconds" here.
- memmove(fTo, newFrameDataStart, fFrameSize);
- }
Add Comment
Please, Sign In to add comment