mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
for snapshot, choose the best to link to the [stream]-best.png
This commit is contained in:
parent
33a282e576
commit
1aa4502d5f
1 changed files with 30 additions and 7 deletions
|
@ -940,8 +940,13 @@ class SrsWorker(cherrypy.process.plugins.SimplePlugin):
|
||||||
print 'abort snapshot %s'%snapshot['cmd']
|
print 'abort snapshot %s'%snapshot['cmd']
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# how many snapshots to output.
|
||||||
|
vframes = 6
|
||||||
|
# the expire in seconds for ffmpeg to snapshot.
|
||||||
|
expire = 10
|
||||||
|
|
||||||
# already snapshoted and not expired.
|
# already snapshoted and not expired.
|
||||||
if process is not None and diff < 10:
|
if process is not None and diff < expire:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# terminate the active process
|
# terminate the active process
|
||||||
|
@ -951,17 +956,35 @@ class SrsWorker(cherrypy.process.plugins.SimplePlugin):
|
||||||
|
|
||||||
# None incidates the process hasn't terminate yet.
|
# None incidates the process hasn't terminate yet.
|
||||||
if process.returncode is not None:
|
if process.returncode is not None:
|
||||||
# process terminated, check the returncode.
|
# process terminated with error.
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
print 'process terminated with error=%s, cmd=%s'%(process.returncode, snapshot['cmd'])
|
print 'process terminated with error=%s, cmd=%s'%(process.returncode, snapshot['cmd'])
|
||||||
|
# process terminated normally.
|
||||||
|
else:
|
||||||
|
# guess the best one.
|
||||||
|
bestsize = 0
|
||||||
|
besturl = os.path.join(static_dir, "%s/%s-best.png"%(snapshot['app'], snapshot['stream']))
|
||||||
|
for i in range(0, vframes):
|
||||||
|
output = os.path.join(static_dir, "%s/%s-%03d.png"%(snapshot['app'], snapshot['stream'], i + 1))
|
||||||
|
fsize = os.path.getsize(output)
|
||||||
|
if bestsize < fsize:
|
||||||
|
os.system("rm -f '%s'"%besturl)
|
||||||
|
os.system("ln -sf '%s' '%s'"%(output, besturl))
|
||||||
|
bestsize = fsize
|
||||||
|
print 'the best thumbnail is %s'%besturl
|
||||||
else:
|
else:
|
||||||
|
# wait for process to terminate, timeout is N*expire.
|
||||||
|
if diff < 10 * expire:
|
||||||
|
continue
|
||||||
# kill the process when user cancel.
|
# kill the process when user cancel.
|
||||||
process.kill()
|
else:
|
||||||
|
process.kill()
|
||||||
|
print 'kill the process %s'%snapshot['cmd']
|
||||||
|
|
||||||
# create new process to snapshot.
|
# create new process to snapshot.
|
||||||
ffmpeg = "./objs/ffmpeg/bin/ffmpeg"
|
ffmpeg = "./objs/ffmpeg/bin/ffmpeg"
|
||||||
output = os.path.join(static_dir, "%s-%s-%%3d.png"%(snapshot['app'], snapshot['stream']))
|
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 3 -y %s'%(ffmpeg, url, output)
|
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())
|
||||||
|
@ -971,7 +994,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-%3d.png
|
# 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
|
||||||
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…
Reference in a new issue