1:打开VLC播放器。
2:选择媒体菜单,在下拉菜单栏中,选择打开网络串流(快捷键Ctrl + N),输入:
udp/h264://@127.0.0.1:8880 或者
udp/h264://@:8880
3:点击播放按钮,使得VLC播放器处于等待码流状态。
4:使用udp协议向主机8880端口发送h264码流。
PS:读取h264文件,向目标主机发送h264码流。
#include<sys/socket.h> #include<netinet/in.h> #include<strings.h> #include<unistd.h> #include<string.h> #include <fcntl.h> #include<stdio.h> void sleep_milliseconds(long milliseconds){ struct timeval t_val; t_val.tv_sec = 0; t_val.tv_usec= milliseconds * 1000; select(0,NULL,NULL,NULL,&t_val); } int main(int argc, char const *argv[]) { int port = 8880; struct sockaddr_in addr_server; addr_server.sin_family = AF_INET; addr_server.sin_port = htons(port); addr_server.sin_addr.s_addr = htonl(INADDR_ANY); bzero(&(addr_server.sin_zero), 8); int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) { printf("socket error! "); return 1; } int fd = open("in.h264", O_RDONLY); if (fd < 0) { printf("open file fail! "); return 0; } printf("send file... "); const int MaxSize = 1024; uint8_t buf[MaxSize]; int ret = -1; int z = 0; while ((ret = read(fd, buf, MaxSize))) { z = sendto(sockfd, buf, ret, 0, (struct sockaddr *) &addr_server, sizeof(addr_server)); if (z < 0) { printf("sendto error "); return 0; } sleep_milliseconds(100); } close(fd); close(sockfd); return 0; }