Advertisement
Guest User

Untitled

a guest
Oct 9th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.72 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. #Author MetaPhaze
  5. #Use at your own risk license
  6.  
  7. import os
  8. import sys
  9. import time
  10.  
  11. OUR_TIME = ""
  12. TIME = ""
  13. NEW_TIME = ""
  14.  
  15. def GetTime():
  16.     TIME = time.ctime()
  17.     print TIME
  18.     NEW_TIME =  TIME.split(" ",5)
  19.     OUR_TIME = "-".join(["%s" % (v) for v in NEW_TIME])
  20.     NEW_TIME = OUR_TIME.split(":", 2)
  21.     OUR_TIME = "-".join(["%s" % (v) for v in NEW_TIME])
  22.     print OUR_TIME
  23.     return OUR_TIME
  24.  
  25. LineSeparator = os.linesep
  26. arg_count = len(sys.argv)
  27. doDir = 0
  28. OutputPath = ""
  29. Normalize = 0
  30.  
  31. FIRST_PASS_COMMAND = "ffmpeg "
  32.  
  33. FIRST_PASS_INPUT_SOUND_FORMAT = "-f alsa "
  34. FIRST_PASS_INPUT_SOUND_OPTS = "-ac 2 -ar 48000 -acodec pcm_s16le -ab 1536k "
  35. FIRST_PASS_OUTPUT_SOUND_FORMAT = "-ac 2 -ab 384k "
  36. # if plughw:1 doesn't work there are other choices
  37. # pulse
  38. # hw:0,0
  39. # hw:0
  40. # /dev/dsp
  41. # /dev/mixer
  42. FIRST_PASS_INPUT_SOUND_DEVICE = "-i hw:0 "
  43.  
  44. FIRST_PASS_INPUT_VIDEO_FORMAT = "-f x11grab "
  45. FIRST_PASS_INPUT_VIDEO_OPTS = "-i :0.0+0+0 " # remove +1280+1024 for full screen
  46. FIRST_PASS_OUTPUT_VIDEO_OPTS = "-vcodec libx264 -preset ultrafast -crf 0 "
  47. FIRST_PASS_OUTPUT_MAP = "" #"-map 0.0 -map 1.0:0.0 -async 1 "
  48.  
  49. FIRST_PASS_RATE_OPTS = "-r 30 -s 1920x1080 " # full screen at 2560x1024
  50. OUR_TIME = GetTime()
  51. FIRST_PASS_OUTPUT = "/home/metaphaze/ramdisk/ScreenCast-Output-"+ OUR_TIME +".mkv"
  52. print FIRST_PASS_OUTPUT
  53.  
  54. if arg_count == 1:
  55.  
  56. # ///////////////////////////////////////////////////////////////////////////////////////////////////////
  57. # /////////////////////////////////////// First Pass
  58. # ///////////////////////////////////////////////////////////////////////////////////////////////////////
  59.     print 'ScreenCapture'
  60.     print 'screencapture --help for help.'
  61.     print 'No options specified using defaults.'
  62.     print 'Capture Started, Press Q to quit.'
  63.  
  64.     #ffmpeg -s sxga -r 30 -f x11grab -i :0.0 -f alsa -ac 2 -i plughw:1
  65.     #-vcodec libx264 -vpre lossless_ultrafast
  66.     #-acodec flac -map 0.0 -map 1.0:0.0 -y /var/tmp/portage/witcherintro.mkv
  67.     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
  68.     print "##################################################################################################"
  69.     print "#                            First Pass - Capture Screen Output                                  #"
  70.     print "##################################################################################################"
  71.     print Command
  72.     print "##################################################################################################"
  73.     os.system(Command)
  74.  
  75.     print "##################################################################################################"
  76.     print "#                           Moving to temp file for work                                         #"
  77.     print "##################################################################################################"
  78.     SECOND_PASS_INPUT = "/home/metaphaze/ramdisk/ScreenCastConvert-" + OUR_TIME + ".mkv"
  79.     Command = "mv " + FIRST_PASS_OUTPUT + " " + SECOND_PASS_INPUT
  80.     print Command
  81.     os.system(Command)
  82.  
  83. # ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  84. # /////////////////////////////////////// Second Pass
  85. #////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  86.     SECOND_PASS_COMMAND = "ffmpeg "
  87.     SECOND_PASS_INPUT_OPTS = "-i "+ SECOND_PASS_INPUT +" "
  88.     SECOND_PASS_SOUND_OPTS = "-acodec libvorbis -ac 2 -ab 192k "
  89.     SECOND_PASS_VIDEO_OPTS = "-vcodec libx264 -preset slow -qp 28 "
  90.     SECOND_PASS_SMP_OPTS = "-threads 0 "
  91.     SECOND_PASS_OUTPUT = FIRST_PASS_OUTPUT.split(".", 1)
  92.     SECOND_PASS_OUTPUT_FILE = SECOND_PASS_OUTPUT[0] + ".mp4"
  93.     SECOND_PASS_OUTPUT_OPTS = SECOND_PASS_OUTPUT_FILE
  94.  
  95.     #ffmpeg -i witcherintro_1-2.mkv -acodec libfaac -ab 128k -ac 2
  96.     #-vcodec libx264 -vpre slow -crf 22 -threads 0 our-final-product.mp4
  97.     print "##################################################################################################"
  98.     print "#                           Second Pass - Convert Capture to mp4                                 #"
  99.     print "##################################################################################################"
  100.     Command = SECOND_PASS_COMMAND + SECOND_PASS_INPUT_OPTS + SECOND_PASS_SOUND_OPTS + SECOND_PASS_VIDEO_OPTS + SECOND_PASS_SMP_OPTS + SECOND_PASS_OUTPUT_OPTS
  101.     print Command
  102.     os.system(Command)
  103.  
  104.     #os.system("rm " + SECOND_PASS_INPUT)
  105.  
  106.     #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
  107.  
  108.     # now lets attempt to fix rushing audio, delay of 2 seconds added
  109.     # Split the Audio and Video from original File
  110.     # ffmpeg -i break.flv -vcodec mpeg2video break-video.m2v -acodec copy break-audio.mp3
  111.     print "##################################################################################################"
  112.     print "#                           Split audio and video for rework                                     #"
  113.     print "##################################################################################################"
  114.     Command = "ffmpeg -i "+SECOND_PASS_OUTPUT_FILE+" -vcodec copy SplitVideo-"+SECOND_PASS_OUTPUT_FILE+" -acodec copy SplitAudio-"+SECOND_PASS_OUTPUT_FILE
  115.     print Command
  116.     #os.system(Command)
  117.     #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.
  118.     #Video Delay Use This:
  119.     #Command = "ffmpeg -i break-audio.mp3 -itsoffset 00:00:10.2 -i break-video.m2v bugle-still-dies.flv"
  120.     #os.system(Command)
  121.  
  122.     #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:
  123.     #Audio Delay Use This:
  124.     #Command = "ffmpeg -i SplitVideo-"+File+".mp4 -itsoffset 00:00:02.0 -i SplitAudio-"+File+".mp4 DelayAudio-"+File+".mp4"
  125.     #print Command
  126.     #os.system(Command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement