我试图找到一种将定义传递到头文件的方法,以便在格式化数组时使用它。我的代码是这样的:
#define CONSTANT 10
#include "myHeaderFile.h"
int main(headerFunction(array)){}
头文件:
int headerFunction(array[][CONSTANT]) { // Multidimensional array
}
它给了我一个没有设置 CONSTANT 的错误。更准确地说:错误:此处未声明“常量”(不在函数中)
所有代码:
#include
#define W 946
#define H 528
#include "myFunctions.h"
// Video resolution
// Allocate a buffer to store one frame
unsigned char frame[H][W][3] = {0};
int main(void)
{
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 1.mp4 -f image2pipe -c:v rawvideo -pix_fmt rgb24 - ", "r"); // ffmpeg -i 1.mp4 -f image2pipe -vcodec rawvideo -pix_fmt rgb24 -
FILE *pipeout = popen("ffmpeg -y -f rawvideo -vcodec rawvideo -pix_fmt rgb24 -s 946x528 -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
flip(frame,x,y,H,W);
// 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);
}
头文件:
int invertRGB(unsigned char frame [H][W][3],int x, int y,int H, int W){
for (y=0 ; y { frame[y][x][0] = 255 - frame[y][x][0]; frame[y][x][1] = 255 - frame[y][x][1]; frame[y][x][2] = 255 - frame[y][x][2]; } return frame; } int flip(unsigned char frame [H][W][3],int x, int y, int H, int W){ unsigned char frameTemp[H][W][3]; for (y=0 ; y { frameTemp[(H-1)-y][(W-1)-x][0] = frame[y][x][0]; frameTemp[(H-1)-y][(W-1)-x][1] = frame[y][x][1]; frameTemp[(H-1)-y][(W-1)-x][2] = frame[y][x][2]; } for (y=0 ; y { frame[y][x][0] = frameTemp[y][x][0]; frame[y][x][1] = frameTemp[y][x][1]; frame[y][x][2] = frameTemp[y][x][2]; } return frame; } 这是我尝试创建视频编辑器的尝试:)