winshining / nginx-http-flv-module

A media streaming server based on nginx-rtmp-module. In addtion to the features nginx-rtmp-module provides, HTTP-FLV, GOP cache, VHosts (one IP for multi domain names) and JSON style statistics are supported now.
BSD 2-Clause "Simplified" License
2.75k stars 571 forks source link

WriteN, RTMP send error 32(**bytes) #251

Closed CJHbeyondDiana closed 11 months ago

CJHbeyondDiana commented 11 months ago

在ubuntu中,使用工业相机读取视频流,无音频流,并通过rtmp推流,打算使用http-flv拉流,终端提示WriteN, RTMP send error 32 (129 bytes) WriteN, RTMP send error 32 (39 bytes) WriteN, RTMP send error 9 (42 bytes),我发现如果只编译nginx-rtmp模块的话,推流没啥问题,但是我一旦编译nginx-http-flv模块,推流就会提示以上信息,使用命令行推流的话也没问题,但是我需要实时读取并推流,这是nginx的问题还是我代码的问题?代码中这个最后一步ret_code = av_interleaved_write_frame(format_context,&pack);返回值一直是-1

Expected behavior (期望行为)

Actual behavior (实际行为)

OS and Nginx version (操作系统和 Nginx 版本号)

ubuntu 18.04 最新nginx

Configuration file (配置文件)

配置文件:

user nobody;

worker_processes 1;

error_log logs/error.log;

error_log logs/error.log notice;

error_log logs/error.log info;

pid logs/nginx.pid;

events { worker_connections 1024; }

http { include mime.types; default_type application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }
    location /live {
        flv_live on; #当HTTP请求以/live结尾,匹配这儿,这个选项表示开启了flv直播播放功能
        chunked_transfer_encoding  on; #HTTP协议开启Transfer-Encoding: chunked;方式回复

        add_header 'Access-Control-Allow-Origin' '*'; #添加额外的HTTP头
        add_header 'Access-Control-Allow-Credentials' 'true'; #添加额外的HTTP头
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

} rtmp { server { listen 1935; #Nginx监听的RTMP推流/拉流端口 application live { live on; #当推流时,RTMP路径中的APP(RTMP中一个概念)匹配myapp时,开启直播 record off; #不记录视频 gop_cache off;

        #gop_cache on;
        #record video;                         #记录直播视频
        #record_path /tmp/rec;                 #视频保存路径
        #record_suffix -%d-%b-%y-%T.flv;       #视频保存名:日期+.flv
    }
}

}

Steps to reproduce the behavior (复现问题步骤)

Error log if any (错误日志)

2023/10/17 01:08:36 [error] 17325#0: *1 codec: invalid video codec header size=5, client: 127.0.0.1, server: 0.0.0.0:1935

winshining commented 11 months ago

日志已经告诉你了,发送的 avc header 不完整,需要至少 18 个字节,nginx-rtmp-module 没做检查。

CJHbeyondDiana commented 11 months ago

大佬可以帮忙看看代码嘛,实在找不到解决办法了 ,很头疼,不管在什么系统上运行都是rtmp可成功推流,http-flv就不行@winshining