Fixing Sync Issues: tsDemux vs Other TS Demuxing Tools

Written by

in

The term tsdemux refers to two major technical implementations used to demux MPEG Transport Stream (.ts) files: a built-in multi-media element inside the GStreamer framework, and standard standalone demuxing libraries like the C/C++ frejoel/tsdemux GitHub repository. Demuxing separates a singular .ts file into its raw independent component parts, such as separating combined audio, video, or data telemetry (like KLV metadata) into distinct files.

A step-by-step technical guide explains how to execute demuxing via GStreamer’s command-line interface (gst-launch-1.0) and how to read basic code implementations. Step 1: Install the Environment

Before demuxing, you must have the appropriate binaries installed. For the command line or framework wrapper, download the core library.

On Linux (Ubuntu/Debian): Run sudo apt-get install gstreamer1.0-plugins-bad (The tsdemux element resides inside the “Bad” plugins package).

On Windows/macOS: Download the official installers from the GStreamer Download Page. Step 2: Analyze the Target TS File

MPEG-TS files frequently encapsulate multiple audio languages or subtitle tracks. To verify the exact structure (known as “pads” in programming), check the streams by running: gst-discoverer-1.0 your_file.ts Use code with caution.

This lists the streams (e.g., video_0, audio_0) so you know what outputs to expect. Step 3: Run the Demuxing Pipeline

Because tsdemux dynamically generates output pads depending on what it finds inside the stream, a standard media pipeline maps the container components to output files. Use the following template in your terminal:

gst-launch-1.0 filesrc location=“input.ts” ! tsdemux name=demuxdemux.video_0 ! queue ! h264parse ! filesink location=“output_video.h264” demux.audio_0 ! queue ! aacparse ! filesink location=“output_audio.aac” Use code with caution. filesrc: Feeds your raw .ts video into the pipeline.

tsdemux name=demux: Names the parsing element so you can reference its separated branches.

demux.video_0 & demux.audio_0: Represents the isolated tracks detected by the software.

parse & filesink: Correctly formats the underlying stream elements and dumps them into your output file paths. Step 4: Demuxing Synchronized Meta/KLV Data (Advanced)

If you are processing drone, military, or mapping footage containing KLV (Key-Length-Value) metadata, use a multiplexed queue to extract text data flawlessly alongside your video:

gst-launch-1.0 filesrc location=“geodata.ts” ! tsdemux name=demux demux. ! multiqueue name=mq mq. ! decodebin ! x264enc ! mp4mux ! filesink location=“clean_video.mp4” mq. ! meta/x-klv ! filesink location=“telemetry.txt” Use code with caution.

(Note: Utilizing a multiqueue ensures that if one data stream completes faster than another, your computer does not drop frames or encounter lag errors). Basic Programmatic Structure (C++ / Rust)

If you prefer building a custom application rather than relying on command line text strings, your source file needs to create the element factories and register a callback listener for pad-added. Because elements inside a .ts file are multiplexed, the application cannot link audio/video streams until tsdemux actually parses the data header. A standard setup mirrors this structural pattern:

Initialize the system elements using ElementFactory::make(“tsdemux”). Add elements into a core operational pipeline graph. Register a callback signal listener for pad-added.

Inside the callback function, check the caps runtime type (e.g., video/x-h264 vs audio/mpeg) to dynamically link the stream to your saving function.

Are you planning to demux standard television captures, or are you working with specialized metadata / telemetry streams? Let me know your workflow, and I can give you the exact terminal command or programming code snippet you need. gstreamer-tsdemux is not discovering all streams

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *