2013年11月27日 星期三

MPEG-2 encoding with ffmpeg

   Recently, I used FreeStudio to encode my video. It's a really excellent and convenient to encode and convert many kind of video formats. I did enjoy using it. However, for some reason, I like to convert my video to its long play MPG format. In that case, FreeStudio makes assumption to build DVD format for burning DVD, if I choose converting video to MPG format. The assumption is inconvenient to me, if I like to convert multiple video at the same time, the multiple video may be merged into one or more VOB files. That's not what I want.
    Therefore, I tried to find command and fortunately I found ffmpeg in its DLL folder. FFMpeg is an open source project which do excellent job in video convert. That's originally used in Linux, but it was ported to Windows as well. After google, I found a good starting article for the parameters to use in ffmpeg. You may refer to the document as below:
 
    In the article, the author suggests some options. If you like to convert mp4 to mpg with better quality. I tried and those input arguments are good choice to use, though I can only share I feel that video and audio quality are both improved.
ffmpeg -i test.mp4 \
    -vcodec mpeg2video -pix_fmt yuv420p -me_method epzs -threads 4 \
    -r 29.97 -g 15 -s 704x396 -b 2500k -bt 300k \
    -acodec mp2 -ac 2 -ab 192k -ar 44100 \    
    -async 1 \    
    -y \    
    -f vob output.mpg

  Below options were what I used before reading the article. With the options, ffmpeg generates smaller size of video file but poorer quality. I can felt the blocking effect and flat sound. Anyway, if the size is what you care about, you may use simpler options to encode your video.
ffmpeg -i test.mp4 \
    -r 29.97 -s 384x240 -b 2150k output.mpg

I created one .vbs file(mp4_mpg.vbs) to do the batch conversion. It's simply to read mp4 files in input folder and to generate converted file in output folder.  you may copy below codes into a .vbs file to simplify your job.
'//==================================================================
'// Author: Richard Tsai
'// Date: 2013/11/25
'// Objective: the script is to encode mp4 to dvd long play format
'// for car video system, which is video rate=2.15Mb, fps = 29.97, resolution = 352.240
'//==================================================================


'//======================================================
'// Constant Declaration
'//======================================================
FPS = 29.97
RESOLUTION = "352x240"
VIDEO_BIT_RATE = 2150000
AUDIO_BIT_RATE = "192k"
OTHER_VIDEO_OPTIONS = " -vcodec mpeg2video -pix_fmt yuv420p -me_method epzs -threads 4 -g 45 -bf 2 -trellis 2 -cmp 2 -subcmp 2 "
OTHER_AUDIO_OPTIONS = " -acodec mp2 -ac 2 -ab " & AUDIO_BIT_RATE & " -ar 44100 -async 1 "

'//======================================================
'// Scripting Components
'//======================================================
Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")

'//======================================================
'// Arguments check
'// vwscript.echo "count=" & WScript.Arguments.Count
'//======================================================
If WScript.Arguments.Count<1 then
   WScript.echo "Usage: " & vbcrlf & "   Cscript mp4_mpg.vbs <Input Folder> {<Output Folder>}"
   WScript.quit
end if 

'//======================================================
'// input / output folders
'//======================================================
inputFolder = WScript.Arguments.Item(0)
outputFolder = ".\output"

If WScript.Arguments.Count>1 then
   outputFolder = WScript.Arguments.Item(1)
end if

if (not fso.FolderExists(outputFolder)) then 
  '// check existence of folder
  Wscript.echo "Create folder " & outputFolder
  fso.createFolder(outputFolder)
end if 

'//======================================================
'// go on anyway for any exception
'//======================================================
on error resume next

'//======================================================
'// for loop all files in the folder
'//======================================================
index = 1
For Each f In fso.GetFolder(WScript.Arguments.Item(0)).Files
  If LCase(fso.GetExtensionName(f)) = "mp4" Then
 '// if you want to decide whether File object is a file or not, you may use f.attributes and 16 for a folder
 '// http://smorgasbork.com/component/content/article/35-linux/97-real-time-mpeg-2-encoding-with-ffmpeg
 'ffmpeg -i test.mp4 \
    '-vcodec mpeg2video -pix_fmt yuv420p -me_method epzs -threads 4 \
    '-r 29.97 -g 45 -bf 2 -trellis 2 -cmp 2 -subcmp 2 -s 704x396 -b 2500k -bt 300k \
    '-acodec mp2 -ac 2 -ab 192k -ar 44100 \    
    '-async 1 \    
    '-y \    
    '-f vob output.mpg
 command = "dll\ffmpeg -i """ & fso.GetAbsolutePathName(f) & """" & _
      OTHER_VIDEO_OPTIONS & _
      OTHER_AUDIO_OPTIONS & _
                     " -y -b " & VIDEO_BIT_RATE & _
      " -r " & FPS & _
      " -s " & RESOLUTION & _
      " """ & outputFolder & "\" & fso.getBaseName(f) & ".mpg"""

 '// print out status
    Wscript.echo "[" & index & "] " & command
 index = index + 1
 
 '// Run encoding
 '//shell.exec(command)
 shell.run command, 0, true
  End If
Next

To execute it, you can press
 Cscript mp4_mpg.vbs <Input Folder> {<Output Folder>}
I hope the article can help you to get started with ffmpeg and share my experience about it.

2013年11月11日 星期一

How to configure Oracle Weblogic 10.3 to consume web service over HTTPS/SSL


   If your system runs on Oracle Webloigc and like to consume external web service over HTTPS, you may have handshake exception problem. To resolve the issue, you may follow the following steps

1) Export certificate from the web service endpoint provider by browser. 
   1a) click the key icon, select Certificate Information.


   1b) Select Base-64 encoding X.509(.CER) format and export the certificate to xxx.cer




2) Create key store and move the keystore file under domain folder:
2.a) keytool -importcert -keystore xxx.jks -trustcacerts -file xxx.cer -storepass p@ssw0rd
2.b) cp xxx.jks $(domain)/jks


3) Add some java options in setDomainEnv.sh
JAVA_PROPERTIES="-Dplatform.home=${WL_HOME} -Dwls.home=${WLS_HOME} -Dweblogic.home=${WLS_HOME} -Dweblogic.nodemanager.sslHostNameVerificationEnabled=false -Dweblogic.security.SSL.allowSmallRSAExponent=true -Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol -Dssl.SocketFactory.provider=com.sun.net.ssl.internal.SSLSocketFactoryImpl -DUseSunHttpHandler=true -Dweblogic.wsee.client.ssl.usejdk=true"

4) Configure keystores in admin console 


5) Restart Weblogic