Skip to content

Commit

Permalink
bumped version; more rigorous ffmpeg error checking + correction
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed May 13, 2021
1 parent 25a3380 commit 6aee9d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion auto_editor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'''__init__.py'''

__version__ = '21.16.1'
__version__ = '21.19.1'
4 changes: 1 addition & 3 deletions auto_editor/ffwrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''ffwrapper.py'''

# Internal Libraries
import subprocess
from os import path
from platform import system

Expand Down Expand Up @@ -49,7 +50,6 @@ def updateLog(self, log):
self.mylog = log

def run(self, cmd: list):
import subprocess
cmd.insert(0, self.myPath)

if(None in cmd):
Expand Down Expand Up @@ -192,12 +192,10 @@ def run(self, cmd: list):
cmd.extend(['-nostats', '-loglevel', 'error'])
self.mylog.debug(cmd)

import subprocess
subprocess.call(cmd)

def Popen(self, cmd: list):
cmd = [self.myPath] + cmd
import subprocess
if(self.FFdebug):
return subprocess.Popen(cmd, stdout=subprocess.PIPE)
return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
Expand Down
35 changes: 25 additions & 10 deletions auto_editor/renderVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Internal Libraries
import subprocess
from os import path
from platform import system

# Included Libaries
Expand All @@ -21,8 +22,8 @@ def fset(cmd, option, value):
if(new_codec != 'dvvideo'): # This codec seems strange.
cmd.extend(['-vcodec', new_codec])

if(new_codec == 'h264' and system() != 'Linux'):
cmd.extend(['-allow_sw', '1'])
# if(new_codec == 'h264' and system() != 'Linux'):
# cmd.extend(['-allow_sw', '1'])
else:
cmd = fset(cmd, '-vcodec', args.video_codec)

Expand All @@ -34,6 +35,25 @@ def fset(cmd, option, value):
cmd.extend(['-movflags', '+faststart', '-strict', '-2'])
return cmd

def scaleToSped(ffmpeg, ffprobe, vidFile, args, temp):

SCALE = f'{temp}{sep()}scale.mp4'
SPED = f'{temp}{sep()}spedup.mp4'

cmd = ['-i', SCALE]
cmd = properties(cmd, args, vidFile, ffprobe)
cmd.append(SPED)
check_errors = ffmpeg.pipe(cmd)

if('Error' in check_errors or 'failed' in check_errors):
cmd = ['-i', SCALE]
if('-allow_sw 1' in check_errors):
cmd.extend(['-allow_sw', '1'])

cmd = properties(cmd, args, vidFile, ffprobe)
cmd.append(SPED)
ffmpeg.run(cmd)


def renderAv(ffmpeg, ffprobe, vidFile: str, args, chunks: list, speeds: list, fps,
has_vfr, temp, log):
Expand Down Expand Up @@ -122,10 +142,7 @@ def read(self, buf_size):
log.error('Broken Pipe Error!')

if(args.scale != 1):
cmd = ['-i', f'{temp}{sep()}scale.mp4']
cmd = properties(cmd, args, vidFile, ffprobe)
cmd.append(f'{temp}{sep()}spedup.mp4')
ffmpeg.run(cmd)
scaleToSped(ffmpeg, ffprobe, vidFile, args, temp)

if(log.is_debug):
log.debug('Writing the output file.')
Expand All @@ -152,7 +169,7 @@ def renderOpencv(ffmpeg, ffprobe, vidFile: str, args, chunks: list, speeds: list
if(args.scale != 1):
width = int(width * args.scale)
height = int(height * args.scale)
video_name = f'{temp}{sep()}resize.mp4'
video_name = f'{temp}{sep()}scale.mp4'
else:
video_name = f'{temp}{sep()}spedup.mp4'

Expand Down Expand Up @@ -371,9 +388,7 @@ def values(val, log, _type, totalFrames, width, height):
cmd.append(f'{temp}{sep()}spedup.mp4')
ffmpeg.run(cmd)
else:
cmd = properties(['-i', f'{temp}{sep()}resize.mp4'], args, vidFile, ffprobe)
cmd.append(f'{temp}{sep()}spedup.mp4')
ffmpeg.run(cmd)
scaleToSped(ffmpeg, ffprobe, vidFile, args, temp)

if(log.is_debug):
log.debug('Writing the output file.')
Expand Down

0 comments on commit 6aee9d4

Please sign in to comment.