软字幕

软字幕

目前正在尝试将我的 mkv 库转换为 mp4 (Iphone 6 plus)

我已经成功将 mkv 正确转换为 mp4,但缺少字幕部分(SRT)

这是我的代码:

dir/b/s *.mkv >mkvlist.txt   ///////// this gets a list of all the mkv files on the directory

for /F "delims=;" %%F in (mkvlist.txt) do ffmpeg.exe  -i "%%F" -format mp4 -vcodec copy -acodec aac -strict -2 -sn "%%~dF%%~pF%%~nF.mp4"   ///////////// this makes the conversion

del mkvlist.txt     ////// this deletes the txt file

我想将字幕包含在脚本中,但是在将字幕的正确名称插入脚本时遇到了问题(因为这是一个多次转换批次)。

答案1

MP4 不支持 SRT。您可以使用软字幕或硬字幕。

软字幕

字幕作为文件中的单独流。它们可以由播放器打开/关闭,并且不需要对视频流进行重新编码。

ffmpeg -i input.mkv -c copy -c:s mov_text output.mp4

MP4 播放器对定时文本软字幕的支持可能相当差。你得试试。

硬字幕

硬字幕被“刻录”到视频中,因此必须对视频重新编码。

ffmpeg -i input.mkv -vf subtitles=input.mkv output.mp4

查看subsbtitles 过滤器文档了解更多信息,例如如果有多个字幕流,如何选择特定的字幕流。

答案2

我在用 Handbrake 翻录的一些 mp4 文件从 MP4 转换为 MKV 时也遇到了类似的问题。我首先咨询了 https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/subtitle_options,这意味着 mkv 和 mp4 有特定的字幕格式。在尝试了 ass 和 mov_text 转换但都不起作用后,我测试了一些文件,发现出现了 dvd_subtitle 格式。经过多次尝试,以下方法终于奏效了。

ffmpeg -i "\\server\directory\Sourcefile.mp4" -c:v copy -c:a copy -c:s dvd_subtitle "\\server\directory\Outputfile.mkv"

希望能帮助到你。

答案3

我希望这可以帮助您实现流程自动化。此代码将 .mp4 视频和 .srt 字幕文件转换为带有嵌入字幕的 .mkv 文件。

批处理文件。

只需同时放入 2 个文件 - .mp4 和 .srt 即可获得带有嵌入字幕的 .mkv 视频。

如果您想要原始/低视频质量,只需注释/取消注释代码中的相应行。

除其他事项外,我还异步调用了 msgBox。谁需要它 - 将其复制到您的来源。

由于某种原因,它不接受文件名中的括号 ()。我没有检查其余字符。

    @echo off
    if "%~x1"==".mp4" (
        set mp4=%~n1
        set path=%~d1%~p1
    )
    if "%~x2"==".mp4" (
        set mp4=%~n2
        set path=%~d1%~p1
    )
    if "%~x1"==".srt" set srt=%~1
    if "%~x2"==".srt" set srt=%~2
    if not "%mp4%"=="" (
        if not "%srt%"=="" (
            :: If your original ffmpeg.exe file located in system32 directory then replace "%~dp0ffmpeg.exe" to ffmpeg
            :: original quality
            ::"%~dp0ffmpeg.exe" -i "%path%%mp4%.mp4" -i "%srt%" -ar 48000 -vcodec libx264 -disposition:s:0 default -scodec copy "%path%%mp4%.mkv"
            :: low quality
            "%~dp0ffmpeg.exe" -i "%path%%mp4%.mp4" -i "%srt%" -ar 48000 -ab 128k -ac 2 -vcodec libx264 -s 480x240 -b 256k -disposition:s:0 default -scodec copy "%path%%mp4%.mkv"
            call :msgbox "File %path%%mp4%.mkv completed."
        ) else call :msgbox "File .srt missing in the input parameters`r`nJust drop 2 files with extensions:`r`n.mp4 - video and .srt - subtitles`r`nto this batch file to get .mkv with subtitles"
    ) else call :msgbox "File .mp4 missing in the input parameters`r`nJust drop 2 files with extensions:`r`n.mp4 - video and .srt - subtitles`r`nto this batch file to get .mkv with subtitles"
    goto :eof
    :msgBox [msgText]
    C:\Windows\System32\mshta.exe vbscript:Execute("CreateObject(""WScript.Shell"").Run ""powershell -Command """"[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')|Out-Null;"""" """"[System.Windows.Forms.MessageBox]::Show(\""""%~1\"""")"""""",0,false:close")
    exit /B

相关内容