Utunbu VLC 播放器播放本機h264碼流


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!\n");
        return 1;
    }
    int fd = open("in.h264", O_RDONLY);
    if (fd < 0) {
        printf("open file fail!\n");
        return 0;
    }
    printf("send file...\n");
    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\n");
            return 0;
        }
        sleep_milliseconds(100);
    }
    close(fd);
    close(sockfd);
    return 0;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM