27

It appears that ffmpeg now has a segmenter in it, or at least there is a command line option

-f segment

in the documentation.

Does this mean I can use ffmpeg to realtime-transcode a video into h.264 and deliver segmented IOS compatible .m3u8 streams using ffmpeg alone? if so, what would a command to transcode an arbitrary video file to a segmented h.264 aac 640 x 480 stream ios compatible stream?

alphablender
  • 2,168
  • 5
  • 27
  • 42
  • 1
    If TS contain multiple programs (TV programs that captured by DVB-T), how can split it? For example I have a TS file that contain football + cooking + cartoon .How can i split this TS file to 3 mpg files? – Dr.jacky Jul 20 '15 at 13:14

2 Answers2

35

Absolutely - you can use -f segment to chop video into pieces and serve it to iOS devices. ffmpeg will create segment files .ts and you can serve those with any web server.

Working example (with disabled sound) - ffmpeg version N-39494-g41a097a:

./ffmpeg -v 9 -loglevel 99 -re -i sourcefile.avi -an \
-c:v libx264 -b:v 128k -vpre ipod320 \ 
-flags -global_header -map 0 -f segment -segment_time 4 \
-segment_list test.m3u8 -segment_format mpegts stream%05d.ts

Tips:

  • make sure you compile ffmpeg from most recent repository
  • compile with libx264 codec
  • -map 0 is needed

How I compiled FFMPEG - with extra rtmp support to get feeds from

export PKG_CONFIG_PATH="/usr/lib/pkgconfig/:../rtmpdump-2.3/librtmp"    

./configure --enable-librtmp --enable-libx264 \
--libdir='../x264/:/usr/local/lib:../rtmpdump-2.3' \
--enable-gpl --enable-pthreads --enable-libvpx \
--disable-ffplay --disable-ffserver --disable-shared --enable-debug
vladaman
  • 3,741
  • 2
  • 29
  • 26
  • I'm on a mac, snow leopard and I'm trying to compile this, don't need librtmp since i'm not doing RTMP streaming, any suggestions on what to download, steps I need to follow to get this working? FFmpeg how-to's seem to refer to things like libfaad which seems to not be necessary anymore. – alphablender May 08 '12 at 05:49
  • 1
    doesn't work for me, the resulting playlist always has just the last element. [just Stream00009.ts for instance] – Aviad Rozenhek Aug 01 '12 at 17:01
  • If TS contain multiple programs (TV programs that captured by DVB-T), how can split it? For example I have a TS file that contain football + cooking + cartoon .How can i split this TS file to 3 mpg files? – Dr.jacky Jul 20 '15 at 13:12
  • 1
    Use -map 0:X and add the streams you want to pick out. Then you can remux the streams into a new, single program (or however many programs) transport stream. – Brian Nov 18 '15 at 15:19
  • I can't find an answer to do this but with MP4/webm. Can you point me in that direction @vladman ? (I've tried different parameters in cli but couldn't make it work) – Javier Constanzo Apr 07 '16 at 19:49
  • notice that if 'c:v copy' is used instead of 'c:v libx264' then segmentation is correct if key frames are uniformply disperesed (in case of '-segment-time 4' it's expected each a key frame each 4 seconds). – Shevach Riabtsev Sep 04 '19 at 13:34
6

This is found in the ffmpeg documentation: https://ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment

hinekyle
  • 822
  • 8
  • 16
Mahendra
  • 13,575
  • 2
  • 16
  • 4