Many people may not be familiar with the TS file format, as it is not as popular as the MP4 format. TS is often found in M3U8 video files, a format widely used in online video playback and live streaming, and serves as the carrier for a series of small video fragments. If you are looking to transcode, distribute, and host TS videos, you might want to consider our services.
To help you better understand TS videos, this article will provide detailed information about the origin of the TS video format, its applications, how to open it, and how to edit and convert it.
A TS file, short for Transport Stream, is a type of video file format used for storing, transmitting, and playing digital video and audio streams. TS is an encapsulated format, also known as MPEG2-TS. MPEG2-TS is a standard data container format for transmitting and storing audio and video, as well as program and system information protocol data. It is mainly used in digital broadcasting systems, such as DVB, ATSC, and IPTV. The transport stream was originally designed for broadcasting. Later, by adding a 4-byte time code (TC) to the standard 188-byte data packet, making it a 192-byte data packet, it was adapted for use with digital cameras, video recorders, and players.
MPEG2 is a multimedia transmission and multiplexing technology that can provide hundreds of program channels in digital TV broadcasting. Multiplexing means that multiple layers of programs can be transmitted simultaneously. In the MPEG-2 standard, there are two different types of bitstreams output to the channel: one is the program stream (PS), which is suitable for scenarios without transmission errors, and the other is the transport stream (TS), which is suitable for scenarios with channel noise.
The program stream is used for stable and reliable media, such as optical discs (e.g. DVD/CD), while the transport stream is used for unstable transmission, such as terrestrial or satellite broadcasting. In addition, the transport stream can transmit multiple programs, and they do not have a hierarchical relationship. Logically, they are all composed of PES (Packetized Elementary Stream) packets, so they can be easily converted between each other.
TS videos (streams) can be divided into three layers: the TS layer (Transport Stream), the PES layer (Packetized Elementary Stream), and the ES layer (Elementary Stream).
The ES layer contains the audio and video data, the PES layer adds information about the data frames, such as time stamps, to the audio and video data, and the TS layer adds necessary information for data stream identification and transmission to the PES layer. A TS video (stream) is composed of multiple TS packets.
The size of a TS packet is fixed at 188 bytes. The TS layer is divided into three parts: TS header, Adaptation Field, and Payload. The TS header is fixed at 4 bytes. The Adaptation Field may or may not exist and is mainly used to fill in data that is less than 188 bytes. The Payload contains the PES data.
TS packet header provides information about the transmission.
The length of the TS packet header is not fixed. The first 4 bytes are fixed, and there may be an adaptation field following the header. The 4 bytes are the minimum header length.
The structure fields of the packet header are as follows:
The length of the Adaptation Field should include one byte for the Transport Error Indicator flag.
PCR (Program Clock Reference) is a program clock reference. PCR, DTS, and PTS are all sampling values of the same system clock. PCR is incremental, so it can be set to the DTS value, and the audio data does not need PCR.
When packing the TS stream, the PAT and PMT tables do not have an Adaptation Field. If the length is insufficient, it can be filled with 0xff.
Both the video stream and audio stream require an adaptation field, which is usually added to the first and last TS packets of a frame, but not added to the middle TS packets.
The information transmitted in the Payload of a TS packet includes two types: PES packets for video and audio, as well as auxiliary data, Program Specific Information (PSI).
TS packets can also be empty packets. Empty packets are used to fill the TS stream and may be inserted or deleted during demultiplexing.
The ES streams of video and audio need to be packaged into PES streams. Auxiliary data (such as teletext information) does not need to be packaged into PES packets.
The PES layer adds information such as time stamps to each video/audio frame. The content of a PES packet can be complex, but the most commonly used fields are:
PTS (Presentation Time Stamp) is used for display timing, while DTS (Decoding Time Stamp) is used for decoding timing.
Both video and audio data require both PTS and DTS timestamps. However, for audio data, PTS and DTS are the same, so only PTS is required.
PTS and DTS are both used for B-frames. For I-frames and P-frames, PTS is equal to DTS. If a video stream does not contain B-frames, then PTS will always be equal to DTS.
When reading video frames from a file, the order of the frames is the same as the order of the DTS timestamps. The DTS algorithm is relatively simple, with an initial value plus an increment. The PTS calculation is more complex and requires an offset added to the DTS.
For audio PES, only PTS (same as DTS) is required, while for video I-frames and P-frames, both PTS and DTS timestamps are required. For video B-frames, only PTS (same as DTS) is required.
The ES layer refers to the elementary stream layer, which contains the raw audio and video data.
In general, video is encoded in H.264 format, while audio is encoded in AAC format.
As a type of container file format, the TS videos have a wide range of applications, including:
1. Broadcasting and television: TS videos are commonly used in broadcasting systems such as DVB and ATSC. The format has error correction and stream synchronization functions, which can maintain transmission integrity when the signal is degraded. The most classic application of TS streams is in digital high-definition television that we use in our daily lives.
2. Real-time streaming media: Apple's HTTP Live Streaming media is based on TS files. In live broadcasting, video streams are sliced or segmented into file fragments for transmission, or played sequentially through given TS file addresses.
3. Blu-ray discs / Full HD videos: As a container format, TS can encapsulate MPEG-2 or VC-1 encodings, and is also a commonly used container format for Blu-ray discs and Full HD videos. Therefore, videos in the TS format usually have high video quality, large file size, and accurate restoration, making it a favorite format among high-definition enthusiasts.
4. Digital cameras: To be used in digital cameras, the TS format grouping has an added 4-byte time code. In addition, with the help of time codes, it can be used to synchronize content shot by multiple cameras.
The TS video format is used for several reasons:
Several programs support TS Videos:
Furthermore, we provide a free online M3U8 Player that supports WebRTC, FLV, and HLS live streaming, as well as on-demand playback in HLS, DASH, FLV, and MP4 formats for your convenience. Feel free to use it.
Some TS videos may require additional codecs to play properly. If you encounter any issues playing a TS file, you may need to install additional codecs or use a different media player.
Downloading TS (Transport Stream) files, which are often used in streaming protocols like HLS (HTTP Live Streaming), involves fetching the individual TS segments and optionally combining them into a single video file. Here are several methods to download TS files:
FFmpeg is a powerful multimedia framework that can handle various video and audio formats, including TS files.
brew install ffmpeg
.sudo apt-get install ffmpeg
for Debian-based systems.Open a terminal or command prompt and run the following command:
ffmpeg -i "http://example.com/path/to/playlist.m3u8" -c copy output.mp4
Replace http://example.com/path/to/playlist.m3u8
with the URL of the M3U8 file that references the TS segments, and output.mp4
with your desired output file name.
There are several browser extensions available that can help you download TS files directly from your web browser.
There are command-line tools specifically designed for downloading TS files.
youtube-dl: A popular command-line program that can download videos from various websites, including those using M3U8 and TS files. Follow the instructions on the official website to install youtube-dl.
Open a terminal or command prompt and run the following command:
youtube-dl "http://example.com/path/to/playlist.m3u8"
Replace http://example.com/path/to/playlist.m3u8
with the URL of the M3U8 file.
If you have direct URLs to the TS files, you can download them manually and combine them.
Use a download manager or your browser to download each TS file individually.
Use FFmpeg to combine the downloaded TS files into a single video file. Create a text file (e.g., filelist.txt
) with the following content:
file 'segment1.ts'
file 'segment2.ts'
file 'segment3.ts'
...
Then run the following command:
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4
Replace filelist.txt
with the name of your text file and output.mp4
with your desired output file name.
By following these methods, you can download TS files and optionally combine them into a single video file on your computer.
If you want to play TS video files on your mobile or other portable media player, the best way is to convert them to a more accessible format, such as MP4. While both TS and MP4 formats are used for storing video files and streaming media, they are vastly different in their applicable areas. TS is more suitable for professional streaming media playback, while MP4 is an excellent choice for storing and watching videos on computers and mobile devices. If you want to play TS video files on a mobile device, it's best to convert them to MP4 format for easier access and playback.
Below is a table explaining the salient difference between TS and MP4.
To convert TS to MP4, you can use video converter software. There are many video converter software available, such as HandBrake, Freemake Video Converter, Any Video Converter, and Wondershare UniConverter. The steps to convert TS to MP4 may vary slightly depending on the software you use.
In conclusion, the TS (Transport Stream) format plays a crucial role in the world of digital video broadcasting and streaming. If you have more extensive needs related to video asset management, such as swift uploading, transcoding, storage, and accelerated playback, EdgeOne VOD is the perfect solution.
Tencent EdgeOne VOD (Video on Demand) offers comprehensive VPaaS (Video Platform as a Service) solutions, including cloud video storage, video transcoding, and video playback acceleration, cater to audio/video capture, upload, storage, automated transcoding, accelerated playback, media asset management, and audio/video communications. VOD enables swift and flexible delivery of high-quality videos, allowing you to concentrate on your business, choose services as needed, and adapt to market changes with agility. On the demo page, you can conveniently experience the EdgeOne video services firsthand.
We have now launched a free trial, click here or contact us for more information. And feel free to begin your journey with us.
1. What is a TS file?
A TS (Transport Stream) file is a standard format for transmitting audio, video, and data over digital broadcast systems such as DVB, ATSC, and IPTV. It is commonly used for streaming and broadcasting purposes.
2. What are the common uses of TS files?
TS files are primarily used for:
3. How can I open a TS file?
You can open TS files with various media players that support the format, such as:
4. How do I convert a TS file to another format?
You can use video conversion software to convert TS files to other formats like MP4, AVI, or MKV. Popular tools include:
ffmpeg -i input.ts -c:v libx264 -c:a aac output.mp4
5. Why are TS files used in streaming?
TS files are used in streaming because they are designed to handle errors and packet loss, making them suitable for unreliable networks. They also support real-time data transmission, which is essential for live streaming.
6. What is the difference between TS and MP4?
7. Can I edit TS files?
Yes, you can edit TS files using video editing software that supports the format, such as:
8. How do I merge multiple TS files?
You can merge multiple TS files using FFmpeg. Create a text file (e.g., filelist.txt
) with the following content:
file 'segment1.ts'
file 'segment2.ts'
file 'segment3.ts'
...
Then run the following command:
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.ts
Replace filelist.txt
with the name of your text file and output.ts
with your desired output file name.
9. Are TS files compressed?
TS files can contain compressed video and audio streams, but the TS format itself is not a compression format. It is a container that can hold various types of compressed data.
10. What is the file extension for TS files?
The file extension for Transport Stream files is .ts
.
11. How do I play TS files on my TV?
You can play TS files on your TV by:
12. What is the difference between TS and M2TS?
13. Can I stream TS files over the internet?
Yes, TS files are commonly used for streaming over the internet, especially with protocols like HLS (HTTP Live Streaming).
14. What is the structure of a TS file?
A TS file consists of packets, each typically 188 bytes in size. These packets contain headers and payloads, which include video, audio, and data streams.
15. How do I troubleshoot playback issues with TS files?