Format Conversion

Complete technical guide for FlowPick format conversion — TS/MP4 remuxing principles, FFmpeg WASM workflow, output format selection, and performance comparison.

FlowPick can merge fragments and convert to standard formats while downloading streaming media. This document explains supported conversion paths, underlying technical principles, output format selection, and performance characteristics.


Prerequisite Concepts: Container vs Codec

Before understanding format conversion, need to distinguish two easily confused concepts:

ConceptDescriptionAnalogy
ContainerFile's "shell", determines file extension and internal data organizationShipping box — determines package shape
CodecCompression algorithm for audio/video dataContents inside the box

FlowPick's format conversion only changes the container, not the codec (i.e., "remuxing"). This means:

  • Video quality and audio quality remain completely unchanged
  • Conversion is very fast (no re-encoding involved)
  • Cannot change codec formats (e.g., H.265 → H.264)
If you need to change codec formats (e.g., compress video, convert codec), use native FFmpeg command-line tool. See Command Line Alternatives.

Conversion Path Overview

FlowPick supports following conversion paths, covering both HLS and DASH mainstream streaming protocols:

Source FormatTarget FormatConversion MethodSpeedQualityTypical Use Case
HLS (TS fragments)MP4FFmpeg WASM RemuxingMediumLosslessUniversal playback, video editing
HLS (TS fragments)TSBinary Direct ConcatenationExtremely FastLosslessMaximum speed, post-processing
DASH (MP4 fragments)MP4FFmpeg WASM RemuxingMediumLosslessUniversal playback
DASH (FMP4 fragments)MP4FFmpeg WASM ReassemblyMediumLosslessRequires init segment
DASH (separate audio/video)MP4FFmpeg WASM MergeSlowerLosslessDASH separate audio/video streams

"Lossless" means no re-encoding is performed; only container format is changed. Video and audio encoded data remain unchanged.


Technical Principles of Conversion

FlowPick uses two conversion engines, automatically selecting optimal solution based on scenario:

EngineApplicable ScenarioAdvantagesDisadvantages
FFmpeg WASMTS→MP4 remuxing, DASH merging, audio-video mergeFull functionality, supports complex conversionsNeeds to load WASM file, higher memory usage
TSToMP4MuxerTS→MP4 streaming remuxingPure JS implementation, no need to load FFmpeg, high memory efficiencyOnly supports single TS→MP4 scenario

TS Fragments → MP4 (FFmpeg WASM Remuxing)

HLS streams typically use MPEG-TS container. When converting to MP4, FlowPick uses FFmpeg WASM to perform following operations:

Input: Multiple .ts fragment files

Processing Flow:

  1. Write all TS fragments into FFmpeg virtual file system (WASM memory)
  2. Generate concat file list (filelist.txt)
  3. Execute remuxing command:
ffmpeg -f concat -safe 0 -i filelist.txt \
  -c copy \
  -movflags +faststart \
  -bsf:a aac_adtstoasc \
  output.mp4

Key Parameter Explanation:

ParameterFunctionWhy Needed
-f concatUse concat demuxer to concatenate fragmentsTS fragments cannot be directly merged, need demuxer processing
-safe 0Allow arbitrary file pathsWASM virtual file system has special path format
-c copyStream copy mode, no re-encodingEnsures lossless conversion, fastest speed
-movflags +faststartMove moov atom to beginning of fileSupports network progressive playback, watch while downloading
-bsf:a aac_adtstoascAAC audio format conversionTS uses ADTS format, MP4 needs ASC format

Performance Characteristics:

  • No encoding/decoding involved, low CPU usage
  • Main time cost is in file I/O (WASM virtual file system read/write)
  • Processing speed approximately 50-100 MB/s (depends on CPU and fragment count)

TS Fragments → MP4 (TSToMP4Muxer Streaming Remuxing)

For large file scenarios, FlowPick prioritizes using proprietary TSToMP4Muxer for streaming remuxing, avoiding FFmpeg WASM memory limitations:

Processing Flow:

  1. Parse TS packets one by one (188 bytes/packet), extract PES data
  2. Convert to MP4 format media data in real-time
  3. Stream write to disk via Streams API (FSA) or memory (Blob)

Advantages:

  • Pure JavaScript implementation, no need to load FFmpeg WASM (saves ~30MB memory)
  • Streaming processing, memory usage independent of file size
  • Supports File System Access API for direct disk writing

Disadvantages:

  • Only supports single TS→MP4 conversion path
  • Does not support separate audio-video merging
TSToMP4Muxer is one of FlowPick's core innovations. It makes processing GB-scale video files possible in the browser without triggering memory overflow. See Download Engine for details.

TS Fragments → TS (Direct Concatenation)

This is the fastest "conversion" method — actually performs no conversion at all, only binary concatenation of TS fragments in order.

Processing Flow:

  1. Download all TS fragments to memory
  2. Concatenate ArrayBuffers sequentially into single Uint8Array
  3. Write directly to file

Advantages:

  • Zero CPU overhead, speed limited only by disk write speed
  • Completely faithful, does not modify any bytes
  • Suitable for subsequent processing with professional tools

Disadvantages:

  • File size may be slightly larger than MP4 (TS container overhead ~5-15%)
  • Some players have poorer support for TS files than MP4

DASH Fragments → MP4

DASH stream fragments are usually MP4 or FMP4 format. Conversion process:

Standard MP4 fragments:

ffmpeg -f concat -safe 0 -i filelist.txt \
  -c copy \
  -movflags +faststart \
  output.mp4

FMP4 fragments (requires init segment):

ffmpeg -i init.mp4 -i video.mp4 -i audio.mp4 \
  -c:v copy -c:a copy \
  -movflags +faststart \
  output.mp4

Audio-Video Separate Merge

DASH streams' video and audio are usually in different AdaptationSets. Merging process:

ffmpeg -f concat -safe 0 -i video_list.txt \
  -f concat -safe 0 -i audio_list.txt \
  -c:v copy -c:a copy \
  -movflags +faststart \
  -bsf:a aac_adtstoasc \
  output.mp4
DASH separate audio-video is an important feature of DASH protocol, allowing platforms to provide independent bitrate options for video and audio. FlowPick auto-detects and merges separate audio-video tracks. See Video Sniffing — DASH Streams for details.

Output Format Selection Guide

Use Cases:

  • Need to play on various players and devices
  • Need to import into video editing software (Premiere, DaVinci Resolve, etc.)
  • Need to upload to video platforms (YouTube, Bilibili, etc.)
  • Need to ensure maximum compatibility

Technical Details:

  • Container: MPEG-4 Part 14
  • MIME Type: video/mp4
  • Supports H.264/AVC, H.265/HEVC, AAC, MP3 etc. codecs
  • faststart flag ensures network progressive playback

TS

Use Cases:

  • Pursue fastest download speed (skip remuxing step)
  • Will further process with professional tools (e.g., FFmpeg CLI) later
  • Source stream itself is TS format and doesn't need conversion
  • Temporary storage, may delete later

Technical Details:

  • Container: MPEG Transport Stream
  • MIME Type: video/mp2t
  • Each fragment independently playable
  • File size typically 5-15% larger than MP4

Format Selection Decision Tree

Need max compatibility? ──Yes──→ Choose MP4
      │
      No
      │
      ▼
Pursue fastest speed? ──Yes──→ Choose TS
      │
      No
      │
      ▼
Will process with FFmpeg later? ──Yes──→ Choose TS
      │
      No
      │
      ▼
    Choose MP4 (Recommended)

Performance Comparison

Following is actual test data under typical conditions (Chrome 126, Intel i7-13700, 16GB RAM):

ScenarioFragment CountTotal SizeTS ConcatenationMP4 Remuxing (FFmpeg)MP4 Streaming (Muxer)
10 min 1080p video~60~200 MB<1 sec~3 sec~2 sec
30 min 1080p video~180~600 MB<1 sec~8 sec~5 sec
60 min 4K video~360~2.5 GB~2 sec~30 sec~18 sec
120 min 4K video~720~5 GB~4 sec~60 sec~35 sec

Above data are estimates; actual performance depends on CPU, memory, and browser state. Streaming Muxer shows more obvious advantages when processing large files.

Factors Affecting Conversion Speed

FactorImpact LevelExplanation
Fragment countHighMore fragments = more file I/O operations
Total file sizeHighDirectly affects read/write time
CPU performanceMediumFFmpeg WASM needs CPU for demux/mux
Memory sizeMediumWASM virtual file system needs sufficient memory
Disk write speedMediumGreater impact when using FSA direct writes
Browser versionLowNewer browsers have better WASM performance

Limitations & Notes

Codec Format Limitations

FlowPick's conversion only changes container format, does not perform re-encoding. This means:

LimitationExplanationImpact
Cannot convert codecsH.265 source still outputs as H.265Older players may not support
Cannot change bitrateOutput bitrate matches sourceCannot compress file size
Cannot change resolutionOutput resolution matches sourceCannot downgrade or upgrade quality
Cannot change framerateOutput framerate matches sourceCannot convert 60fps→30fps
Non-standard sample rateOutput remains as-isSome players may behave abnormally

Memory Limitations

FFmpeg WASM runs in browser, subject to following limitations:

LimitationSpecific ValueImpact
WASM memory limit4GB (32-bit address space)Very large files may exceed limit
Virtual file systemStored in memoryFile size limited by available memory
Multi-threaded modeRequires SharedArrayBufferNeeds correct COEP/COOP headers
For files over 2GB, FlowPick automatically uses streaming Muxer or TS direct concatenation mode to avoid FFmpeg WASM memory limitations. See Download Engine — Memory Management for details.

Browser Compatibility

FeatureChromeEdgeFirefoxSafari
FFmpeg WASM single-threadedSupportedSupportedSupportedPartially supported
FFmpeg WASM multi-threadedNeeds COEP/COOPNeeds COEP/COOPNeeds COEP/COOPNot supported
TSToMP4Muxer streamingSupportedSupportedSupportedSupported
TS direct concatenationSupportedSupportedSupportedSupported
For more details on browser compatibility, see Browser Compatibility.

Command Line Alternatives

If you're familiar with command line, you can use native FFmpeg for better performance:

# HLS → MP4
ffmpeg -i "https://example.com/playlist.m3u8" -c copy -bsf:a aac_adtstoasc output.mp4

# DASH → MP4
ffmpeg -i "https://example.com/manifest.mpd" -c copy output.mp4

# TS fragment concatenation
cat segment_*.ts > output.ts

# TS → MP4 remuxing
ffmpeg -i output.ts -c copy -bsf:a aac_adtstoasc output.mp4

Advantages of native FFmpeg:

AdvantageExplanation
Not limited by browser memoryCan use all system memory
Hardware-accelerated encoding/decodingSupports NVENC, QSV, VideoToolbox etc.
More formats and codecsSupports hundreds of formats and codecs
Faster processingNative code performance far exceeds WASM
Supports re-encodingCan change codec format, bitrate, resolution

FAQ

Why is converted MP4 smaller than TS?

TS container has header overhead per 188-byte packet, while MP4 container's index structure is more compact. After remuxing, file size typically reduces 5-15%, but audio-video data remains completely unchanged.

Does conversion lose quality?

No. FlowPick uses -c copy (stream copy) mode, only changing container format, no re-encoding. Every byte of video and audio is preserved as-is.

Why can't some videos play after conversion?

Possible reasons:

  • Source video uses codec unsupported by your player (e.g., H.265)
  • Missing fragments during conversion caused incomplete file
  • Issue with source stream itself
If you encounter playback issues, please check Common Issues Troubleshooting and Known Issues.