fix jump
This commit is contained in:
parent
e1470fbb66
commit
70abd1f9ea
1 changed files with 34 additions and 24 deletions
58
bin/jump
58
bin/jump
|
@ -69,7 +69,8 @@ parser.add_argument('--silent_speed', type=float, default=7.50, help="the speed
|
||||||
parser.add_argument('--frame_margin', type=float, default=2, help="some silent frames adjacent to sounded frames are included to provide context. How many frames on either the side of speech should be included? That's this variable.")
|
parser.add_argument('--frame_margin', type=float, default=2, help="some silent frames adjacent to sounded frames are included to provide context. How many frames on either the side of speech should be included? That's this variable.")
|
||||||
parser.add_argument('--sample_rate', type=float, default=44100, help="sample rate of the input and output videos")
|
parser.add_argument('--sample_rate', type=float, default=44100, help="sample rate of the input and output videos")
|
||||||
parser.add_argument('--frame_rate', type=float, default=30, help="frame rate of the input and output videos. optional... I try to find it out myself, but it doesn't always work.")
|
parser.add_argument('--frame_rate', type=float, default=30, help="frame rate of the input and output videos. optional... I try to find it out myself, but it doesn't always work.")
|
||||||
parser.add_argument('--frame_quality', type=int, default=6, help="quality of frames to be extracted from input video. 1 is highest, 31 is lowest, 3 is the default.")
|
parser.add_argument('--frame_quality', type=int, default=9, help="quality of frames to be extracted from input video. 1 is highest, 31 is lowest, 3 is the default.")
|
||||||
|
parser.add_argument('--audio_only', default=False, action='store_true', help="outputs an audio file")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -79,6 +80,7 @@ frameRate = args.frame_rate
|
||||||
SAMPLE_RATE = args.sample_rate
|
SAMPLE_RATE = args.sample_rate
|
||||||
SILENT_THRESHOLD = args.silent_threshold
|
SILENT_THRESHOLD = args.silent_threshold
|
||||||
FRAME_SPREADAGE = args.frame_margin
|
FRAME_SPREADAGE = args.frame_margin
|
||||||
|
AUDIO_ONLY = args.audio_only
|
||||||
NEW_SPEED = [args.silent_speed, args.sounded_speed]
|
NEW_SPEED = [args.silent_speed, args.sounded_speed]
|
||||||
if args.url != None:
|
if args.url != None:
|
||||||
INPUT_FILE = downloadFile(args.url)
|
INPUT_FILE = downloadFile(args.url)
|
||||||
|
@ -99,10 +101,11 @@ AUDIO_FADE_ENVELOPE_SIZE = 400 # smooth out transitiion's audio by quickly fadin
|
||||||
|
|
||||||
createPath(TEMP_FOLDER)
|
createPath(TEMP_FOLDER)
|
||||||
|
|
||||||
command = "ffmpeg -i "+INPUT_FILE+" -qscale:v "+str(FRAME_QUALITY)+" "+TEMP_FOLDER+"/frame%06d.jpg -hide_banner"
|
if not AUDIO_ONLY:
|
||||||
subprocess.call(command, shell=True)
|
command = "ffmpeg -i \""+INPUT_FILE+"\" -qscale:v "+str(FRAME_QUALITY)+" "+TEMP_FOLDER+"/frame%06d.jpg -hide_banner"
|
||||||
|
subprocess.call(command, shell=True)
|
||||||
|
|
||||||
command = "ffmpeg -i "+INPUT_FILE+" -ab 160k -ac 2 -ar "+str(SAMPLE_RATE)+" -vn "+TEMP_FOLDER+"/audio.wav"
|
command = "ffmpeg -i \""+INPUT_FILE+"\" -ab 160k -ac 2 -ar "+str(SAMPLE_RATE)+" -vn "+TEMP_FOLDER+"/audio.wav"
|
||||||
|
|
||||||
subprocess.call(command, shell=True)
|
subprocess.call(command, shell=True)
|
||||||
|
|
||||||
|
@ -116,16 +119,19 @@ sampleRate, audioData = wavfile.read(TEMP_FOLDER+"/audio.wav")
|
||||||
audioSampleCount = audioData.shape[0]
|
audioSampleCount = audioData.shape[0]
|
||||||
maxAudioVolume = getMaxVolume(audioData)
|
maxAudioVolume = getMaxVolume(audioData)
|
||||||
|
|
||||||
f = open(TEMP_FOLDER+"/params.txt", 'r+')
|
if not AUDIO_ONLY:
|
||||||
pre_params = f.read()
|
f = open(TEMP_FOLDER+"/params.txt", 'r+')
|
||||||
f.close()
|
pre_params = f.read()
|
||||||
params = pre_params.split('\n')
|
f.close()
|
||||||
for line in params:
|
params = pre_params.split('\n')
|
||||||
m = re.search('Stream #.*Video.* ([0-9]*) fps',line)
|
for line in params:
|
||||||
if m is not None:
|
m = re.search('Stream #.*Video.* ([0-9]*) fps',line)
|
||||||
frameRate = float(m.group(1))
|
if m is not None:
|
||||||
|
frameRate = float(m.group(1))
|
||||||
|
|
||||||
samplesPerFrame = sampleRate/frameRate
|
samplesPerFrame = sampleRate/frameRate
|
||||||
|
else:
|
||||||
|
samplesPerFrame = sampleRate
|
||||||
|
|
||||||
audioFrameCount = int(math.ceil(audioSampleCount/samplesPerFrame))
|
audioFrameCount = int(math.ceil(audioSampleCount/samplesPerFrame))
|
||||||
|
|
||||||
|
@ -184,15 +190,16 @@ for chunk in chunks:
|
||||||
outputAudioData[outputPointer:outputPointer+AUDIO_FADE_ENVELOPE_SIZE] *= mask
|
outputAudioData[outputPointer:outputPointer+AUDIO_FADE_ENVELOPE_SIZE] *= mask
|
||||||
outputAudioData[endPointer-AUDIO_FADE_ENVELOPE_SIZE:endPointer] *= 1-mask
|
outputAudioData[endPointer-AUDIO_FADE_ENVELOPE_SIZE:endPointer] *= 1-mask
|
||||||
|
|
||||||
startOutputFrame = int(math.ceil(outputPointer/samplesPerFrame))
|
if not AUDIO_ONLY:
|
||||||
endOutputFrame = int(math.ceil(endPointer/samplesPerFrame))
|
startOutputFrame = int(math.ceil(outputPointer/samplesPerFrame))
|
||||||
for outputFrame in range(startOutputFrame, endOutputFrame):
|
endOutputFrame = int(math.ceil(endPointer/samplesPerFrame))
|
||||||
inputFrame = int(chunk[0]+NEW_SPEED[int(chunk[2])]*(outputFrame-startOutputFrame))
|
for outputFrame in range(startOutputFrame, endOutputFrame):
|
||||||
didItWork = copyFrame(inputFrame,outputFrame)
|
inputFrame = int(chunk[0]+NEW_SPEED[int(chunk[2])]*(outputFrame-startOutputFrame))
|
||||||
if didItWork:
|
didItWork = copyFrame(inputFrame,outputFrame)
|
||||||
lastExistingFrame = inputFrame
|
if didItWork:
|
||||||
else:
|
lastExistingFrame = inputFrame
|
||||||
copyFrame(lastExistingFrame,outputFrame)
|
else:
|
||||||
|
copyFrame(lastExistingFrame,outputFrame)
|
||||||
|
|
||||||
outputPointer = endPointer
|
outputPointer = endPointer
|
||||||
|
|
||||||
|
@ -204,8 +211,11 @@ for endGap in range(outputFrame,audioFrameCount):
|
||||||
copyFrame(int(audioSampleCount/samplesPerFrame)-1,endGap)
|
copyFrame(int(audioSampleCount/samplesPerFrame)-1,endGap)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
command = "ffmpeg -framerate "+str(frameRate)+" -i "+TEMP_FOLDER+"/newFrame%06d.jpg -i "+TEMP_FOLDER+"/audioNew.wav -strict -2 "+OUTPUT_FILE
|
if not AUDIO_ONLY:
|
||||||
subprocess.call(command, shell=True)
|
command = "ffmpeg -framerate "+str(frameRate)+" -i "+TEMP_FOLDER+"/newFrame%06d.jpg -i "+TEMP_FOLDER+"/audioNew.wav -strict -2 \""+OUTPUT_FILE+"\""
|
||||||
|
subprocess.call(command, shell=True)
|
||||||
|
else:
|
||||||
|
copyfile(TEMP_FOLDER+"/audioNew.wav", OUTPUT_FILE)
|
||||||
|
|
||||||
deletePath(TEMP_FOLDER)
|
deletePath(TEMP_FOLDER)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue