Compare commits
No commits in common. "d4881197480599371cdef781b7fc316e31b9160c" and "ba5e4af355b9a4e5c38be22bff9eef11539ecba2" have entirely different histories.
d488119748
...
ba5e4af355
5 changed files with 43 additions and 49 deletions
|
|
@ -165,10 +165,6 @@ def load_config(init=False):
|
||||||
if set(old_formats) != set(formats):
|
if set(old_formats) != set(formats):
|
||||||
sformats = supported_formats()
|
sformats = supported_formats()
|
||||||
settings.FFMPEG_SUPPORTS_VP9 = 'vp9' in sformats
|
settings.FFMPEG_SUPPORTS_VP9 = 'vp9' in sformats
|
||||||
try:
|
|
||||||
settings.CHOP_SUPPORT = int(sformats.get('version', ['0'])[0]) > 2
|
|
||||||
except:
|
|
||||||
settings.CHOP_SUPPORT = False
|
|
||||||
if sformats:
|
if sformats:
|
||||||
for f in formats:
|
for f in formats:
|
||||||
if f not in sformats or not sformats[f]:
|
if f not in sformats or not sformats[f]:
|
||||||
|
|
|
||||||
|
|
@ -5,39 +5,10 @@ from bisect import bisect_left
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
|
||||||
def make_keyframe_index(video):
|
|
||||||
cmd = [
|
|
||||||
'ffprobe',
|
|
||||||
'-v', 'error',
|
|
||||||
'-show_packets', '-select_streams', 'v',
|
|
||||||
'-show_entries', 'packet=pts_time,flags',
|
|
||||||
'-of', 'csv',
|
|
||||||
'-i', video
|
|
||||||
]
|
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
||||||
stdout, stderr = p.communicate()
|
|
||||||
result = stdout.decode().strip()
|
|
||||||
keyframe_times = []
|
|
||||||
timecode = 0
|
|
||||||
for line in result.split('\n'):
|
|
||||||
if line.split(',')[1] != 'N/A':
|
|
||||||
timecode = line.split(',')[1]
|
|
||||||
if ',K' in line:
|
|
||||||
keyframe_times.append(float(timecode))
|
|
||||||
|
|
||||||
last_keyframe = ox.avinfo(video)['duration']
|
|
||||||
if keyframe_times[-1] != last_keyframe:
|
|
||||||
keyframe_times.append(last_keyframe)
|
|
||||||
|
|
||||||
keyframes_cache = video + '.keyframes'
|
|
||||||
with open(keyframes_cache, 'w') as fd:
|
|
||||||
json.dump(keyframe_times, fd, indent=0)
|
|
||||||
return keyframe_times
|
|
||||||
|
|
||||||
|
|
||||||
class Chop(object):
|
class Chop(object):
|
||||||
keyframes = []
|
keyframes = []
|
||||||
subtitles = None
|
subtitles = None
|
||||||
|
info = {}
|
||||||
ffmpeg = [
|
ffmpeg = [
|
||||||
'ffmpeg',
|
'ffmpeg',
|
||||||
'-nostats', '-loglevel', 'error',
|
'-nostats', '-loglevel', 'error',
|
||||||
|
|
@ -106,6 +77,12 @@ class Chop(object):
|
||||||
for segment in segments:
|
for segment in segments:
|
||||||
os.unlink(segment)
|
os.unlink(segment)
|
||||||
|
|
||||||
|
def get_info(self):
|
||||||
|
if self.info:
|
||||||
|
return self.info
|
||||||
|
self.info = ox.avinfo(self.video)
|
||||||
|
return self.info
|
||||||
|
|
||||||
def get_keyframes(self):
|
def get_keyframes(self):
|
||||||
video = self.video
|
video = self.video
|
||||||
if self.keyframes:
|
if self.keyframes:
|
||||||
|
|
@ -116,8 +93,35 @@ class Chop(object):
|
||||||
with open(keyframes_cache, 'r') as fd:
|
with open(keyframes_cache, 'r') as fd:
|
||||||
self.keyframes = json.load(fd)
|
self.keyframes = json.load(fd)
|
||||||
return self.keyframes
|
return self.keyframes
|
||||||
self.keyframes = make_keyframe_index(video)
|
|
||||||
return self.keyframes
|
cmd = [
|
||||||
|
'ffprobe',
|
||||||
|
'-v', 'error',
|
||||||
|
'-show_packets', '-select_streams', 'v',
|
||||||
|
'-show_entries', 'packet=pts_time,flags',
|
||||||
|
'-of', 'csv',
|
||||||
|
'-i', video
|
||||||
|
]
|
||||||
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
result = stdout.decode().strip()
|
||||||
|
keyframe_times = []
|
||||||
|
timecode = 0
|
||||||
|
for line in result.split('\n'):
|
||||||
|
if line.split(',')[1] != 'N/A':
|
||||||
|
timecode = line.split(',')[1]
|
||||||
|
if ',K' in line:
|
||||||
|
keyframe_times.append(float(timecode))
|
||||||
|
|
||||||
|
last_keyframe = self.get_info()['duration']
|
||||||
|
if keyframe_times[-1] != last_keyframe:
|
||||||
|
keyframe_times.append(last_keyframe)
|
||||||
|
|
||||||
|
self.keyframes = keyframe_times
|
||||||
|
if not os.path.exists(keyframes_cache):
|
||||||
|
with open(keyframes_cache, 'w') as fd:
|
||||||
|
json.dump(keyframe_times, fd)
|
||||||
|
return keyframe_times
|
||||||
|
|
||||||
def get_gop_sections(self, start: float, end: float) -> dict:
|
def get_gop_sections(self, start: float, end: float) -> dict:
|
||||||
keyframes = self.get_keyframes()
|
keyframes = self.get_keyframes()
|
||||||
|
|
@ -137,17 +141,17 @@ class Chop(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
def encode(self, source, target, start, duration):
|
def encode(self, source, target, start, duration):
|
||||||
info = ox.avinfo(self.video)
|
info = self.get_info()
|
||||||
if info['audio']:
|
if self.info['audio']:
|
||||||
acodec = [
|
acodec = [
|
||||||
'-c:a',
|
'-c:a',
|
||||||
info['audio'][0]['codec']
|
self.info['audio'][0]['codec']
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
acodec = []
|
acodec = []
|
||||||
vcodec = [
|
vcodec = [
|
||||||
'-c:v',
|
'-c:v',
|
||||||
info['video'][0]['codec']
|
self.info['video'][0]['codec']
|
||||||
]
|
]
|
||||||
|
|
||||||
cmd = self.ffmpeg + [
|
cmd = self.ffmpeg + [
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ from ox.utils import json
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .chop import Chop, make_keyframe_index
|
|
||||||
|
|
||||||
img_extension = 'jpg'
|
img_extension = 'jpg'
|
||||||
|
|
||||||
MAX_DISTANCE = math.sqrt(3 * pow(255, 2))
|
MAX_DISTANCE = math.sqrt(3 * pow(255, 2))
|
||||||
|
|
@ -57,10 +55,7 @@ def supported_formats():
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
stdout = stdout.decode('utf-8')
|
stdout = stdout.decode('utf-8')
|
||||||
stderr = stderr.decode('utf-8')
|
|
||||||
version = stderr.split('\n')[0].split(' ')[2]
|
|
||||||
return {
|
return {
|
||||||
'version': version.split('.'),
|
|
||||||
'ogg': 'libtheora' in stdout and 'libvorbis' in stdout,
|
'ogg': 'libtheora' in stdout and 'libvorbis' in stdout,
|
||||||
'webm': 'libvpx' in stdout and 'libvorbis' in stdout,
|
'webm': 'libvpx' in stdout and 'libvorbis' in stdout,
|
||||||
'vp8': 'libvpx' in stdout and 'libvorbis' in stdout,
|
'vp8': 'libvpx' in stdout and 'libvorbis' in stdout,
|
||||||
|
|
@ -352,7 +347,6 @@ def stream(video, target, profile, info, audio_track=0, flags={}):
|
||||||
shutil.move(enc_target, target)
|
shutil.move(enc_target, target)
|
||||||
for f in glob('%s.log*' % target):
|
for f in glob('%s.log*' % target):
|
||||||
os.unlink(f)
|
os.unlink(f)
|
||||||
make_keyframe_index(target)
|
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -619,7 +613,8 @@ def chop(video, start, end, subtitles=None):
|
||||||
fd.write(subtitles)
|
fd.write(subtitles)
|
||||||
else:
|
else:
|
||||||
subtitles_f = None
|
subtitles_f = None
|
||||||
if ext == '.mp4' and settings.CHOP_SUPPORT:
|
if ext == '.mp4':
|
||||||
|
from .chop import Chop
|
||||||
Chop(video, choped_video, start, end, subtitles_f)
|
Chop(video, choped_video, start, end, subtitles_f)
|
||||||
if subtitles_f:
|
if subtitles_f:
|
||||||
os.unlink(subtitles_f)
|
os.unlink(subtitles_f)
|
||||||
|
|
|
||||||
|
|
@ -370,7 +370,6 @@ class File(models.Model):
|
||||||
self.info.update(stream.info)
|
self.info.update(stream.info)
|
||||||
self.parse_info()
|
self.parse_info()
|
||||||
self.save()
|
self.save()
|
||||||
extract.make_keyframe_index(stream.media.path)
|
|
||||||
return True, stream.media.size
|
return True, stream.media.size
|
||||||
return save_chunk(stream, stream.media, chunk, offset, name, done_cb)
|
return save_chunk(stream, stream.media, chunk, offset, name, done_cb)
|
||||||
return False, 0
|
return False, 0
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ pandora.ui.metadataDialog = function(data) {
|
||||||
var keys = [
|
var keys = [
|
||||||
'title', 'alternativeTitles', 'director',
|
'title', 'alternativeTitles', 'director',
|
||||||
'country', 'year', 'language', 'runtime', 'color', 'sound',
|
'country', 'year', 'language', 'runtime', 'color', 'sound',
|
||||||
'productionCompany', 'filmingLocations'
|
'productionCompany',
|
||||||
'producer', 'writer', 'cinematographer', 'editor', 'composer', 'actor',
|
'producer', 'writer', 'cinematographer', 'editor', 'composer', 'actor',
|
||||||
'lyricist', 'singer',
|
'lyricist', 'singer',
|
||||||
'genre', 'keyword', 'summary'
|
'genre', 'keyword', 'summary'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue