int main (int argc, char **argv) { void *capture = capture_open("/dev/video0", VIDEO_WIDTH, VIDEO_HEIGHT, PIX_FMT_YUV420P); if (!capture) { fprintf(stderr, "ERR: can't open '/dev/video0'\n"); exit(-1); } void *encoder = vc_open(VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_FPS); if (!encoder) { fprintf(stderr, "ERR: can't open x264 encoder\n"); exit(-1); } void *sender = sender_open(TARGET_IP, TARGET_PORT); if (!sender) { fprintf(stderr, "ERR: can't open sender for %s:%d\n", TARGET_IP, TARGET_PORT); exit(-1); } int tosleep = 1000000 / VIDEO_FPS; FILE *fp_save = fopen("./my1.264", "wb"); for (; ; ) { // 抓 Picture pic; capture_get_picture(capture, &pic); // 压 const void *outdata; int outlen; int rc = vc_compress(encoder, pic.data, pic.stride, &outdata, &outlen); if (rc < 0) continue; // 发 sender_send(sender, outdata, outlen); fwrite(outdata, 1, outlen, fp_save); // 等 //usleep(tosleep); } fclose(fp_save); sender_close(sender); vc_close(encoder); capture_close(capture); return 0; }
void getNextFrame1 () { // capture: Picture pic; if (capture_get_picture(mp_capture, &pic) < 0) { fprintf(stderr, "==== %s: capture_get_picture err\n", __func__); m_started = 0; return; } // compress const void *outbuf; int outlen; if (vc_compress(mp_compress, pic.data, pic.stride, &outbuf, &outlen) < 0) { fprintf(stderr, "==== %s: vc_compress err\n", __func__); m_started = 0; return; } int64_t pts, dts; int key; vc_get_last_frame_info(mp_compress, &key, &pts, &dts); // save outbuf gettimeofday(&fPresentationTime, 0); fFrameSize = outlen; if (fFrameSize > fMaxSize) { fNumTruncatedBytes = fFrameSize - fMaxSize; fFrameSize = fMaxSize; } else { fNumTruncatedBytes = 0; } memmove(fTo, outbuf, fFrameSize); // notify afterGetting(this); m_started = 0; }