is currently getting started learning about FFmpeg. When introducing SDL threads, there are the following problems:
1. Create demux_ thread in main thread
2. demux_thread
3. main
4. Complete code ffplay.c
-sharpinclude <stdio.h>
-sharpinclude <libavformat/avformat.h>
-sharpinclude <SDL.h>
-sharpinclude <SDL_thread.h>
-sharpinclude <libavutil/avstring.h>
-sharpinclude "main.h"
int demux_thread(void *opaque) {
VideoState *is = (VideoState *) opaque;
AVFormatContext *ic = NULL;
int ret;
printf("1");
ret = avformat_open_input(&ic, is->filename, 0, 0);
printf("2");
if (ret < 0) {
char buf[1024];
av_strerror(ret, buf, sizeof(buf));
fprintf(stderr, "Failed avformat_open_input: %s\n", buf);
return -1;
}
printf("");
return 0;
}
int main(int argc, char *argv[]) {
VideoState *is = NULL;
is = av_mallocz(sizeof(VideoState));
av_register_all();
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
fprintf(stderr, "Failed SDL_Init: %s", SDL_GetError());
exit(1);
}
char *filename = "/Users/xxxx/Workspace/C/ffplay/test.mp4";
av_strlcpy(is->filename, filename, sizeof(is->filename));
demux_thread(is);
// is->demux_tid = SDL_CreateThread(demux_thread, "demux_thread", is);
// if (!is->demux_tid) {
// fprintf(stderr, "Failed SDL_CreateThread\n");
// av_free(is);
// return -1;
// }
return 0;
}