How to Process Buffer Data and Send it to RTMP using ffmpeg

Abstract: Resolve low-latency RTMP streaming by piping raw or encoded video buffers directly into ffmpeg via stdin without intermediate file storage.

Created: 2026-09-15 by

Processing buffer data and sending it to RTMP with ffmpeg requires piping raw video frames or encoded packets into the standard input stream while configuring the output to accept network transmission. By utilizing the pipe protocol and appropriate container formats, you can achieve low-latency streaming from custom applications directly to an RTMP server without intermediate file storage.

Understanding the Data Flow

When working with buffer data, you are typically dealing with raw uncompressed video frames (such as YUV420P) or already encoded bitstreams (like H.264/AVC). The goal is to feed this continuous stream of bytes into ffmpeg so that it can encapsulate the data into a format suitable for Real-Time Messaging Protocol (RTMP) delivery. This approach is common in media servers, custom video processing pipelines, and IoT devices where memory efficiency is critical. The core mechanism relies on the ability of ffmpeg to read from standard input (stdin). Instead of specifying an input file path like /path/to/video.mp4, you use the special URL scheme pipe:0. This tells the encoder to expect a stream of data coming from the parent process. It is crucial to understand that RTMP expects specific codec parameters; if you send raw frames, ffmpeg must encode them on the fly. If you send pre-encoded packets, you may need to demux them correctly before re-encapsulation.

Encoding Raw Frames for RTMP

The most common scenario involves receiving raw video frames in memory and pushing them to a live stream. In this case, you must define the pixel format, resolution, and frame rate explicitly because the input stream contains no header information. The command structure uses -f rawvideo to specify the input format and -pix_fmt yuv420p to ensure compatibility with most RTMP servers. For example, if your application produces 1920x1080 frames at 30 frames per second, the command would look like this:
ffmpeg -f rawvideo -vcodec rawvideo -s 1920x1080 -r 30 -i pipe:0 -c:v libx264 -preset ultrafast -f flv rtmp://server/app/stream_key
Here, -c:v libx264 instructs ffmpeg to compress the raw frames using the H.264 codec. The -preset ultrafast option is vital for real-time buffering because it minimizes encoding latency, which is essential when dealing with live data streams. The output format -f flv is required because RTMP traditionally uses the FLV container structure. If you are also handling audio, you must include the audio stream parameters similarly. For instance, adding AAC audio might involve:
ffmpeg -f rawvideo -s 1920x1080 -r 30 -i pipe:0 -f s16le -ar 44100 -ac 2 -i pipe:1 -c:v libx264 -preset ultrafast -c:a aac -b:a 128k -f flv rtmp://server/app/stream_key
This command reads video from pipe:0 and audio from pipe:1, synchronizing them before sending to the RTMP endpoint. Note that managing multiple pipes requires careful synchronization in your host application to prevent drift between audio and video buffers.

Handling Pre-Encoded Bitstreams

Sometimes, your buffer data consists of already encoded H.264 NAL units rather than raw pixels. In this case, you should avoid re-encoding to save CPU cycles. Instead, use the copy codec flag to pass the data through unchanged. However, RTMP still requires a proper container, so you must mux the raw bitstream into an FLV container.
ffmpeg -f h264 -i pipe:0 -c:v copy -f flv rtmp://server/app/stream_key
Using -f h264 tells ffmpeg that the incoming stream is a raw H.264 elementary stream. The -c:v copy flag ensures no decoding or encoding occurs, reducing latency significantly. This method is ideal for high-performance environments where the upstream application handles all compression logic. It is important to note that raw H.264 streams lack timing information. You may need to provide frame rate hints using -r 30 if the stream appears stuttered. Additionally, ensure that your buffer data includes proper start codes for each NAL unit, as missing delimiters can cause parsing errors in the muxer.

Optimizing Latency and Stability

Low latency is often the primary concern when streaming buffer data. Several flags can help tune the performance. The -tune zerolatency option in libx264 disables B-frames and forces immediate output of GOPs, which reduces delay. Combining this with -preset ultrafast creates a highly responsive pipeline. Buffer management in your host application is equally important. Ensure that you write data to the pipe in chunks that match the expected packet size of the RTMP protocol. Writing too much data at once can overwhelm the internal buffers, causing drops, while writing too little can lead to underflow. Monitoring the return status of the write operations helps detect connection issues early. For more advanced filtering, such as scaling or color space conversion, you can insert filters between the input and output. See How to use ffplay with -bsf? for insights into bitstream filters that can preprocess data before muxing. This is useful if you need to correct timestamps or adjust metadata dynamically.

Troubleshooting Common Issues

One frequent issue is the "Invalid data found" error. This usually means the input format does not match the actual data. Verify that -f rawvideo matches your pixel layout and that -pix_fmt is correct. Another common problem is audio-video desynchronization. Use -fflags +genpts to force ffmpeg to generate presentation timestamps if they are missing from the source. If the stream disconnects frequently, check the network stability and consider increasing the buffer size with -bufsize. Also, ensure that the RTMP server supports the specific profile and level of the H.264 stream you are sending. Compatibility issues between the encoder settings and server expectations can cause silent failures. For related troubleshooting on timestamp issues, refer to Fixing the 'ffmpeg -itsoffset is not working' Issue, as similar principles apply when manipulating time-based data in streams.

Frequently Asked Questions

Can I stream raw audio only to RTMP?

Yes, you can stream raw audio by specifying -f s16le or -f f32le depending on your sample format. You must also set the sample rate with -ar and channel count with -ac before encoding with -c:a aac.

Why is my RTMP stream experiencing high latency?

High latency is often caused by heavy encoding presets or the use of B-frames. Switching to -preset ultrafast and -tune zerolatency removes these delays. Additionally, ensuring your buffer writes are consistent prevents queuing delays in the pipeline.

Do I need to handle timestamps manually?

For raw video inputs, ffmpeg generates timestamps based on the frame rate you provide. However, for pre-encoded bitstreams, timestamps may be missing. Using -fflags +genpts helps automatically generate these timestamps to maintain synchronization.

What happens if the pipe closes unexpectedly?

If the parent process closes the pipe, ffmpeg will stop and exit with an error code. Your application should monitor the ffmpeg process status and reconnect or restart the stream if necessary to maintain service continuity.

Is it possible to add subtitles to the RTMP stream?

Standard RTMP does not support embedded subtitles in the same way HLS does. You would need to burn subtitles into the video stream using -vf subtitles or overlay text graphics, as RTMP primarily transmits audio and video tracks.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More