carykh / jumpcutter

Automatically edits vidx. Explanation here: https://www.youtube.com/watch?v=DQ8orIurGxw
MIT License
3.07k stars 544 forks source link

Possible to save audio stats (or just RE-USE the jpegs saved on the FIRST PASS) for multiple runs without saving frames each time? #157

Open petermg opened 4 years ago

petermg commented 4 years ago

Is there a way to make this save the stats it generates from the original audio file to generate multiple passes with different variables? This would be useful in cases where working on long video files and the current settings don't produce a desired file. For example, sometimes I run this with audio set to anywhere from 0.1 to 0.3 and the frame_margin anywhere between 10 to 60 depending on the framerate of the video I'm processing and what I'm trying to achieve. I don't always want hard fast cuts but sometimes I do and I'd like to see different versions processed of the same original. Would be super useful for it NOT to have to copy ALL THE FRAMES to jpegs for EVERY SINGLE RUN. I've messed around with it so that it doesn't delete the TEMP folder but I don't know how to make it NOT save the jpeg files again. For example, I was trying to modify my original script to just not delete the TEMP folder, then make an ADDITIONAL version that I could run AFTER the first that would remove the saving of the jpeg files but still write the wav files and then processes the original jpegs to create a new video file based on the new settings of frame_margin and silent_threshold, but I can't figure out how to make my second one NOT save new frames... :\ Hope this makes sense.

Dreiparrent commented 4 years ago

Hey @petermg,

Look at the commands around line 95.

createPath(TEMP_FOLDER)

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"

subprocess.call(command, shell=True)

command = "ffmpeg -i "+TEMP_FOLDER+"/input.mp4 2>&1"
f = open(TEMP_FOLDER+"/params.txt", "w")
subprocess.call(command, shell=True, stdout=f)

With these, we are asking python to send shell commands.

By removing these subprocess methods, you will no longer ask ffmpeg to create the frames, audio, or params.

If this is important to you, I suggest wrapping these commands in a function that you can enable/disable with a parser arg.

Otherwise, you can always comment it out :)

Let me know if this helps or if you would like more detail.

Cheers