FFmpeg is a powerful video stream processing tool; basic transcoding operations go without saying. I think most people get to know it through its omnipotent format conversion.
If you have a Bilibili live account, you can try the commands below. If you want to push to Longzhu or Huya,
you’re welcome to explore FFmpeg‘s commands — I’ll add a link on the blog for you.
If you really want to live stream, just use OBS; here’s a simple tutorial.
Pushing to Bilibili with FFmpeg
Actually I referred to this fellow’s configuration: The posture of live streaming on Bilibili with FFmpeg
1 | # The address at the end is the RTMP address + stream key |
The command above pushes a video to the live room. Going through the whole command would bore you, so I’ll pick a few key
parameters (actually I hadn’t used FFmpeg before; I really don’t want to learn the rest for now — if there are problems please
point them out directly in the comments).
| Parameter | Some meaning |
|---|---|
| -re | Slow down the reading speed. Without this parameter, pushing video reaches 100~200 fps — the server can’t keep up. |
| -i; -vf | Specify the video and subtitles. |
| -c:v libx264 | I don’t know why x264 encoding is a must — maybe it’s just needed |
| -flv | Bilibili only accepts flv-format streams |
Raspberry Pi Pushing
Many of you have little things like Raspberry Pis; you can totally push directly from a Pi. Anyway, for Linux,
FFmpeg has almost become default software. Post your live address and let’s all watch together.
FFmpeg Screen Recording and Testing
After RTMP pushing, a bit of screen recording and testing:
1 | ffmpeg \ |
The command above records the screen content into output.mp4.
Note: because I’m a Linux user, I use
-f x11grabhere. If you’re a Windows user, use-f gdigrab;Macusers, explore on your own.
The command above is enough for recording, but if we just want to view the video, we don’t necessarily need it to generate a file — and generated files have to be deleted afterwards.
Achieving Quick Preview
At this point, if you have the concept of streams, you should know that video is also a stream. The operation just now simply directed the
video stream into the file output.mp4. So we can play the video stream directly with a player,
which leads naturally to the command below: generate no file, and use stdout directly as the intermediate stream.
1 | ffmpeg \ |
The - in the command outputs the video stream to stdout; mpv - means reading the video stream from stdout
(vlc - also works).
So you can directly use a local player to view and test FFmpeg‘s output.
Finally, here’s my live address. When I stream Oxygen Not Included, everyone’s welcome to watch — haha, seems this is the real point: