Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate an RTMP test stream using ffmpeg command?

I would like to test my streaming infrastructure by generating an RTMP test video with a timestamp. This could look like that screen. The image doesn't matter. I'm after the working stream generated on-the-fly and timestamp only. I intend to use the ffmpeg tool for that purpose. The command could look something like

$ ffmpeg -i image.png \
    -vf drawtext="fontfile=/Library/Fonts/Arial.ttf: \
        timecode='00\:00\:00\:00': r=1: fontcolor=white: \
        fontsize=24: box=1: [email protected]: \
        boxborderw=5: x=(w-text_w)/2: y=(h-text_h)/2" \
    -f flv rtmp://localhost/live/test

I do run locally a streaming server based on NGINX and its RTMP module.

However, the above command gives me the following error:

Input #0, png_pipe, from 'image.png':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: png, rgb24(pc), 768x576 [SAR 7874:7874 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> flv1 (flv))
Press [q] to stop, [?] for help
[Parsed_drawtext_0 @ 0x7fb78450ece0] Using non-standard frame rate 1/1
Output #0, flv, to 'rtmp://localhost/live/test':
  Metadata:
    encoder         : Lavf57.71.100
    Stream #0:0: Video: flv1 (flv) ([2][0][0][0] / 0x0002), yuv420p, 768x576 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.89.100 flv
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
[flv @ 0x7fb785812a00] Failed to update header with correct duration.
[flv @ 0x7fb785812a00] Failed to update header with correct filesize.
frame=    1 fps=0.0 q=8.6 Lsize=      50kB time=00:00:00.00 bitrate=406016.0kbits/s speed=0.019x
video:49kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.451271%

The streaming server operates as expected. The problem is with the command. Would anyone be able to help me?

like image 458
Daniel Stefaniuk Avatar asked Jun 12 '17 19:06

Daniel Stefaniuk


People also ask

How do I Restream with FFmpeg?

To re-stream using FFmpeg, use the -re option when encoding the video file for Wowza Streaming Engine™ media server software. The -re option instructs the encoder to read the source at its native frame rate.


1 Answers

ffmpeg has testsrc you can use as a test source input stream:

ffmpeg -r 30 -f lavfi -i testsrc -vf scale=1280:960 -vcodec libx264 -profile:v baseline -pix_fmt yuv420p -f flv rtmp://localhost/live/test

-r, scaling, profile, etc are just an example and can be ommited/played with. The point is using -i testsrc

like image 130
Chen Fisher Avatar answered Sep 19 '22 14:09

Chen Fisher