Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- #Author MetaPhaze
- #Use at your own risk license
- import os
- import sys
- import time
- OUR_TIME = ""
- TIME = ""
- NEW_TIME = ""
- def GetTime():
- TIME = time.ctime()
- print TIME
- NEW_TIME = TIME.split(" ",5)
- OUR_TIME = "-".join(["%s" % (v) for v in NEW_TIME])
- NEW_TIME = OUR_TIME.split(":", 2)
- OUR_TIME = "-".join(["%s" % (v) for v in NEW_TIME])
- print OUR_TIME
- return OUR_TIME
- LineSeparator = os.linesep
- arg_count = len(sys.argv)
- doDir = 0
- OutputPath = ""
- Normalize = 0
- FIRST_PASS_COMMAND = "ffmpeg "
- FIRST_PASS_INPUT_SOUND_FORMAT = "-f alsa "
- FIRST_PASS_INPUT_SOUND_OPTS = "-ac 2 -ar 48000 -acodec pcm_s16le -ab 1536k "
- FIRST_PASS_OUTPUT_SOUND_FORMAT = "-ac 2 -ab 384k "
- # if plughw:1 doesn't work there are other choices
- # pulse
- # hw:0,0
- # hw:0
- # /dev/dsp
- # /dev/mixer
- FIRST_PASS_INPUT_SOUND_DEVICE = "-i hw:0 "
- FIRST_PASS_INPUT_VIDEO_FORMAT = "-f x11grab "
- FIRST_PASS_INPUT_VIDEO_OPTS = "-i :0.0+0+0 " # remove +1280+1024 for full screen
- FIRST_PASS_OUTPUT_VIDEO_OPTS = "-vcodec libx264 -preset ultrafast -crf 0 "
- FIRST_PASS_OUTPUT_MAP = "" #"-map 0.0 -map 1.0:0.0 -async 1 "
- FIRST_PASS_RATE_OPTS = "-r 30 -s 1920x1080 " # full screen at 2560x1024
- OUR_TIME = GetTime()
- FIRST_PASS_OUTPUT = "/home/metaphaze/ramdisk/ScreenCast-Output-"+ OUR_TIME +".mkv"
- print FIRST_PASS_OUTPUT
- if arg_count == 1:
- # ///////////////////////////////////////////////////////////////////////////////////////////////////////
- # /////////////////////////////////////// First Pass
- # ///////////////////////////////////////////////////////////////////////////////////////////////////////
- print 'ScreenCapture'
- print 'screencapture --help for help.'
- print 'No options specified using defaults.'
- print 'Capture Started, Press Q to quit.'
- #ffmpeg -s sxga -r 30 -f x11grab -i :0.0 -f alsa -ac 2 -i plughw:1
- #-vcodec libx264 -vpre lossless_ultrafast
- #-acodec flac -map 0.0 -map 1.0:0.0 -y /var/tmp/portage/witcherintro.mkv
- Command = FIRST_PASS_COMMAND + FIRST_PASS_INPUT_SOUND_FORMAT + FIRST_PASS_INPUT_SOUND_OPTS + FIRST_PASS_INPUT_SOUND_DEVICE + FIRST_PASS_RATE_OPTS + FIRST_PASS_INPUT_VIDEO_FORMAT + FIRST_PASS_INPUT_VIDEO_OPTS + FIRST_PASS_OUTPUT_VIDEO_OPTS + FIRST_PASS_OUTPUT_MAP + FIRST_PASS_OUTPUT_SOUND_FORMAT + FIRST_PASS_OUTPUT
- print "##################################################################################################"
- print "# First Pass - Capture Screen Output #"
- print "##################################################################################################"
- print Command
- print "##################################################################################################"
- os.system(Command)
- print "##################################################################################################"
- print "# Moving to temp file for work #"
- print "##################################################################################################"
- SECOND_PASS_INPUT = "/home/metaphaze/ramdisk/ScreenCastConvert-" + OUR_TIME + ".mkv"
- Command = "mv " + FIRST_PASS_OUTPUT + " " + SECOND_PASS_INPUT
- print Command
- os.system(Command)
- # ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- # /////////////////////////////////////// Second Pass
- #////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- SECOND_PASS_COMMAND = "ffmpeg "
- SECOND_PASS_INPUT_OPTS = "-i "+ SECOND_PASS_INPUT +" "
- SECOND_PASS_SOUND_OPTS = "-acodec libvorbis -ac 2 -ab 192k "
- SECOND_PASS_VIDEO_OPTS = "-vcodec libx264 -preset slow -qp 28 "
- SECOND_PASS_SMP_OPTS = "-threads 0 "
- SECOND_PASS_OUTPUT = FIRST_PASS_OUTPUT.split(".", 1)
- SECOND_PASS_OUTPUT_FILE = SECOND_PASS_OUTPUT[0] + ".mp4"
- SECOND_PASS_OUTPUT_OPTS = SECOND_PASS_OUTPUT_FILE
- #ffmpeg -i witcherintro_1-2.mkv -acodec libfaac -ab 128k -ac 2
- #-vcodec libx264 -vpre slow -crf 22 -threads 0 our-final-product.mp4
- print "##################################################################################################"
- print "# Second Pass - Convert Capture to mp4 #"
- print "##################################################################################################"
- Command = SECOND_PASS_COMMAND + SECOND_PASS_INPUT_OPTS + SECOND_PASS_SOUND_OPTS + SECOND_PASS_VIDEO_OPTS + SECOND_PASS_SMP_OPTS + SECOND_PASS_OUTPUT_OPTS
- print Command
- os.system(Command)
- #os.system("rm " + SECOND_PASS_INPUT)
- #ffmpeg -i /var/tmp/portage/ScreenCast-Output.mkv -acodec libfaac -ab 96k -ac 2 -vcodec libx264 -vpre slow -crf 24 -threads 8 /var/tmp/portage/ScreenCast-Output-2.mp4
- # now lets attempt to fix rushing audio, delay of 2 seconds added
- # Split the Audio and Video from original File
- # ffmpeg -i break.flv -vcodec mpeg2video break-video.m2v -acodec copy break-audio.mp3
- print "##################################################################################################"
- print "# Split audio and video for rework #"
- print "##################################################################################################"
- Command = "ffmpeg -i "+SECOND_PASS_OUTPUT_FILE+" -vcodec copy SplitVideo-"+SECOND_PASS_OUTPUT_FILE+" -acodec copy SplitAudio-"+SECOND_PASS_OUTPUT_FILE
- print Command
- #os.system(Command)
- #To introduce the delay we need to use the -itsoffset option to offset one stream to sync with the other. Mostly you'll have delay in milliseconds, but to illustrate the option better, I'll assume there's a 10.2 second delay in the audio, that is you hear the gunshot after the bad guy has fired at the hero guy, and instead accidentally shot his bugle.
- #Video Delay Use This:
- #Command = "ffmpeg -i break-audio.mp3 -itsoffset 00:00:10.2 -i break-video.m2v bugle-still-dies.flv"
- #os.system(Command)
- #This will create a new FLV file that plays the audio just like it appears in the original file, but adds a 10.2-second delay in the video. Conversely, if your climax is ruined by the premature delivery of the last words of the hero, you can delay the audio to sync it with the video. Assuming the difference between the two is three milliseconds:
- #Audio Delay Use This:
- #Command = "ffmpeg -i SplitVideo-"+File+".mp4 -itsoffset 00:00:02.0 -i SplitAudio-"+File+".mp4 DelayAudio-"+File+".mp4"
- #print Command
- #os.system(Command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement