[FFmpeg-devel] [PATCH] tools: add a HLS serving example.
Clément Bœsch
ubitux at gmail.com
Tue Aug 14 14:33:27 CEST 2012
From: Clément Bœsch <clement.boesch at smartjog.com>
---
tools/hls.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100755 tools/hls.py
diff --git a/tools/hls.py b/tools/hls.py
new file mode 100755
index 0000000..e773a48
--- /dev/null
+++ b/tools/hls.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+#
+# example of usage:
+#
+# % mkdir -p ~/www/bbb-hls
+# % ./ffmpeg -i big_buck_bunny_480p_h264.mov -c copy -map 0:0 -map 0:1 \
+# -bsf h264_mp4toannexb \
+# -f segment \
+# -segment_list segments.list \
+# -segment_time 10 \
+# -segment_list_size 0 \
+# -segment_list_type ext \
+# ~/www/bbb-hls/fileSequence%03d.ts
+# % python2 tools/hls.py segments.list > ~/www/bbb-hls/playlist.m3u8
+# % cd ~/www
+# % python2 -m SimpleHTTPServer
+# Serving HTTP on 0.0.0.0 port 8000 ...
+#
+# [...]
+#
+# % ./ffplay http://localhost:8000/bbb-hls/playlist.m3u8
+#
+
+import sys, math
+
+# Parse segment list
+f = open(sys.argv[1], 'r')
+data = []
+last_pts = None
+for line in f.readlines():
+ name, startstr, endstr = line.rstrip().split(',')
+ start, end = float(startstr), float(endstr)
+ if last_pts != None:
+ data[-1]['duration'] = start - last_pts
+ last_pts = start
+ data.append({'name': name, 'start': start, 'end': end})
+if last_pts:
+ data[-1]['duration'] = data[-1]['end'] - data[-1]['start']
+f.close()
+
+# Maximum segment duration in seconds
+target_duration = max(seg['duration'] for seg in data)
+target_duration = int(math.ceil(target_duration))
+
+# M3U playlist
+print '#EXTM3U'
+print '#EXT-X-TARGETDURATION:%d' % target_duration
+for seg in data:
+ print '#EXTINF:%f,' % seg['duration']
+ print seg['name'].split('/')[-1]
+print '#EXT-X-ENDLIST'
--
1.7.10.4
More information about the ffmpeg-devel
mailing list