illuspas / Node-Media-Server

A Node.js implementation of RTMP/HTTP-FLV/WS-FLV/HLS/DASH/MP4 Media Server
https://www.npmjs.com/package/node-media-server
MIT License
5.92k stars 1.52k forks source link

Record to MP4 doesn't work #145

Open bobahvas opened 5 years ago

bobahvas commented 5 years ago

Output:

2018-11-12 01:46:26 3108 [INFO] Node Media Server v1.4.7
2018-11-12 01:46:26 3108 [INFO] Node Media Rtmp Server started on port: 1935
2018-11-12 01:46:26 3108 [INFO] Node Media Http Server started on port: 8080
2018-11-12 01:46:26 3108 [INFO] Node Media WebSocket Server started on port: 8080
2018-11-12 01:46:26 3108 [INFO] Node Media Trans Server started for apps: [ vod ] , MediaRoot: ./media, ffmpeg version: 4.0.2
2018-11-12 01:46:29 3108 [INFO] [rtmp connect] id=P6UP2LJK ip=::1 app=vod args={"app":"vod","type":"nonprivate","flashVer":"FMLE/3.0 (compatible; Lavf58.12.100)","tcUrl":"rtmp://localhost:1935/vod"}
2018-11-12 01:46:29 3108 [INFO] [rtmp publish] New stream. id=P6UP2LJK streamPath=/vod/STREAM_NAME streamId=1
2018-11-12 01:46:29 3108 [INFO] [Transmuxing MP4] /vod/STREAM_NAME to ./media/vod/STREAM_NAME/2018-11-12-01-46.mp4
2018-11-12 01:46:29 3108 [FFDEBUG] -y,-fflags,nobuffer,-analyzeduration,1000000,-i,rtmp://127.0.0.1:1935/vod/STREAM_NAME,-c:v,libx264,-c:a,aac,-f,tee,-map,0:a?,-map,0:v?,[movflags=faststart]./media/vod/STREAM_NAME/2018-11-12-01-46.mp4|
2018-11-12 01:46:29 3108 [FFDEBUG] FF输出:ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.1 (GCC) 20180722

2018-11-12 01:46:29 3108 [FFDEBUG] FF输出:  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100

2018-11-12 01:46:29 3108 [INFO] [rtmp connect] id=PGESY7PL ip=::ffff:127.0.0.1 app=vod args={"app":"vod","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/vod","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1}
2018-11-12 01:46:29 3108 [INFO] [rtmp play] Join stream. id=PGESY7PL streamPath=/vod/STREAM_NAME  streamId=1 
2018-11-12 01:46:30 3108 [INFO] [rtmp publish] Handle video. id=P6UP2LJK streamPath=/vod/STREAM_NAME frame_type=1 codec_id=7 codec_name=H264 512x288
2018-11-12 01:46:30 3108 [INFO] [rtmp publish] Handle audio. id=P6UP2LJK streamPath=/vod/STREAM_NAME sound_format=10 sound_type=2 sound_size=1 sound_rate=3 codec_name=AAC 44100 2ch
2018-11-12 01:46:31 3108 [FFDEBUG] FF输出:Input #0, flv, from 'rtmp://127.0.0.1:1935/vod/STREAM_NAME':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: 
2018-11-12 01:46:31 3108 [FFDEBUG] FF输出:isomiso2avc1mp41
    title           : Big Buck Bunny, Sunflower version
    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
    composer        : Sacha Goedegebure
    genre           : Animation
    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
    encoder         : Lavf58.12.100
  Duration: 00:00:00.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 512x288 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 1k tbn, 60 tbc
    Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s

2018-11-12 01:46:31 3108 [FFDEBUG] FF输出:Stream mapping:
  Stream #0:1 -> #0:0 (aac (native) -> aac (native))
  Stream #0:0 -> #0:1 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help

2018-11-12 01:46:31 3108 [FFDEBUG] FF输出:frame=    0 fps=0.0 q=0.0 size=N/A time=-577014:32:22.77 bitrate=N/A speed=N/A    
2018-11-12 01:46:32 3108 [FFDEBUG] FF输出:frame=    0 fps=0.0 q=0.0 size=N/A time=-577014:32:22.77 bitrate=N/A speed=N/A    
2018-11-12 01:46:32 3108 [FFDEBUG] FF输出:frame=    0 fps=0.0 q=0.0 size=N/A time=-577014:32:22.77 bitrate=N/A speed=N/A    
2018-11-12 01:46:33 3108 [FFDEBUG] FF输出:frame=    0 fps=0.0 q=0.0 size=N/A time=-577014:32:22.77 bitrate=N/A speed=N/A    
2018-11-12 01:46:33 3108 [FFDEBUG] FF输出:frame=    0 fps=0.0 q=0.0 size=N/A time=-577014:32:22.77 bitrate=N/A speed=N/A    
2018-11-12 01:46:34 3108 [FFDEBUG] FF输出:Too many packets buffered for output stream 0:0.

2018-11-12 01:46:34 3108 [FFDEBUG] FF输出:[aac @ 000001bca9c9eac0] Qavg: 753.109
[aac @ 000001bca9c9eac0] 2 frames left in the queue on closing

2018-11-12 01:46:34 3108 [INFO] [rtmp play] Close stream. id=PGESY7PL streamPath=/vod/STREAM_NAME streamId=1
2018-11-12 01:46:34 3108 [INFO] [rtmp disconnect] id=PGESY7PL
2018-11-12 01:46:34 3108 [FFDEBUG] FF输出:Conversion failed!

2018-11-12 01:46:34 3108 [INFO] [Transmuxing end] /vod/STREAM_NAME

Configuration:

ffmpeg -re -i data/sample.mp4 -c:v libx264 -preset superfast -tune zerolatency -c:a aac -ar 44100 -f flv rtmp://localhost/vod/STREAM_NAME
const { NodeMediaServer } = require('node-media-server');

const config = {
    logType: 4,
    rtmp: {
        port: 1935,
        chunk_size: 60000,
        gop_cache: true,
        ping: 60,
        ping_timeout: 30
    },
    http: {
        port: 8080,
        mediaroot: './media',
        allow_origin: '*'
    },
    trans: {
        ffmpeg: 'D:\\ffmpeg\\ffmpeg.exe',
        tasks: [
            {
                app: 'vod',
                mp4: true,
                mp4Flags: '[movflags=faststart]',
            }
        ]
    }
};

const nms = new NodeMediaServer(config);
nms.run();
kaustas commented 5 years ago

I also had issue with saving mp4 record of rtmp stream. I'm using Windows as well. When stream stopped Node-media-server kills ffmpeg process before it can correcly finish record and add moov atom block in the begining of file. So when i try to deal with mp4 file i got: moov atom not found error. Solution for me was to remove 'this.ffmpeg_exec.kill();' line from node_trans_session.js file.

Spo-oky commented 5 years ago

I've changed to this.ffmpeg_exec.stdin.write('q') instead of 'this.ffmpeg_exec.kill();' as I've seen it on internet on "how to quit ffmpeg from nodejs". It works for me.... Hope it helps you.

Sasha2018RL commented 5 years ago

I've changed to this.ffmpeg_exec.stdin.write('q') instead of 'this.ffmpeg_exec.kill();' as I've seen it on internet on "how to quit ffmpeg from nodejs". It works for me.... Hope it helps you.

Its work, thank you!

lonasozo commented 1 year ago

I got same error on last version

lonasozo commented 1 year ago

P.s. I've made the changes suggested in this issue, still have problems on bigger files.