如何解决头文件为什么不读取C中的常量#define?
我试图找到一种将格式传递到头文件中以在格式化数组时使用它的方法。 我的代码是这样的:
#define CONSTANT 10
#include "myHeaderFile.h"
int main(headerFunction(array)){}
头文件:
int headerFunction(array[][CONSTANT]) { // Multidimensional array
}
这给我一个错误,提示未设置CONSTANT。 更确切地说: 错误:此处未声明“ CONSTANT”(不在函数中)
所有代码:
#include <stdio.h>
#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,H,W);
// Write this frame to the output pipe
fwrite(frame,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<H ; ++y) for (x=0 ; x<W ; ++x)
{
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 W){
unsigned char frameTemp[H][W][3];
for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x)
{
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<H ; ++y) for (x=0 ; x<W ; ++x)
{
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;
}
这是我尝试创建视频编辑器的尝试:)
解决方法
这是因为在读取头文件时未定义CONSTANT
。
尝试一下:
#define CONSTANT 10
#include "myHeaderFile.h"
int main(headerFunction(array)){}
在“所有代码”中,您对常量(在unsigned char frame [H][W][3]
中使用)和参数(在int H,int W
中使用)使用了相同的名称,因此,参数也被视为宏并替换为整数,使定义无效。
在这种情况下,大小是固定的,因此您不需要参数H
和W
,应将其删除。
不要忘记从调用点中删除多余的参数。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。