add optoin to use melt(MLT) to extract frames from H264
This commit is contained in:
parent
1efd49e19a
commit
ada3bbe346
5 changed files with 44 additions and 13 deletions
2
README
2
README
|
@ -29,7 +29,7 @@ To run pan.do/ra you need to install and setup:
|
||||||
python-geoip python-html5lib python-lxml \
|
python-geoip python-html5lib python-lxml \
|
||||||
python-gst0.10 gstreamer0.10-plugins-good gstreamer0.10-plugins-bad \
|
python-gst0.10 gstreamer0.10-plugins-good gstreamer0.10-plugins-bad \
|
||||||
postgresql postgresql-contrib rabbitmq-server \
|
postgresql postgresql-contrib rabbitmq-server \
|
||||||
ffmpeg2theora libav-tools libavcodec-extra-53 \
|
ffmpeg2theora libav-tools libavcodec-extra-53 melt \
|
||||||
python-ox oxframe imagemagick poppler-utils mkvtoolnix gpac
|
python-ox oxframe imagemagick poppler-utils mkvtoolnix gpac
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ def run_command(cmd, timeout=10):
|
||||||
return p.returncode
|
return p.returncode
|
||||||
|
|
||||||
|
|
||||||
def frame(video, frame, position, height=128, redo=False):
|
def frame(video, frame, position, height=128, redo=False, info=None):
|
||||||
'''
|
'''
|
||||||
params:
|
params:
|
||||||
video input
|
video input
|
||||||
|
@ -339,6 +339,16 @@ def frame(video, frame, position, height=128, redo=False):
|
||||||
if redo or not exists(frame):
|
if redo or not exists(frame):
|
||||||
ox.makedirs(folder)
|
ox.makedirs(folder)
|
||||||
if video.endswith('.mp4'):
|
if video.endswith('.mp4'):
|
||||||
|
if settings.USE_MELT:
|
||||||
|
cmd = melt_frame_cmd(video, frame, position, height, info)
|
||||||
|
else:
|
||||||
|
cmd = melt_frame_cmd(video, frame, position, height)
|
||||||
|
else:
|
||||||
|
cmd = ['oxframe', '-i', video, '-o', frame,
|
||||||
|
'-p', str(position), '-y', str(height)]
|
||||||
|
run_command(cmd)
|
||||||
|
|
||||||
|
def avconv_frame_cmd(video, frame, position, height=128):
|
||||||
cmd = [
|
cmd = [
|
||||||
AVCONV, '-y',
|
AVCONV, '-y',
|
||||||
'-ss', str(position),
|
'-ss', str(position),
|
||||||
|
@ -349,10 +359,29 @@ def frame(video, frame, position, height=128, redo=False):
|
||||||
if not frame.endswith('.png'):
|
if not frame.endswith('.png'):
|
||||||
cmd += ['-f', 'mjpeg']
|
cmd += ['-f', 'mjpeg']
|
||||||
cmd += [frame]
|
cmd += [frame]
|
||||||
else:
|
return cmd
|
||||||
cmd = ['oxframe', '-i', video, '-o', frame,
|
|
||||||
'-p', str(position), '-y', str(height)]
|
def melt_frame_cmd(video, frame, position, height=128, info=None):
|
||||||
run_command(cmd)
|
if not info:
|
||||||
|
info = ox.avinfo(video)
|
||||||
|
fps = float(AspectRatio(info['video'][0]['framerate']))
|
||||||
|
format = frame.split('.')[-1]
|
||||||
|
vcodec = 'mjpeg' if format == 'jpg' else 'png'
|
||||||
|
cmd = [
|
||||||
|
'melt',
|
||||||
|
'-silent',
|
||||||
|
video,
|
||||||
|
'in=%d' % position, 'out=%d' % position,
|
||||||
|
'-consumer' 'avformat:%s' % frame,
|
||||||
|
'vcodec=%s' % vcodec
|
||||||
|
]
|
||||||
|
if height:
|
||||||
|
dar = AspectRatio(info['video'][0]['display_aspect_ratio'])
|
||||||
|
width = int(dar * height)
|
||||||
|
width += width % 2
|
||||||
|
position = int(position * fps)
|
||||||
|
cmd += ['-s', '%sx%s' % (width, height)]
|
||||||
|
return cmd
|
||||||
|
|
||||||
def frame_direct(video, target, position):
|
def frame_direct(video, target, position):
|
||||||
fdir = os.path.dirname(target)
|
fdir = os.path.dirname(target)
|
||||||
|
|
|
@ -1084,7 +1084,7 @@ class Item(models.Model):
|
||||||
path = os.path.join(settings.MEDIA_ROOT, stream.path(),
|
path = os.path.join(settings.MEDIA_ROOT, stream.path(),
|
||||||
'frames', "%dp"%height, "%s.jpg"%position)
|
'frames', "%dp"%height, "%s.jpg"%position)
|
||||||
if not os.path.exists(path) and stream.media:
|
if not os.path.exists(path) and stream.media:
|
||||||
extract.frame(stream.media.path, path, position, height)
|
extract.frame(stream.media.path, path, position, height, info=stream.info)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return None
|
return None
|
||||||
return path
|
return path
|
||||||
|
|
|
@ -152,6 +152,7 @@ LOGGING = {
|
||||||
AUTH_PROFILE_MODULE = 'user.UserProfile'
|
AUTH_PROFILE_MODULE = 'user.UserProfile'
|
||||||
AUTH_CHECK_USERNAME = True
|
AUTH_CHECK_USERNAME = True
|
||||||
AVCONV_VERSION = 0
|
AVCONV_VERSION = 0
|
||||||
|
USE_MELT=False
|
||||||
|
|
||||||
#=========================================================================
|
#=========================================================================
|
||||||
#Pan.do/ra related settings settings
|
#Pan.do/ra related settings settings
|
||||||
|
|
|
@ -52,6 +52,7 @@ apt-get install -y \
|
||||||
$LIBAVCODEC_EXTRA \
|
$LIBAVCODEC_EXTRA \
|
||||||
libav-tools \
|
libav-tools \
|
||||||
ffmpeg2theora \
|
ffmpeg2theora \
|
||||||
|
melt \
|
||||||
mkvtoolnix \
|
mkvtoolnix \
|
||||||
gpac \
|
gpac \
|
||||||
imagemagick \
|
imagemagick \
|
||||||
|
|
Loading…
Reference in a new issue