buffer

Python-Opencv Write x264 video on memory buffer

随声附和 提交于 2021-02-07 10:34:19
问题 I have a problem for writing x264 video(or single frame) on memory buffer. In opencv for images, imencode and imdecode do this task. But i want save x264 video frame for lower memory usage and sending on internet. I am able to with jpeg but jpeg size bigger than x264 video frame and quality much worser. I searched but i can't find how i write video frame on buffer. Here is the example code to taking frames on webcam import numpy as np import cv2 cap = cv2.VideoCapture(0) cap.set(3,320) cap

Example of a buffer overflow leading to a security leak

百般思念 提交于 2021-02-04 09:39:44
问题 I read many articles about unsafe functions like strcpy, memcpy, etc. which may lead to security problems when processing external data, like the content of a file or data coming from sockets. This may sound stupid, but I wrote a vulnerable program but I did not manage to "hack" it. I understand the problem of buffer overflow. Take this example code: int main() { char buffer[1]; int var = 0; scan("%s", &buffer); printf("var = 0x%x\n", var); return 0; } When I execute the program and type

How to make a circular buffer?

我与影子孤独终老i 提交于 2021-01-29 18:06:15
问题 I have to make a circular buffer out of an array for class and I can't quite grasp how the concept is implemented. I get that there are are indexes that go back and forth but I don't really understand how this is actually implemented. How do you even assign a tail or head to elements of an array, or index them both ways? Any advice, code or explanation would be extremely helpful. 回答1: A circular buffer is basically just an array and two integers that keep track of the positions that you

Go: efficiently handling fragmented data received via TCP

空扰寡人 提交于 2021-01-29 17:12:40
问题 I am writing a small tcp-server that is only suppose to read data, parse the receiving data (dynamic length frames) and handling these frames. Consider the following code: func ClientHandler(conn net.Conn) { buf := make([]byte, 4096) n, err := conn.Read(buf) if err != nil { fmt.Println("Error reading:", err.Error()) return } fmt.Println("received ", n, " bytes of data =", string(buf)) handleData(buf) This is pretty much the essence of my code as is. I read X bytes into a empty buffer and then

Is there an easy way to create square buffers around point and if they intersect, merge them?

99封情书 提交于 2021-01-29 13:58:04
问题 I am trying to create square buffers around given points, I am able to create circular buffers but not square ones. from shapely.ops import transform from shapely.geometry import Point local_azimuthal_projection = "+proj=aeqd +R=6371000 +units=m +lat_0={} +lon_0={}".format(lat, lon) wgs84_to_aeqd = partial( pyproj.transform, pyproj.Proj('+proj=longlat +datum=WGS84 +no_defs'), pyproj.Proj(local_azimuthal_projection), ) aeqd_to_wgs84 = partial( pyproj.transform, pyproj.Proj(local_azimuthal

How to record video and take picture at the same time with single camera in GStreamer?

风格不统一 提交于 2021-01-29 11:48:58
问题 I'm trying to record video and take picture at the same time with single camera in GStreamer. But I have an issue. I use tee to use both record video and take a picture. To set video duration, I use num-buffers , assume that I set 100. When take picture, the num-buffers needed is only 1 . But when using tee , num-buffers of take picture pipeline is also 100. So It's mean, my program take 100 picture and my image file is up to 5Mb(320x240). I just want it's take a single picture each 1 minute

Catch buffered stdout output of exec.Command

北城以北 提交于 2021-01-29 09:53:23
问题 I'm trying to catch output of external program. Example: #include <stdio.h> #include <unistd.h> #include <stddef.h> int main() { int i = 0; while(i < 10) { printf("i = %i\n", i++); usleep(2000000); } return 0; } And here is my main.go: package main import ( "bufio" "io" "log" "os/exec" ) func reecho(closer io.ReadCloser) { reader := bufio.NewReader(closer) for { s, e := reader.ReadString('\n') if e != nil { log.Println(e) break } log.Println(s) } } func main() { cmd := exec.Command(".

C - how to poll() input without buffering?

天涯浪子 提交于 2021-01-29 07:54:12
问题 I am trying to detect any character typed to stdin (without a newline character). I tried : setvbuf(stdin, NULL, _IONBF); //This returns 0 struct pollfd pfd = {STDIN_FILENO, POLLIN}; while (!poll(pfd, 1, ms)) { /* do some thing, e.g. printf("n\n"); */ } It appears not stop printing when I typed q , but did stop after I hit enter . The system I am working on is arch-linux, compiler is gcc. 回答1: The q is being held up in the kernel's TTY layer driver/buffer because it is in "cooked" mode. In

What is the difference between a pointer to a buffer and a pointer to a file?

丶灬走出姿态 提交于 2021-01-29 07:24:44
问题 In Chapter 22 of " C Programming: A Modern Approach ", the basics of the <stdio.h> header are explained. One detail that has me a little confused is the difference between a pointer to a buffer and a pointer to a file (denoted as FILE * ). Consider the following (through which the confusion is derived): fopen is prototyped as: FILE *fopen(const char * restrict filename, const char * restrict mode) . fflush is prototyped as int fflush (FILE *stream) . fflush is described as a function the

Sum column in stream using node

↘锁芯ラ 提交于 2021-01-29 07:18:22
问题 My goal is to count the sum of a column which correlates to another column in a csv. For example, I have an input csv what looks like this "500","my.jpg" "500","my.jpg" "200","another.jpg" I want the output to be: [{ bytes: 1000, uri: "my.jpg" }, { bytes:200, "another.jpg" }] Note: I need to do this as a stream as there can be over 3 millions records for a given csv and looping is just too slow. I have managed to accomplish this using awk but I am struggling to implement it in node Here is