FFmpeg transcode MP4 to RTSP result in Non-monotonous DTS

Abstract: Resolve FFmpeg Non-monotonous DTS errors when transcoding MP4 to RTSP by forcing constant frame rate and removing B-frames.

Created: 2026-08-19 by
The "Non-monotonous DTS" error occurs when FFmpeg detects that timestamp deltas are not strictly increasing, often due to variable frame rates or B-frames in the source MP4. To resolve this during RTSP transcoding, you must enforce a constant frame rate using the -r flag and remove B-frames with -bf 0. These adjustments ensure the output stream has predictable timing, allowing RTSP clients to decode the video without buffer underflow or synchronization errors.

Understanding Non-Monotonous DTS

DTS stands for Decode Time Stamp. In a valid video stream, these timestamps must be monotonically increasing, meaning each subsequent frame's DTS must be greater than or equal to the previous one. When FFmpeg encounters a situation where the calculated DTS decreases or jumps unpredictably, it halts processing to prevent downstream players from desynchronizing audio and video.

This issue is particularly common when converting container formats like MP4 to streaming protocols like RTSP. The source MP4 file may contain Variable Frame Rate (VFR) content, such as screen recordings or certain camera feeds, where the time between frames varies. Additionally, modern codecs often use B-frames (Bidirectional frames) which reference both past and future frames, complicating the DTS ordering. RTSP servers expect a steady, linear stream of data, making them sensitive to these irregularities.

Why MP4 Files Cause This Issue

MP4 files are highly flexible containers that can store video with complex temporal structures. Unlike raw streams, they allow for:

  • Variable Frame Rates: Frames are not spaced evenly in time.
  • B-Frames: These frames are displayed out of order relative to their decoding order, requiring careful rearrangement of timestamps.
  • Keyframe Intervals: Irregular keyframe placement can disrupt the stream structure if not handled correctly by the encoder.

When FFmpeg reads these complex structures, it attempts to map them to a linear timeline. If the mapping logic fails to account for all edge cases in the source file, it produces non-monotonic DTS values, triggering the error.

Solution 1: Force Constant Frame Rate

The most effective way to fix non-monotonous DTS is to force FFmpeg to output a Constant Frame Rate (CFR). This ensures that every frame is spaced exactly at the same interval, eliminating timing jitter. You can achieve this by adding the -r flag followed by the desired frame rate (e.g., 30 or 60).

ffmpeg -i input.mp4 -c:v libx264 -r 30 -f rtsp rtsp://localhost:8554/stream

In this command, -r 30 tells FFmpeg to output 30 frames per second consistently. If the source has a different frame rate, FFmpeg will either drop duplicate frames or repeat frames to maintain the 30fps rhythm. This regularization of time intervals resolves the DTS calculation errors because the decoder knows exactly when each frame should arrive.

Solution 2: Remove B-Frames

B-frames are another major contributor to DTS issues. They require the decoder to have access to future frames before displaying the current one, which creates complex dependency chains. RTSP streaming benefits from simpler prediction modes. You can disable B-frames by adding -bf 0 to your FFmpeg command.

ffmpeg -i input.mp4 -c:v libx264 -bf 0 -f rtsp rtsp://localhost:8554/stream

By setting -bf 0, you instruct the H.264 encoder to only use I-frames (Intra) and P-frames (Predictive). This simplifies the decoding process significantly. While it may slightly increase bitrate due to reduced compression efficiency, it guarantees a linear DTS flow. This method is especially useful for live streaming scenarios where low latency and stability are prioritized over maximum compression.

Solution 3: Use Muxing Options for RTSP

RTSP has specific requirements for how data is packaged. Using appropriate muxer options can help FFmpeg manage timestamps more effectively. The -fflags +genpts option forces FFmpeg to generate new PTS/DTS values based on the packet duration, rather than relying on the source file's potentially flawed timestamps. Combine this with -movflags +frag_keyframe if you are using fragmented MP4 containers, though for standard RTSP, simple muxing flags often suffice.

ffmpeg -i input.mp4 -c:v libx264 -r 30 -bf 0 -fflags +genpts -f rtsp rtsp://localhost:8554/stream

This comprehensive approach addresses multiple potential causes simultaneously. It forces a constant frame rate, removes complex B-frames, and regenerates timestamps from scratch. This combination is robust against various types of source file anomalies.

Related Streaming Considerations

When troubleshooting RTSP streams, it is important to consider the entire pipeline. For instance, if you are converting other formats like HEVC, similar timestamp issues may arise. See How to Convert HEVC MP4 to HLS Stream with ffmpeg for insights into handling complex codec timestamps. Additionally, audio synchronization is critical; if your audio track also experiences playback issues after fixing the video DTS, refer to Fixing AAC Audio Tracks That Won't Play After FFmpeg Transcode to ensure both tracks remain aligned.

If you are integrating this stream into a web application, you might encounter client-side buffering errors. Check Streaming RTSP URL Video Using Node.js: Troubleshooting FFmpeg Errors for debugging strategies related to network delivery and player compatibility.

Frequently Asked Questions

Why does my RTSP stream freeze after starting?

Freezing usually indicates that the client cannot keep up with the incoming data rate or that timestamps are misaligned. Ensure you are using a constant frame rate (-r) and check your network bandwidth. If the bitrate is too high, reduce it with -b:v.

Can I use H.265 (HEVC) instead of H.264 for RTSP?

Yes, but many older RTSP clients and hardware decoders do not support HEVC. H.264 remains the standard for broad compatibility. If you must use HEVC, ensure your client supports it and apply the same DTS fixes.

Does removing B-frames affect video quality?

Removing B-frames can slightly reduce compression efficiency, leading to a larger file size or higher bitrate for the same visual quality. However, for real-time streaming, the trade-off is often worth it for the increased stability and lower latency.

What if the source video has no audio?

If the source lacks audio, FFmpeg might still try to create an empty audio stream, which can cause sync issues. Use -an to explicitly disable audio encoding if you only need video, preventing unnecessary timestamp calculations for missing audio packets.

How do I verify the DTS values in the output?

You can use ffprobe to inspect the stream properties. Run ffprobe -show_packets output.ts to view individual packet timestamps. Look for any negative delta values or decreasing sequences, which indicate persistent DTS problems.

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