mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #502, snapshot 1 image per 1 seconds, choose best from 5 images.
This commit is contained in:
parent
1aa4502d5f
commit
2bae6e09d3
1 changed files with 17 additions and 9 deletions
|
@ -941,9 +941,21 @@ class SrsWorker(cherrypy.process.plugins.SimplePlugin):
|
||||||
break
|
break
|
||||||
|
|
||||||
# how many snapshots to output.
|
# how many snapshots to output.
|
||||||
vframes = 6
|
vframes = 5
|
||||||
# the expire in seconds for ffmpeg to snapshot.
|
# the expire in seconds for ffmpeg to snapshot.
|
||||||
expire = 10
|
expire = 1
|
||||||
|
# the timeout to kill ffmpeg.
|
||||||
|
kill_ffmpeg_timeout = 30 * expire
|
||||||
|
# the ffmpeg binary path
|
||||||
|
ffmpeg = "./objs/ffmpeg/bin/ffmpeg"
|
||||||
|
# the best url for thumbnail.
|
||||||
|
besturl = os.path.join(static_dir, "%s/%s-best.png"%(snapshot['app'], snapshot['stream']))
|
||||||
|
# the lambda to generate the thumbnail with index.
|
||||||
|
lgo = lambda dir, app, stream, index: os.path.join(dir, "%s/%s-%03d.png"%(app, stream, index))
|
||||||
|
# the output for snapshot command
|
||||||
|
output = os.path.join(static_dir, "%s/%s-%%03d.png"%(snapshot['app'], snapshot['stream']))
|
||||||
|
# the ffmepg command to snapshot
|
||||||
|
cmd = '%s -i %s -vf fps=1 -vcodec png -f image2 -an -y -vframes %s -y %s'%(ffmpeg, url, vframes, output)
|
||||||
|
|
||||||
# already snapshoted and not expired.
|
# already snapshoted and not expired.
|
||||||
if process is not None and diff < expire:
|
if process is not None and diff < expire:
|
||||||
|
@ -963,9 +975,8 @@ class SrsWorker(cherrypy.process.plugins.SimplePlugin):
|
||||||
else:
|
else:
|
||||||
# guess the best one.
|
# guess the best one.
|
||||||
bestsize = 0
|
bestsize = 0
|
||||||
besturl = os.path.join(static_dir, "%s/%s-best.png"%(snapshot['app'], snapshot['stream']))
|
|
||||||
for i in range(0, vframes):
|
for i in range(0, vframes):
|
||||||
output = os.path.join(static_dir, "%s/%s-%03d.png"%(snapshot['app'], snapshot['stream'], i + 1))
|
output = lgo(static_dir, snapshot['app'], snapshot['stream'], i + 1)
|
||||||
fsize = os.path.getsize(output)
|
fsize = os.path.getsize(output)
|
||||||
if bestsize < fsize:
|
if bestsize < fsize:
|
||||||
os.system("rm -f '%s'"%besturl)
|
os.system("rm -f '%s'"%besturl)
|
||||||
|
@ -974,7 +985,7 @@ class SrsWorker(cherrypy.process.plugins.SimplePlugin):
|
||||||
print 'the best thumbnail is %s'%besturl
|
print 'the best thumbnail is %s'%besturl
|
||||||
else:
|
else:
|
||||||
# wait for process to terminate, timeout is N*expire.
|
# wait for process to terminate, timeout is N*expire.
|
||||||
if diff < 10 * expire:
|
if diff < kill_ffmpeg_timeout:
|
||||||
continue
|
continue
|
||||||
# kill the process when user cancel.
|
# kill the process when user cancel.
|
||||||
else:
|
else:
|
||||||
|
@ -982,9 +993,6 @@ class SrsWorker(cherrypy.process.plugins.SimplePlugin):
|
||||||
print 'kill the process %s'%snapshot['cmd']
|
print 'kill the process %s'%snapshot['cmd']
|
||||||
|
|
||||||
# create new process to snapshot.
|
# create new process to snapshot.
|
||||||
ffmpeg = "./objs/ffmpeg/bin/ffmpeg"
|
|
||||||
output = os.path.join(static_dir, "%s/%s-%%03d.png"%(snapshot['app'], snapshot['stream']))
|
|
||||||
cmd = '%s -i %s -vf fps=1/6 -vcodec png -f image2 -an -y -vframes %s -y %s'%(ffmpeg, url, vframes, output)
|
|
||||||
print 'snapshot by: %s'%cmd
|
print 'snapshot by: %s'%cmd
|
||||||
|
|
||||||
process = create_process(cmd, discard.fileno(), discard.fileno())
|
process = create_process(cmd, discard.fileno(), discard.fileno())
|
||||||
|
@ -994,7 +1002,7 @@ class SrsWorker(cherrypy.process.plugins.SimplePlugin):
|
||||||
pass;
|
pass;
|
||||||
|
|
||||||
# {"action":"on_publish","client_id":108,"ip":"127.0.0.1","vhost":"__defaultVhost__","app":"live","stream":"livestream"}
|
# {"action":"on_publish","client_id":108,"ip":"127.0.0.1","vhost":"__defaultVhost__","app":"live","stream":"livestream"}
|
||||||
# ffmpeg -i rtmp://127.0.0.1:1935/live?vhost=dev/stream -vf fps=1/6 -vcodec png -f image2 -an -y -vframes 3 -y static-dir/live/livestream-%03d.png
|
# ffmpeg -i rtmp://127.0.0.1:1935/live?vhost=dev/stream -vf fps=1 -vcodec png -f image2 -an -y -vframes 3 -y static-dir/live/livestream-%03d.png
|
||||||
def snapshot_create(self, req):
|
def snapshot_create(self, req):
|
||||||
url = "rtmp://127.0.0.1/%s...vhost...%s/%s"%(req['app'], req['vhost'], req['stream'])
|
url = "rtmp://127.0.0.1/%s...vhost...%s/%s"%(req['app'], req['vhost'], req['stream'])
|
||||||
if url in self.__snapshots:
|
if url in self.__snapshots:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue