Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

transcode and segment with ffmpeg

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?

like image 509
alphablender Avatar asked Jan 07 '12 05:01

alphablender


People also ask

Does ffmpeg support HLS?

For this task we will use ffmpeg , a powerful tool that supports conversion of various video formats from one to another, including HLS both as input and output.

What is Probesize?

probesize integer (input) Set probing size in bytes, i.e. the size of the data to analyze to get stream information. A higher value will enable detecting more information in case it is dispersed into the stream, but will increase latency.

What formats can Ffmpeg support?

This is the input file. FFmpeg can input most container formats natively, including MP4, . ts, MOV, AVI, Y4M, MKV, and many others. This is the output file.


2 Answers

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 git repository
  • compile with libx264 codec
  • -map 0 is needed

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

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 
like image 56
vladaman Avatar answered Sep 21 '22 07:09

vladaman


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

like image 31
Mahendra Avatar answered Sep 20 '22 07:09

Mahendra