FFmpeg流媒体(1)

2019-02-22  本文已影响0人  Goning

FFmpeg发布与录制RTMP流


1、rtmp_app参数

通过该参数设置推流发布点,录制命令如下:

ffmpeg -rtmp_app live -i rtmp://publish.chinaffmpeg.com -c copy -f flv output.flv

或发布流命令如下:

ffmpeg -re -i input.mp4 -c copy -f flv -rtmp_app live rtmp://publish.chinaffmpeg.com
[rtmp @ 0x7fa4f3600380] Unexpected reply on getStreamLength()
[rtmp @ 0x7fa4f3600380] Server error: identify stream failed.
rtmp://publish.chinaffmpeg.com: Unknown error occurred

报错如上,此错误是因为未设置stream项,但rtmp_app参数设置是生效的,可通过Wireshark抓包确认,如下图所示:


2、rtmp_playpath参数
ffmpeg -re -i input.mp4 -c copy -f flv -rtmp_app live -rtmp_playpath class rtmp://publish.chinaffmpeg.com
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.19.100
  Duration: 00:00:30.32, start: 0.000000, bitrate: 397 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], 261 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, flv, to 'rtmp://publish.chinaffmpeg.com':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
    Stream #0:0(und): Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p, 480x208 [SAR 16:15 DAR 32:13], q=2-31, 261 kb/s, 25 fps, 25 tbr, 1k tbn, 12800 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help

设置了rtmp_app与rtmp_playpath,可通过以下命令从RTMP服务器中拉取直播流并录制:

ffmpeg -rtmp_app live -rtmp_playpath class -i rtmp://publish.chinaffmpeg.com -c copy -f flv output.flv

如果不使用rtmp_app与rtmp_playpath参数,也可以使用以下参数方式进行推流和拉流:

ffmpeg -i input.mp4 -c copy -f flv rtmp://publish.chinaffmpeg.com/live/class
ffmpeg -i rtmp://publish.chinaffmpeg.com/live/class -c copy -f flv output.flv
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.19.100
  Duration: 00:00:30.32, start: 0.000000, bitrate: 397 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], 261 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, flv, to 'rtmp://publish.chinaffmpeg.com/live/class':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
    Stream #0:0(und): Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p, 480x208 [SAR 16:15 DAR 32:13], q=2-31, 261 kb/s, 25 fps, 25 tbr, 1k tbn, 12800 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help

3、rtmp_pageurl、rtmp_swfurl、rtmp_tcurl参数

在RTMP的Connect命令中包含了很多Object,其中就包括rtmp_pageurl、rtmp_swfurl、rtmp_tcurl等,例如通过页面的Flashplayer进行播放rtmp_pageurl。
FFmpeg发起播放时,不会在Connect命令中携带pageUrl字段,如下图:

如果设置rtmp_pageurl参数,则会发现Object中多了一项,如下:

ffmpeg -rtmp_pageurl "http://www.chinaffmpeg.com" -i rtmp://publish.chinaffmpeg.com/live/class

此外,rtmp_swfurl、rtmp_tcurl参数与rtmp_pageurl类似。

上一篇下一篇

猜你喜欢

热点阅读