<p>My goal is to optimize m2ts generated by ffmpeg for HLS because the generated m2ts has lots of structural overhead.</p>

<p>The below is an example of the result analyzed by Apple Media Stream Validator:</p>

<pre><code>Average segment duration: 4.95 seconds
Playlist target bitrate: 112.00kbits/sec 
Segment bitrate: Average: 149.65 kbits/sec (exceeds target by 33.62 %), Max: 179.40 kbits/sec (exceeds target by 60.18 %) 
Average segment structural overhead: 33.52 kbits/sec (22.40 %)
</code></pre>

<p>The m2ts is generated through the following ffmpeg command (for generating HLS):</p>

<pre><code>ffmpeg -i audio_p0.mp4 -i video_p0.mp4 -dn -sn -threads 0 -map 0:0 -map 1:0 -f ssegment -segment_time 5 -segment_list movie.m3u8 -segment_list_entry_prefix p0 -segment_format mpegts -c:v copy -c:a copy -vbsf h264_mp4toannexb -flags -global_header p0/stream_%04d.ts
</code></pre>

<p>The output of the above command:</p>

<pre><code>ffmpeg version 2.5.2 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan  7 2015 09:58:46 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libvpx --enable-libvo-aacenc --enable-libfdk-aac --enable-libx265 --enable-nonfree --enable-vda
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.102 / 56. 15.102
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'audio_p0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf56.15.102
  Duration: 00:00:43.76, start: 0.046440, bitrate: 33 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 32 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'video_p0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.15.102
  Duration: 00:00:43.63, start: 0.000000, bitrate: 80 kb/s
    Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 426x240 [SAR 640:639 DAR 16:9], 79 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Output #0, stream_segment,ssegment, to 'p0/stream_%04d.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf56.15.102
    Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, 32 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:1(und): Video: h264 (avc1 / 0x31637661), yuv420p, 426x240 [SAR 640:639 DAR 16:9], q=2-31, 79 kb/s, 24 fps, 90k tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -&gt; #0:0 (copy)
  Stream #1:0 -&gt; #0:1 (copy)
Press [q] to stop, [?] for help
frame= 1047 fps=0.0 q=-1.0 Lsize=N/A time=00:00:43.76 bitrate=N/A
video:427kB audio:172kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
</code></pre>

CC BY-SA 3.0
2015-01-08T17:37:44.573Z
You did not provide very much information. Are you using `ffmpeg`? If yes, then show your command and the **complete** console output. What do you mean by "trim out"? What exactly are you trying to do?
llogan
CC BY-SA 3.0
2015-01-09T10:17:11.093Z
I update the title to reflect more clear. To optimize or reduce the structural overhead of m2ts generated by ffmpeg.
Drake Guan
CC BY-SA 3.0
2015-01-09T19:43:08.797Z
You forgot the console output from `ffmpeg`. I'm not sure how I could be more clear about asking for the output, but I need to work on that since it seems to be omitted often.
llogan
<ffmpeg><linux><mpeg>
Any m2ts optimizer under Linux?
Drake Guan
# Any m2ts optimizer under Linux?

(Asked by: username_0 on 2015-01-08)

My goal is to optimize m2ts generated by ffmpeg for HLS because the generated m2ts has lots of structural overhead.
The below is an example of the result analyzed by Apple Media Stream Validator:
Average segment duration: 4.95 seconds
Playlist target bitrate: 112.00kbits/sec 
Segment bitrate: Average: 149.65 kbits/sec (exceeds target by 33.62 %), Max: 179.40 kbits/sec (exceeds target by 60.18 %) 
Average segment structural overhead: 33.52 kbits/sec (22.40 %)

The m2ts is generated through the following ffmpeg command (for generating HLS):
ffmpeg -i audio_p0.mp4 -i video_p0.mp4 -dn -sn -threads 0 -map 0:0 -map 1:0 -f ssegment -segment_time 5 -segment_list movie.m3u8 -segment_list_entry_prefix p0 -segment_format mpegts -c:v copy -c:a copy -vbsf h264_mp4toannexb -flags -global_header p0/stream_%04d.ts

The output of the above command:
ffmpeg version 2.5.2 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan  7 2015 09:58:46 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libvpx --enable-libvo-aacenc --enable-libfdk-aac --enable-libx265 --enable-nonfree --enable-vda
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.102 / 56. 15.102
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'audio_p0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf56.15.102
  Duration: 00:00:43.76, start: 0.046440, bitrate: 33 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 32 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'video_p0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.15.102
  Duration: 00:00:43.63, start: 0.000000, bitrate: 80 kb/s
    Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 426x240 [SAR 640:639 DAR 16:9], 79 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Output #0, stream_segment,ssegment, to 'p0/stream_%04d.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf56.15.102
    Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, 32 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:1(und): Video: h264 (avc1 / 0x31637661), yuv420p, 426x240 [SAR 640:639 DAR 16:9], q=2-31, 79 kb/s, 24 fps, 90k tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 1047 fps=0.0 q=-1.0 Lsize=N/A time=00:00:43.76 bitrate=N/A
video:427kB audio:172kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

**Tags:** ffmpeg, linux, mpeg

> **Comments:**
> **username_1**: You did not provide very much information. Are you using `ffmpeg`? If yes, then show your command and the **complete** console output. What do you mean by "trim out"? What exactly are you trying to do?  
> **username_0**: I update the title to reflect more clear. To optimize or reduce the structural overhead of m2ts generated by ffmpeg.  
> **username_1**: You forgot the console output from `ffmpeg`. I'm not sure how I could be more clear about asking for the output, but I need to work on that since it seems to be omitted often.  

---

## 0 answers

