Skip to content

终于调通了H264网络裸流播放的功能,再次感谢 #3

@billzbh

Description

@billzbh

一开始这个demo其实已经弄好了接口。
play接口为播放本地H264裸流文件或者MP4文件。
render其实可以播放网络H264裸流,做法是:

  1. java -> JNI -> 创建一个PIPE文件,缓存fd变量(参考文章)
  2. 调用render
  3. java -> JNI -> 不断将网络收到的数据写到 PIPE(fd)里

可能遇到的问题:

  1. 播放画面需要等待5-6s才出现,可以在 avformat_find_stream_info 前面调用avFormatContext->max_analyze_duration = 1 * AV_TIME_BASE;
    在avformat_open_input前调用avFormatContext->probesize = 50 *1024;//这个大小最好是你H264关键帧的大小

  2. 播放每隔2s有一次卡顿,检查来检查去,感觉是PIPE文件的缓冲不够,导致网络数据写的时候阻塞了。所以我将PIPE文件设置了一下,问题解决: fcntl(fd, F_SETPIPE_SZ, 1024 * 256);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions