Wikipedia:Reference desk/Archives/Computing/2022 May 12

Computing desk
< May 11 << Apr | May | Jun >> May 13 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


May 12

edit

Extracting the subtitles of an MP4 video

edit

I'm looking for a free app running on macOS Mojave (i.e. pre-64 bit) to export the subtitles of an MP4 video as a text file in the .srt format. I downloaded and installed several apps that promised they would do this, but could not get them to work, like there was a menu entry "Export SRT", but greyed-out. Does anyone have an experience of actually doing this successfully?  --Lambiam 11:54, 12 May 2022 (UTC)[reply]

I assume these are not hardcoded subs but are they subpicture or text? If you're not sure, consider that a decent video player should have an option for the font etc for text subtitles which would include overriding any font specified in the subtitles in the unlikely event there is, but this won't work for subpicture subtitles for obvious reasons. It also won't work for hardcoded subtitles but you should already know they are hardcoded since they can't be disabled in a decent player (which can disable even forced subtitles). Nil Einne (talk) 12:29, 12 May 2022 (UTC)[reply]
These are purely textual subtitles that can be toggled on and off by a CC button. I suppose the subtitle component of the video has the ISO 14496-17 format mentioned at MPEG-4 Part 17, but I don't know how such streams are encoded in the binary form of the .mp4 format, and also not how this ISO subtitle format relates to the .srt format. I know how to add a plain text file with .srt-style subtitles to a video without subtitles. Now I want to go the other direction and extract such an added subtitle stream as a plain text file.  --Lambiam 13:45, 12 May 2022 (UTC)[reply]
I use kdenlive. It lets you import/export/edit subtitles. I know it runs on Linux and Windows. I don't see why it won't run on MacOS. 97.82.165.112 (talk) 15:27, 12 May 2022 (UTC)[reply]
Thanks. I installed kdenlive, but it won't let me use "Add Clip" to add an MP4 video to an empty new project – the .mp4 file type is treated as "not supported". Browsing the forums I see I'm not the only one with the problem, but I saw no proposed remedies. The screen shots in the tutorial are rather different from what I see on my screen.  --Lambiam 19:46, 12 May 2022 (UTC)[reply]
I've only used FFmpeg to remove unwanted textual subtitle streams (or to bake in a .srt), but it seems it can extract them back to an .srt file - according to this superuser.com post, the command line is:
          ffmpeg -i Movie.mkv -map 0:s:0 subs.srt
If you don't have a working FFmpeg install, it seems MacOS users install it, and other free software, with brew. -- Finlay McWalter··–·Talk 16:06, 12 May 2022 (UTC)[reply]
Thanks. I tried
ffmpeg -i my.mp4 -map 0:s:? subs.srt
but got an error message Output file #0 does not contain any stream.  --Lambiam 21:29, 12 May 2022 (UTC)[reply]
And when I try ffmpeg -i my.mp4 -map 0:? subs.srt, the message is, Automatic encoder selection failed for output stream #0:0. Default encoder for format srt (codec none) is probably disabled. Please choose an encoder manually. Error selecting an encoder for stream 0:0.  --Lambiam 21:34, 12 May 2022 (UTC)[reply]
ffprobe -i my.mp4 will list all the stream in the file; if there isn't a subtitle stream listed there, then there isn't one. I found a file that had subtitles. ffprobe says
          Stream #0:2: Subtitle: subrip (default)
and doing
          ffmpeg -i my.mp4 -map 0:s:0 subs.srt
(note still 0:s:0 not 0:s:2 or 0:s:?) extracts the subtitles correctly. -- Finlay McWalter··–·Talk 21:47, 12 May 2022 (UTC)[reply]
Question: do the subtitles (as shown on screen) have fancy formatting (beyond plain text)? That is, do they have different fonts, and particularly different colours (such as different people being subtitled in different colours)? If so, they may be in SubStation Alpha (ASS or SSA) format, rather than srt. I've no experience of these (I think it's mostly used for subtitling Anime stuff). It may be necessary to install the relevant library, the appropriately named libass -- Finlay McWalter··–·Talk 22:44, 12 May 2022 (UTC)[reply]
I note that the Substation Alpha article links to a MacOS program called subler which seems to know a lot of about subtitle formats. Whether the issue is ASS or something else, I'm thinking your problem may be that the subtitles are encoded with some other format - hence the tools you've tried not recognising it, and being unable to extract. -- Finlay McWalter··–·Talk 22:54, 12 May 2022 (UTC)[reply]
If using FFmpeg and getting unexpected output like the OP, I would suggest starting off with listing streams. While I don't use FFmpeg much, from my experience it's easily possible to have problems because the command line you copied is designed for a stream config which isn't how your file is organised. Nil Einne (talk) 06:46, 13 May 2022 (UTC)[reply]
The errors you mention with multiple programs indicate that you do not have the video codec installed on your computer. Note that mp4 is a container format. It can contain video, audio, images, and text of many different formats. It is possible you do not have the mp4 codec installed. It is possible that your mp4 file contains something you do not have a codec for. Because multiple programs report that it cannot open the file or that when it tries to do so, it gets an empty video/audio stream, I would begin with what they all have in common, which is the codec used to open the file. 97.82.165.112 (talk) 00:38, 13 May 2022 (UTC)[reply]
This is incredibly unlikely since FFMPEG does not generally use external codecs, and indeed has limited support of such. It definitely does not need them to understand the MP4 container or for that matter to CPU decode or encode the video codecs generally encountered in them. Nil Einne (talk) 06:09, 13 May 2022 (UTC)[reply]