How to generate an RTMP test stream using ffmpeg command?
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
Daniel Stefaniuk
Updated on June 29, 2020Comments
-
Daniel Stefaniuk almost 4 years
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?
-
llogan almost 7 yearsI doubt the
-r 30
is doing anything, and your example is upscaling the original testsrc size of 320x240. You can set frame rate and video size in testsrc itself:testsrc=r=30:s=1280x960
. Consider adding-re
input option to simulate a live input stream: otherwise it will attempt to encode as fast as possible. -
Dave Stein over 5 years
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p test.mp4
works for me. I subtracted that extra-if
before the address of your example. Adding that failed. Going back to RTMP land I tried this:ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -f flv rtmp://mylocation
I get the error:rtmp://mylocation: Input/output error
. Any idea? -
Dave Stein over 5 years
-
TurtleTread over 4 yearsumm...why does the number in the stream continue to grow when I stop running this command in the terminal? the browser player does detect the stop signal it seems but continue to get stream?