-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgneg.c
46 lines (36 loc) · 1.37 KB
/
imgneg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
// Video resolution
#define W 1280
#define H 720
// Allocate a buffer to store one frame
unsigned char frame[H][W][3] = {0};
void main()
{
int x, y, count;
// Open an input pipe from ffmpeg and an output pipe to a second instance of ffmpeg
FILE *pipein = popen("ffmpeg -i teapot.mp4 -f image2pipe -vcodec rawvideo -pix_fmt rgb24 -", "r");
FILE *pipeout = popen("ffmpeg -y -f rawvideo -vcodec rawvideo -pix_fmt rgb24 -s 1280x720 -r 25 -i - -f mp4 -q:v 5 -an -vcodec mpeg4 output.mp4", "w");
// Process video frames
while(1)
{
// Read a frame from the input pipe into the buffer
count = fread(frame, 1, H*W*3, pipein);
// If we didn't get a frame of video, we're probably at the end
if (count != H*W*3) break;
// Process this frame
for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x)
{
// Invert each colour component in every pixel
frame[y][x][0] = 255 - frame[y][x][0]; // red
frame[y][x][1] = 255 - frame[y][x][1]; // green
frame[y][x][2] = 255 - frame[y][x][2]; // blue
}
// Write this frame to the output pipe
fwrite(frame, 1, H*W*3, pipeout);
}
// Flush and close input and output pipes
fflush(pipein);
pclose(pipein);
fflush(pipeout);
pclose(pipeout);
}