Categories
Windows

A batch file of VLC for hardcoding subtitles to each mp4 on Windows.

   Recently, I needed to merge some mp4 files and srt files. If you only need to merge, it is very easy way you have. That is to use MP4Box. But I needed a hardcord subtitle version this time. I think MP4Box cannot give this type. Am I right? Anyway I couldn’t create a mp4 file with a hardcord subtitle by MP4Box, so I was searching for information and found this out on YouTube. It’s very nice. But, this time I had mp4 files more than twenty and have to set this about each mp4 file if I use VLC GUI. It’s very inconvenient. So I wrote a batch file as below.
   For VLC batch file transcode information, see Transcode – VideoLAN Wiki.

setlocal enabledelayedexpansion

set VLCEXE="C:\Program Files\VideoLAN\VLC\vlc.exe"
set InputFileExtension=mp4
set OutFolder=

pushd %~dp0
if "!OutFolder!" NEQ "" (
	if not exist "!OutFolder!" (
		mkdir !OutFolder!
	)
)
set Dist=!OutFolder!
for %%a in (%*) do (
	if %%~xa==.!InputFileExtension! (
		if "!OutFolder!"=="" set Dist=%%~dpa
		cmd /c
		!VLCEXE! -I dummy -vvv %%a --sout #transcode{vcodec=h264,scale=auto,acodec=mpga,ab=128,channels=2,samplerate=44100,soverlay}:file{dst=!Dist!\sub_%%~na.mp4,no-overwrite} :no-sout-all :sout-keep vlc://quit
	)
)
popd
exit

   After I did my job, I add some improvement to the batch.

[How to use]

  1. Copy & paste the above codes to a text editor, and save it as a batch file named ‘hardecoding_subs_by_vls.bat’ or something. You can have ‘hardecoding_subs_by_vls.txt’ from here. Change its extension from txt to bat.
  2. Place hardecoding_subs_by_vls.bat to somewhere in your PC and create its shortcut file on your Desktop.
  3. Of course, you need a mp4 file and a srt file😁. A pair of them need to have the same name, for example ‘sample.mp4’ and ‘sample.srt’. The files have to exist in the same folder.
  4. For transcoding, do Drag&Drop about a mp4 file/mp4 files to the batch file short cut.
  5. To transcode takes approximately the same time as the mp4 length. So if you have a lot of mp4 files, you must wait for a long time.

About the batch file options.

  • VLCEXE=”C:Program FilesVideoLANVLCvlc.exe”
    If you install 32-bit version VLC on Windows 64-bit, change to VLCEXE=”C:Program Files (x86)VideoLANVLCvlc.exe”.
  • The meaning of InputFileExtension=mp4 is literal😁.
  • OutFolder=
    The default is blank. When you leave it blank, the hardcoded sub mp4 file is created in the same folder about the original mp4 file.
    If you set a destination to it, for example OutFolder=D:subfiles, all the hardcoded sub mp4 files are created in D:subfiles. But the batch file does not check mp4 file names, so it overwrites the same name files if you set a destination. Be careful about it.
同一記事の日本語版

Leave a Reply

Your email address will not be published. Required fields are marked *