Guest User

script for subtitle adjusting

a guest
Dec 20th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. @echo off
  2.  
  3.  
  4. :: define suffix and language , for other languages, use 3-letter stream-representaion of language like eng for english,
  5. :: kor for korean , jpn for japanese and so on...
  6. set "srt_output_suffix=_synced"
  7. set "lang=eng"
  8.  
  9.  
  10. set "srt_output_suffix_eng=_%lang%%srt_output_suffix%"
  11. set "srt_extention=.srt"
  12. for /f "delims=" %%a in ("%~1") do set "Extension_1=%%~xa"
  13. for /f "delims=" %%a in ("%~1") do set "file_1_name=%%~na"
  14. for /f "delims=" %%a in ("%~2") do set "Extension_2=%%~xa"
  15. for /f "delims=" %%a in ("%~2") do set "file_2_name=%%~na"
  16.  
  17.  
  18. For %%A in ("%~1") do (
  19. Set file_1_p=%%~dpA
  20. Set file_1_p_full=%%~A
  21. )
  22.  
  23. For %%A in ("%~2") do (
  24. Set file_2_p=%%~dpA
  25. Set file_2_p_full=%%~A
  26. )
  27.  
  28.  
  29.  
  30. if %Extension_1%==%srt_extention% (
  31. ffprobe -show_entries stream=index,codec_type:stream_tags=language -of compact=p=0:nk=1 "%file_2_p_full%" -v 0 | grep %lang% | grep audio > output_audio_index.txt
  32. type output_audio_index.txt
  33. set /p audio_index= < output_audio_index.txt
  34. del output_audio_index.txt
  35. call :capture
  36. pause
  37. )
  38.  
  39. if %Extension_2%==%srt_extention% (
  40. ffprobe -show_entries stream=index,codec_type:stream_tags=language -of compact=p=0:nk=1 "%file_1_p_full%" -v 0 | grep %lang% | grep audio > output_audio_index.txt
  41. type output_audio_index.txt
  42. set /p audio_index= < output_audio_index.txt
  43. del output_audio_index.txt
  44. call :capture
  45. pause
  46. )
  47.  
  48.  
  49. goto:no_srt_found
  50.  
  51. :capture
  52.  
  53. set /A stream_index=%audio_index:~0,1%
  54. set /A ffmpeg_index=%audio_index:~0,1% -1
  55.  
  56. :: file no audio is found then perform the normal ffs command
  57.  
  58. if %stream_index%==-1 (
  59. echo "No %lang% stream is found..."
  60. echo "Using default ffs command"
  61. if %Extension_1%==%srt_extention% (
  62. ffs "%file_2_p_full%" -i "%file_1_p_full%" -o "%file_1_p%%file_1_name%%srt_output_suffix%.srt"
  63. echo Done
  64. pause
  65. )
  66.  
  67. if %Extension_2%==%srt_extention% (
  68. ffs "%file_1_p_full%" -i "%file_2_p_full%" -o "%file_2_p%%file_2_name%%srt_output_suffix%.srt"
  69. echo Done
  70. pause
  71. )
  72. ) else (
  73.  
  74.  
  75. echo %lang% stream is found...
  76. echo Using Stream #0:%stream_index%
  77.  
  78.  
  79. if %Extension_1%==%srt_extention% (
  80. ffs "%file_2_p_full%" -i "%file_1_p_full%" -o "%file_1_p%%file_1_name%%srt_output_suffix_eng%.srt" --reference-stream a:%ffmpeg_index%
  81. echo Done
  82. pause
  83. )
  84.  
  85. if %Extension_2%==%srt_extention% (
  86. ffs "%file_1_p_full%" -i "%file_2_p_full%" -o "%file_2_p%%file_2_name%%srt_output_suffix_eng%.srt" --reference-stream a:%ffmpeg_index%
  87. echo Done
  88. pause
  89. )
  90.  
  91. )
  92.  
  93.  
  94.  
  95. :no_srt_found
  96. ::print warning message if no srt file is detected
  97. echo "no srt file detected"
  98. pause
  99.  
Add Comment
Please, Sign In to add comment