SDL 中播YUV和PCM數據的步驟:
1,播放YUV數據: 其實就是不斷更新紋理
//1 打開文件
video_file = fopen(path, "r");
//2 讀取數據
video_buff_len = fread(video_buf, 1, yuv_frame_len, video_file)
//3 更新紋理
SDL_UpdateTexture(texture, NULL, video_pos, video_width);
1,播放PCM數據
需要 SDL_OpenAudio(&spec, NULL) 打開播放器 spec 是設置參數:
//SDL_AudioSpec
spec.freq = 44100;
spec.format = AUDIO_S16SYS;
spec.channels = 2;
spec.silence = 0;
spec.samples = 1024;
spec.callback = read_audio_data;
spec.userdata = NULL;```
SDL_PauseAudio(0); // 播放 暫停
SDL_CloseAudio(); 結束
//1 打開文件
video_file = fopen(path, "r");
//2 讀取數據
video_buff_len = fread(video_buf, 1, yuv_frame_len, video_file)
3 在播放器回調函數中填充讀取的數據
SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
最後附上 雷神的學習資料