- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 FFmpeg 解码 H.264 视频,用于以下程序:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <time.h>
#include <libavcodec/avcodec.h>
#include <libavutil/mathematics.h>
#include <SDL/SDL.h>
void sigint_handler(int signal) {
printf("\n");
exit(0);
}
const char *window_title;
SDL_Surface *screen;
SDL_Overlay *yuv_overlay;
#define INBUF_SIZE 80000
/*
* Video decoding example
*/
static long get_time_diff(struct timeval time_now) {
struct timeval time_now2;
gettimeofday(&time_now2,0);
return time_now2.tv_sec*1.e6 - time_now.tv_sec*1.e6 + time_now2.tv_usec - time_now.tv_usec;
}
int video_open(AVCodecContext *avctx, const char *filename){
int flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
int w,h;
flags |= SDL_RESIZABLE;
if (avctx->width){
w = avctx->width;
h = avctx->height;
} else {
w = 640;
h = 480;
}
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_INIT_VIDEO failed!\n");
exit(1);
}
screen = SDL_SetVideoMode(w, h, 0, flags);
if (!screen) {
fprintf(stderr, "SDL: could not set video mode - exiting\n");
return -1;
}
if (!window_title)
window_title = filename;
SDL_WM_SetCaption(window_title, window_title);
yuv_overlay = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, screen);
if (yuv_overlay->hw_overlay) {
fprintf(stderr, "Using hardware overlay!\n");
}
return 0;
}
int main(int argc, char **argv) {
AVCodec *codec;
AVCodecContext *c= NULL;
AVCodecParserContext *parser = NULL;
int frame, got_picture, len2, len;
const char *filename;
FILE *f;
AVFrame *picture;
char *arghwtf = malloc(INBUF_SIZE);
char *luma = NULL;
char *chroma = NULL;
int i=0;
uint64_t in_len;
int pts, dts;
struct timeval t;
float inv_fps = 1e6/23.98;
AVPacket avpkt;
SDL_Rect rect;
/* register all the codecs */
avcodec_register_all();
filename = argv[1];
av_init_packet(&avpkt);
printf("Decoding file %s...\n", filename);
/* find the H.264 video decoder */
codec = avcodec_find_decoder(CODEC_ID_H264);
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
c = avcodec_alloc_context3(codec);
picture = avcodec_alloc_frame();
c->skip_loop_filter = 48; // skiploopfilter=all
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}
/* the codec gives us the frame size, in samples */
parser = av_parser_init(c->codec_id);
parser->flags |= PARSER_FLAG_ONCE;
f = fopen(filename, "rb");
if (!f) {
fprintf(stderr, "could not open %s\n", filename);
exit(1);
}
frame = 0;
gettimeofday(&t, 0);
if(fread(arghwtf, 1, INBUF_SIZE, f) == 0) {
exit(1);
}
in_len = 80000;
while (in_len > 0 && !feof(f)) {
len = av_parser_parse2(parser, c, &avpkt.data, &avpkt.size, arghwtf, in_len,
pts, dts, AV_NOPTS_VALUE);
len2 = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
if (len2 < 0) {
fprintf(stderr, "Error while decoding frame %d\n", frame);
exit(1);
}
if (got_picture) {
if(!screen) {
video_open(c, filename);
rect.x = 0;
rect.y = 0;
rect.w = c->width;
rect.h = c->height;
inv_fps = av_q2d(c->time_base);
fprintf(stderr, "w:%i h:%i\n", rect.w, rect.h);
luma = malloc(c->width*c->height);
chroma = malloc(c->width*c->height/4);
SDL_DisplayYUVOverlay(yuv_overlay, &rect);
signal(SIGINT, sigint_handler);
}
fprintf(stderr, "\rDisplaying %c:frame %3d (%02d:%02d)...", av_get_pict_type_char(picture->pict_type), frame, frame/1440, (frame/24)%60);
fflush(stderr);
SDL_LockYUVOverlay(yuv_overlay);
for(i=0;i<c->height;i++) {
memcpy(luma + i * c->width, picture->data[0] + i * picture->linesize[0], c->width);
}
memcpy(yuv_overlay->pixels[0], luma, c->width * c->height);
for(i=0;i<c->height/2;i++) {
memcpy(chroma + i * c->width/2, picture->data[2] + i * picture->linesize[2], c->width/2);
}
memcpy(yuv_overlay->pixels[1], chroma, c->width * c->height / 4);
for(i=0;i<c->height/2;i++) {
memcpy(chroma + i * c->width/2, picture->data[1] + i * picture->linesize[1], c->width/2);
}
memcpy(yuv_overlay->pixels[2], chroma, c->width * c->height / 4);
SDL_UnlockYUVOverlay(yuv_overlay);
SDL_DisplayYUVOverlay(yuv_overlay, &rect);
while(get_time_diff(t) < inv_fps) {
sleep(1000);
}
frame++;
gettimeofday(&t, 0);
}
memcpy(arghwtf, arghwtf + len, 80000-len);
fread(arghwtf + 80000 - len, 1, len, f);
}
/* some codecs, such as MPEG, transmit the I and P frame with a
latency of one frame. You must do the following to have a
chance to get the last frame of the video */
avpkt.data = NULL;
avpkt.size = 0;
len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
if (got_picture) {
printf("saving last frame %3d\n", frame);
fflush(stdout);
/* Display last frame here, same code as in the decoding loop above. */
frame++;
}
fclose(f);
avcodec_close(c);
av_free(c);
av_free(picture);
printf("\n");
}
它给出了错误:
||=== H264_decoding, Debug ===|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp||In function ‘int main(int, char**)’:|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|107|error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|136|warning: ‘AVFrame* avcodec_alloc_frame()’ is deprecated (declared at /home/yoohoo/ffmpeg_build/include/libavcodec/avcodec.h:3629) [-Wdeprecated-declarations]|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|136|warning: ‘AVFrame* avcodec_alloc_frame()’ is deprecated (declared at /home/yoohoo/ffmpeg_build/include/libavcodec/avcodec.h:3629) [-Wdeprecated-declarations]|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|138|error: invalid conversion from ‘int’ to ‘AVDiscard’ [-fpermissive]|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|140|error: ‘avcodec_open’ was not declared in this scope|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|163|error: invalid conversion from ‘char*’ to ‘const uint8_t* {aka const unsigned char*}’ [-fpermissive]|
/home/yoohoo/ffmpeg_build/include/libavcodec/avcodec.h|4465|error: initializing argument 5 of ‘int av_parser_parse2(AVCodecParserContext*, AVCodecContext*, uint8_t**, int*, const uint8_t*, int, int64_t, int64_t, int64_t)’ [-fpermissive]|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|181|error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|182|error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|188|error: ‘av_get_pict_type_char’ was not declared in this scope|
/home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|210|error: ‘sleep’ was not declared in this scope|
||=== Build finished: 9 errors, 2 warnings ===|
我想知道这是一个不兼容的问题,因为我将这个 C 程序移到了 C++,但我最终需要在 C++ 中使用它。如何解决这些无效转换问题?提前致谢!
最佳答案
在代码的 main() 函数中
char *arghwtf = malloc(INBUF_SIZE);
您已经使用返回 void * 的 malloc 函数分配了内存,并且您正在将此 void * 分配给 char *,这就是您收到错误的原因。您必须将其类型转换为 char *。
试试这个。
char *arghwtf =(char *) malloc(INBUF_SIZE);
关于c++ - FFmpeg H264解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30345495/
我尝试在安装了多类型 MFC 库的 visual studio 2015 MFC 上运行以前编写的 MFC c++ 代码。 但是,我这里仍然有 12 个关于缺少函数的错误: IntelliSense:
我正在学习 OOP 并且有疑问。假设我有一个包含 ClassB.h 的文件 ClassA.h,并且在某些时候我的 ClassB.h 需要包含 ClassA .h。 这会产生一个错误,我想我明白为什么会
我开始使用 CUDA 进行编程,在一些示例中我找到了包含文件 cuda.h、cuda_runtime.h 和 cuda_runtime_api.h 包含在代码中。有人可以向我解释一下这些文件之间的区别
我有一些生成正则表达式的代码。那么下面的表达式实际上是: ^(?:\s*((exclude|include|hide|show|protect|risk|dir-merge|merge)),\s*((
我一直在查看一些源代码,以更好地了解我们使用的这款游戏的核心,并编写更可靠、更快速的插件。然后我发现了这段奇怪的代码...... public void setMaxH(double amount)
通常我们会使用标准类型作为 std::unordered_map 的键和值.但现在我需要自定义我自己的键和值类。 键类在block_cache_key.h 中定义如下: #ifndef BLOCK_C
例如,我想要两个头文件,它们可以依赖于另一个头文件中的函数。 //Header1.h file #include Header2.h void h1(){ //... func1(); } v
我正在研究来自 Sedgewick 的 Shell 排序 Algorithms in C part 1-4在第 172 页。 我使用 size (数组的长度),而不是 l和 r (开始和结束);所以我
我在 macOS BigSur 上通过 VMWare 使用 Ubuntu 20.04.2 LTS。我安装了最新版本的 tcl、tcl-dev、tk 和 tk-dev - 版本 8.6。我想编译 Arc
我用我的 glu 和 gl 头文件构建了一个 OpenGL 程序,默认包含在 windows 7 专业版中。现在,我买了一本描述 OpenGL 游戏开发的书。这本书的作者说,我必须在我的项目中包含 g
我想在 token 中保留特殊字符,同时仍对特殊字符进行 token 化。说我有话 "H&R Blocks" 我想将其标记为 "H", "R", "H&R", "Blocks" 我读了http://w
关于 hash 作为 trans 参数的另一个问题。在下面的代码中,简单地使用 hash 会给出不正确的结果,但是将其替换为 keys 和 values 会使其正确。怎么了? my @alph1 =
我已经编写了一个 C 程序,它获取屏幕像素的 RGB 值 (0-255),并知道其位置 (x,y)。它可以在 Linux 中运行,但是当我尝试在 Visual Studio (Windows) 中编译
我已经使用 Windows 7 专业版中默认包含的 glu 和 gl 头文件构建了一个 OpenGL 程序。现在,我买了一本描述 OpenGL 游戏开发的书。这本书的作者说,我必须将glew head
#include using namespace std; #include //#include int main() { initscr();
h:messages h:form 内的组件还显示与外部组件相关的消息。 如何限制它只显示与包含 h:form 内的组件相关的消息? 我不喜欢用单独的h:message来使我的代码膨胀。每个输入组件的
我下载了示例代码和 cpp 文件,其中包含 list.h、queue.h 和 vector.h 等头文件,如果我尝试构建,我会收到“ fatal error :没有这样的文件或目录编译终止”我想我应该
我有一个编译成功的桌面项目,但是在我向项目添加新配置以支持 Windows Mobile 平台后,我收到以下错误: error C2146: syntax error : missing ';' be
有很多关于这个错误的帖子,但我无法解决它,我希望你能拿出解决方案。我在 Ubuntu 机器上。 ~/graphmap2$ 在这个文件夹中,我下载了 zlib。可以看图 经过一番谷歌搜索后,我还注意到没
是否可以在 Visual C++ 中使用以下 header : 图.h dos.h bios.h 最佳答案 据我所知,无法在 Visual C++ 中使用它, 与此同时,我希望您关注 Open Wat
我是一名优秀的程序员,十分优秀!