FFMPEG开发rtsp播放器
公司做桌面共享的时候,抓屏使用的是EasyScreenLive,流媒体服务器EasyDarwin,客户端播放器使用的是vlc,在网络不好的情况下经常会出现卡顿、黑屏,后来使用EasyPlayer-RTSP播放效果不错,但是EasyPlayer不是开源的可控性也不强,也不能添加日志,所以萌生自己开发一个rtsp播放器的想法。
下图是经过俩天测试后的效果,左侧是easyplayer的效果,右侧是自己写的demo。
demo是模仿ffplayer源码开发的所以我们就通过分析ffplayer来进行吧,demo只保留了视频信号,没有处理音频和字幕。
1.ffplayer read_thread 分析
2.ffplayer packet_queue 分析
3.ffplayer decoder_thread 分析
4.ffplayer frame_queue分析
首先介绍贯穿整个项目的一个结构体
typedef struct VideoState {
AVFormatContext *ic;
AVStream *video_st;
SwsContext *swsContext;
AVFrame *avFrameRGB;
int force_refresh;
const char *urlname;
uint8_t *imageBuffer;
FrameQueue pictq;
PacketQueue videoq;
Decoder viddec;
pthread_cond_t continue_read_thread;
ZST_ReadThread *readThread = nullptr;
int last_video_stream,video_stream_index;
int eof;
int abort_request;
int frame_drops_late;
int av_sync_type;
int codec_width;
int codec_height;
int realtime;
double frame_timer;
double max_frame_duration; //
} VideoState;
存在问题
- avformat_find_stream_info 和avcodec_send_packet程序异常崩溃,解决好长时间都没有解决,然后用命令行测试ffplayer.exe播放视频也会崩溃,然后在windows用不同版本ffmpeg进行编译都会出现这个随机崩溃得问题,然后就在ubuntu下编译ffmepg,成功解决。
ubuntu下ffmepg编译