2015年10月21日水曜日

IkaLogの自動録画機能を自分好みにしてみたメモ

はじめに

ここに書かれてある情報は、個人的に行った改造になりますので、この情報を元に作者の方に問い合わせはしないでください。

お約束ですが、手を入れると今まで動いていたものが動かなくなってしまう可能性もありますので、ご自身の判断でイカよろしくお願い致します。

IkaLogの自動録画機能を自分好みにしてみました

自分が使いやすいように、 IkaLog (WinIkaLog20151022_065159_43e0ca0) に同梱されていた ControlAmarecTV.au3 に少し手を入れてみました。

自分で使えたらいいや的な対応なので、わたしが知らないだけで、もっと良い方法があるのかも知れません。
その時は教えて頂けたらありがたいです。



手動でアマレコTVの録画を録画するために、こんな感じで録画開始にF11キー、録画停止にF12キーを割り当てています。


この設定に合わせてスクリプトに少し手を入れてみました。

;
;  IkaLog
;  ======
;  Copyright (C) 2015 Takeshi HASEGAWA
;
;  Licensed under the Apache License, Version 2.0 (the 'License');
;  you may not use this file except in compliance with the License.
;  You may obtain a copy of the License at
;
;      http://www.apache.org/licenses/LICENSE-2.0
;
;  Unless required by applicable law or agreed to in writing, software
;  distributed under the License is distributed on an 'AS IS' BASIS,
;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;  See the License for the specific language governing permissions and
;  limitations under the License.

;
;  Start and stop recording using Open Broadcaster Software(OBS).
;
;  To Start Recording:
;    ControlAmarecTV.au3 start
;
;  To Stop Recording:
;    ControlAmarecTV.au3 stop
;
;  To Reanem the recording:
;    If you want to rename the recording to a specific filename,
;    Specifcy the filename as environment variables
;    IKALOG_MP4_DESTDIR and IKALOG_MP4_DESTNAME.
;
;  Though this script will sleep seconds so that work on
;  a specific environment. The behavior is subject to change.
;

#include 
#include 

Func RenameFile($source)
 Local $dest = EnvGet('IKALOG_MP4_DESTNAME')
 $dest = StringReplace($dest, "/", "\")
 If $dest = '' Then
  Return False
 EndIf

 ; IkaLog assumes mp4 as video file extension, but AmarecTV uses avi.
 If StringRight($dest, 4) = ".mp4" Then
  $dest = StringReplace($dest, ".mp4", ".avi", -1)
 EndIf

 FileMove($source, $dest, $FC_OVERWRITE)
EndFunc

Func FindRecentRecording()
 Local $directory = EnvGet('IKALOG_MP4_DESTDIR')

 ; Replace all slashes to backslashes.
 ; $directory also needs a backslash at its end.
 $directory = StringReplace($directory, "/", "\")
 If StringRight($directory, 1) <> "\" Then
  $directory = $directory & "\"
 EndIf

 Local $hSearch = FileFindFirstFile($directory & "*.avi*")

 If $hSearch = -1 Then
  MsgBox(0, "Error", "Could not find any candinates in " & $directory & " (path 1)", 10)
  Return False
 EndIf

 Local $latest_file = ''
 Local $latest_timestamp = ''

 While True
  Local $file = FileFindNextFile($hSearch)
  If @error Then ExitLoop

  Local $timestamp = FileGetTime($directory & $file, $FT_MODIFIED, $FT_STRING)
  If StringCompare($timestamp, $latest_timestamp) > 0 Then
   $latest_file = $directory & $file
   $latest_timestamp = $timestamp
  EndIf
 WEnd

 FileClose($hSearch)

 If $latest_file = '' Then
  MsgBox(0, "Error", "Could not find any candinates in " & $directory & " (path 2)", 10)
  Return False
 EndIf

 Return $latest_file
EndFunc

Func ControlAmarecTV($stop)
 Local $hWnd = WinWait('[CLASS:AmaRecTV; INSTANCE:2]', '', 1)

 If $hWnd = 0 Then
  MsgBox(0, "Error", "Could not find AmarecTV")
  Return False
 EndIf

 Local $text = ControlGetText($hWnd, "", "[CLASS:msctls_statusbar32]")
 Local $inRecording = StringInStr($text, '録画中...') > 0

 Local $click = False
 If $inRecording and $stop Then
  ; Stop Recording.
  $click = True
 ElseIf (Not $inRecording) and (Not $stop) Then
  ; Start Recording.
  $click = True
 EndIf

 If $click Then
  If $stop Then
   ; 録画停止待ち時間を10.6秒に変更
   Sleep(1000 * 10.6)
   Else
   ; 録画開始待ち時間を4.4秒追加
   Sleep(1000 * 4.4)
   EndIf

  ; Send Ctrl-Z

  WinActivate($hWnd)
  WinWaitActive($hWnd, "", 1)

  ;send("^z") --コメントアウト

  ;
  ;アマレコTVの録画開始をF11,停止をF12に設定してあります。
  If $stop Then
   ; 録画停止キー(F12)送る
   send("{f12}")
   Else
   ; 録画開始キー(F11)送る
   send("{f11}")
  EndIf

  ;ファイル名の変更は行わないのでコメントアウト
  ; If $stop Then
  ;  Sleep(1000 * 10)
  ;  Local $file  = FindRecentRecording()
  ;  RenameFile($file)
  ; EndIf
 EndIf
EndFunc

$stop = StringCompare($CmdLine[1], 'stop') == 0
ControlAmarecTV($stop)


※ 録画停止後のファイル名変更機能は、使わないのでコメントアウトしています。
※ 環境と好みによって、待ち時間を変更する必要があると思います。

変更後の動作確認は、アマレコTVを起動して(何もいいので)映像が流れている状態で、コマンドプロンプトから
"C:\IkaLog\tools\ControlAmarecTV.au3 start" で、4.4秒後に録画開始され

"C:\IkaLog\tools\ControlAmarecTV.au3 stop" で、10.6秒後に録画停止されたら大丈夫っぽいです。

こんな感じです。












※ お使いの環境により、アプリケーションと拡張子の関連付けが必要になるかもしれません。
OSは、Windows10 Pro を使っています。

後は、IkaLogを起動して普通にスプラトゥーンを遊んだ後で、実際に録画出来ているか確認すれば完了です。
アマレコTVの標準機能で、録画の開始・停止で音が鳴る設定があるので、それを使えばいいかなと思います。

アマレコTVで録画したファイルは、サイズが4GB~4.8GBくらいあるので、AviUTLを使って1/8くらいにサイズを落として、 Free YouTube Uploader というソフトでYouTubeへまとめてアップロードした後、削除しています。

IkaLogの自動録画機能を使うと、こんな感じの動画が、手放しで録画できるようになります!

0 件のコメント:

コメントを投稿