Extract Subtitles From Dvd Ffmpeg

  1. Ffmpeg Copy Subtitle
  2. Ffmpeg Extract Subtitle From Mkv
  3. Extract Subtitle From Mp4

Subtitles are pretty much the same. The subtitles will be printed in the info and then you can extract them, similar to: ffmpeg -threads 4 -i VIDEO.mkv -vn -an -codec:s:0.2 srt myLangSubtitle.srt. 0.2 is the identifier that you have to read from the info. SOLUTION 3: The following script extracts all audio streams from files in current directory. To extract subtitles from.mp4 files that have subtitles embeded you can use the command line tool ffmpeg. To install it use: sudo apt install ffmpeg (on older ubuntu use sudo ap-get install ffmpeg. Then use the following syntax from within the right folder. You can extract or convert those subtitles. To convert to srt from dvbteletext. Ffmpeg -txtformat text -i inputfile out.srt Your FFmpeg needs to be configured with -enable-libzvbi for this to work, and results in something like this.

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址:https://www.aliyun.com/minisite/goods

I have checked the FFMpeg documentation and many forums and figured out the correct command-line to extract subtitles from an .MP4 video should look like so:

However, I get the following error, which lends me to question whether this is feasible at all:

Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Using ffmpeg -codecs, I can confirm that ffmpeg should be able to encode subrip subtitles.

Using ffmpeg -i video.mp4, I can see that there is two subtitle tracks embedded in the video :

EDIT

Extract

I have tested with the simplified command-line shown in the comments but I still get the same error. Here is a link to the detailed verbose output from running the command. I have also tried to completely disable metadata and chapters in the resulting output but that still produces the same error.

ffmpegextractsubtitlesrt
|
this questionedited Dec 19 '13 at 13:43 asked Dec 19 '13 at 8:41 Maxime Labelle 2,286 1 14 39 3 Simple ffmpeg -i in.mp4 out.srt works for me correctly. (ffmpeg 2.0.1) – pogorskiy Dec 19 '13 at 9:17 Try ffmpeg .. -loglevel debug .. to get more info about error – pogorskiy Dec 19 '13 at 9:20 I have tries both suggestions, but I cannot identify an obvious mistake. Perhaps this is caused by ffmpeg trying to output chapter markers in the resulting srt file? I have including the detailed debug output. – Maxime Labelle Dec 19 '13 at 13:35 1 Can't see anything obvious either, but maybe try a more recent version from ffmpeg.org/download.html and use ffmpeg -i video.mp4 -map 0:s:0 output.srt to only use the first subtitle stream for your output. (By the way, ffmpeg CLI questions are off topic for SO, so I've voted to move it to Super User.) – slhck Dec 19 '13 at 13:50 Sorry about the off-topic nature of my post. I'll make sure to ask those kinds of questions in SU. I'll try a more recent build of ffmpeg. Cheers. – Maxime Labelle Dec 19 '13 at 13:55 | show more comment

3 Answers
3

I enventually figured out why I did not succeed:

The specified command-line would have been perfectly fine if the subtitles from the source video were encoded in a text-based representation. However, as can be seen in the output to the ffmpeg -i command-line, the subtitles are encoded in the 'dvd_subtitle' format.

The dvd_subtitle format stores bitmaps for each subtitle in the video. Therefore, there is no way ffmpeg would be able to translate the bitmaps into text.

For this task, one has to resort to an OCR-based software which assists a user with the task of identifying each subtitle as text from its bitmap représentation.

Recommend:c++ - How to extract elementary video from mp4 using ffmpeg programmatically

deo to mp4 using h264/AVC codec. The main scheme is something like that: -open input -demux -decode -encode -mux The actual code is below: #include <iostream>#include <math.h>extern 'C' {#ifndef __STDC_CONSTANT_MACROS#undef main /* Pr

(There is a secondary text-based subtitle in the source video, but I don't know where it came from and is not seen by most popular players. For all intents and purposes, this 'mov_text' subtitle seems to be a stub placeholder, probably an artifact of the conversion from the original DVD) Heroes gods and monsters pdf.


Extract |
this answer answered Jan 2 '14 at 16:52 Maxime Labelle 2,286 1 14 39 I think that text track is the chapter markers, not sure though. – mcdado Jul 8 '14 at 10:04 |

Just FYI, (Can't comment due to rep yet), but extracting SRT from an MP4 will result in a file formatted as MOV_Text not the regular SRT. It will still get added and work but its like changing mp4 to m4v. While it usually works, things don't work the same in the code. Mov_text is horrible for manually adjusting font/size etc etc. Best bet is to download and test an SRT from the web!

This will work, but will result in mov_text coded srt file:


|

Ffmpeg Copy Subtitle


this answer answered Oct 15 '15 at 5:59 FreeSoftwareServers 330 2 11 |

Try using map option.. if there are too many streams in input files..

Syntax would be:

ffmpeg -i video.mp4 -map 0:4 out.srt

Since there are two subtitle streams in your video, first on 0:3 which is dvdsubtitle so cannot be converted to srt so we will convert second subtitle on 0:4 stream which is mov_text and is soft copy of subtitle so can be easily converted..


|

Ffmpeg Extract Subtitle From Mkv


this answer answered Feb 4 at 7:35 Manthaar Janyaro 1 |

Recommend:extract - Error while extracting subtitle from mkv or m2ts to srt with FFmpeg

ideo). I tried a lot of variant i found with google. But every time i get this error: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height I think, this error means that ffm

Some music audio only titles are just becoming available on Blu-Ray, and music lovers may need to extract the audio to another portable medium. Since the Blu-Ray audio is usually one big file, the file chapters need to be found and split. Most portable media requires VFAT filesystem preventing larger files sizes, and further splitting is essential.

This article will only discuss unencrypted Blu-Ray Audio media, and merrily point users to MakeMKV (media-video/makemkv) for handling encrypted Blu-Ray media.

Important
Copying copy righted material not purchased by you or material you do not hold a license is a crime. Some Countries may be more strict, and consider simply tampering with encrypted material a crime. Funny things may also occur if you tinker with encrypted Blu-Rays, such as blacklisting. ;-)
Note
Audio ranges greater than 24 bits or 480000 Hz are frequently stated as being indistinguishable to the human ear. As for me, I notice little difference between 16 and 24 bit, or 44100 and 48000 Hz of noisy music.
Note
Encrypted (or commercial) Blu-ray media is extremely difficult to enjoy within Linux, as MPlayer's libaacs rarely works when playing encrypted Blu-ray media. Also anything higher than the common 16 bit 44100 Hz (CD Audio Quality), and you will require a Home Theater or 5.1/7.1 Dolby/DTS Audio Receiver with more than five quality speakers to decode and be able to notice a difference above CD audio quality. Receivers also have the ability to copy stereo two channel into five or more channel audio, sounding extremely similar to 5.1 PCM. If you're an older person and dislike having to always buy additional equipment to be able to enjoy these newer proprietary formats, it has been quite common when considering Blu-ray media, to continue using only the tried and well tested CD and DVD media!

Install Required Packages

Although MPlayer can also be used, FFmpeg seems more refined when dumping or clipping specific audio chapters from DVD or Blu-Ray media.

(If somebody successfully uses MPlayer/MPlayer2 to dump PCM specified chapters, feel free to add it to this Wiki page and retitle appropriately. I've only experienced MPlayer seeking to the beginnning chapter and, not recognizing or stopping at the specified end chapter. ie. 'mplayer -ao pcm:fast:file=audio.wav -chapter 2-2 -vo null -vc null input_file')

Mount Blu-Ray Disc

Blu-Rays use UDF, and require to be mounted as such. Probably best to edit the following file to provide mount points as such. (I use AutoFS, so incorporate as needed.)

FILE/etc/fstab

Or the following will automatically decide with little to no additional access time difference,

Create the mount folders if you don't have them already,

Mount the disc,

Find Available Stream Types

You've likely found your main large media stream file on your Blu-Ray, something similar to ./BDMV/STREAM/0000.m2ts.

Using ffplay, you'll likely see something like this within stdout,

Extract Subtitle From Mp4

Keep an eye on the Hz, s16/s24/s32 and kb/s, as they're indicators of audio quality.

Extract Audio Streams

Extract Full Audio Streams

To extract the three individual stream types into one large file, you can use FFmpeg. (Although this is likely undesirable due to file size limitations on VFAT filesystems.)

user $ffmpeg -i ./BDMV/STREAM/00000.m2ts -map 0:1 -acodec pcm_s24le music.wav
user $ffmpeg -i ./BDMV/STREAM/00000.m2ts -map 0:2 -acodec pcm_s24le music-pcm51.wav
user $ffmpeg -i ./BDMV/STREAM/00000.m2ts -map 0:3 -acodec copy music.dts

Verify you have successfully extracted the streams using ffplay or mplayer. Monitor the stdout messages to ensure proper drivers and codecs are used for the stream types specified.

(For DTS playback using MPlayer, you'll likely need to specify ac=hwdts for MPlayer for passing through DTS to your HDMI/SPDIF audio receiver. MPlayer uses the following for specifying streams, 'mplayer -aid 1 -demuxer lavf ./BDMV/STREAM/00000.m2ts'.)

Devices with only 16 Bit Microsoft PCM Audio Support

Some audio receivers and devices will only play 16 bit Microsoft PCM WAV files! If you have 24 bit audio files as indicated above and such hindered devices, you will need to unfortunately down mix in order for the files to be playable on those devices. The above formentioned conversion provides 24 bit PCM Riff/Aiff files, while the below ffmpeg incanatation will provide 16 bit Microsoft PCM WAV files.

user $ffmpeg -i ./BDMV/STREAM/00000.m2ts -map 0:1 -acodec pcm_s16le music.wav

Another work around, is to play the 24bit PCM WAV files using a software media player such as FFplay and MPlayer, and route the sound to your audio receiver using HDMI or S/PDIF. One other option, ensure you buy a receiver capable of playing the 24 bit PCM files via USB media!

Note
If this section applies to you, then you will need to augment the further FFmpeg incanatations below with the '-acodec pcm_s16le' option.

Extract Individual Chapters

Find Chapters

1) The package media-video/bluray_info will display chapters.

2) FFprobe provided by media-video/ffmpeg package will display the chapters to stdout, if they are preserved within the media file.

More elaborate or useful examples using ffprobe,

Subtitles
user $ffprobe -i 00.mkv -print_format default -show_chapters -loglevel error > 00.mkv.txt 2>&1
user $ffprobe -i 00.mkv -print_format flat -show_chapters -loglevel error > 00.mkv.txt 2>&1
Note
If you use MakeMKV, make sure you extract to a format preserving Chapters with using 'makemkvcon mkv'. Using 'makemkvcon backup' does not preserve chapter information as of this writing!

For extracting streams including chapter info for use with ffprobe:

(MPlayer can also identify chapters using 'mindentify', however the chapter times do not appear comptabile with FFmpeg.)

Extract a Chapter

At this point, we'll assume we want Stream #1 for standard two stereo PCM WAV files (ie. map 0:1) and the second (#0.2) chapter.

FFprobe's snipped output:

The incanatation of FFmpeg we'll use for exacting this individual chapter, using seconds for start and duration indicators.

user $ffmpeg -ss [start] -i in.dts -t [duration] -c:v copy -c:a copy out.wav

With this example, the start time will be 534.934400 and duration will be 888.087200 minus 534.934400.

For example,

user $ffmpeg -ss 534.934400 -i ./BDMV/STREAM/00000.m2ts -t 353.152800 -c:v copy -c:a copy out.wav
Extract Multiple Chapters

I have only piped the message stdout of the CLI tools to a series of text files, utilizing grep and bc (CLI Calculator), along side VI/VIM for line duplication and clipping for creating one time scripts for extracting multiple files at once.

Someday, this will likely be automated and integrated into abcde.sh.

Tips

Cover Art

Cover art is usually found within the /mnt/dvd/BDMV/META/DL folder. For example:

user $cp /mnt/dvd/BDMV/META/DL/discinfo_640x360.jpg ${HOME}/Music/My_Album/cover.jpg

MPlayer Upmix When 24bit Decoding Not Available

My receiver is apparently not capable of decoding 24 bit PCM WAV, but will decode 16 and 32 bit PCM WAV through HDMI.

The PCM 5.1 WAV files are encoded at 24 bit PCM 5.1 WAV 48000 Hz.

The work around here is to upmix to 32 bit using sb32le or floatle, since MPlayer by default down mixes to 16 bit or s16le. MPlayer also by default cuts channels to two channels.

user $mplayer -af format=s32le,channels=8 PCM51-24bit/01.my_music_track.dts
user $mplayer2 -af format=s32le,channels=8 PCM51-24bit/01.my_music_track.dts

No DTS-H Master?

My receiver shows it's decoding DTS-HD Master stream when bit perfect or high definition audio decoding is selected within my Window's player, but my receiver only says it's decoding the usual 'DTS' decoding while playing streams within Linux. From reports on the web, bit perfect or high definition streaming to the receiver isn't possible within Linux. Other reports state it is possible using Intel's HDMI. (NVidia's video card HDMI using Linux binary drivers isn't performing DTS-HD Master here.)

Gapless Playback

Split tracks of long streams, it's nice to have gapless playback for preventing interruptions between tracks.

FIXME: The following is from Snipplr, but doesn't work for me. :-/

user $aplay -t raw -c 2 -f S16_LE -r 44100 /tmp/aufifo &> /tmp/aplayfifo.log &
user $mplayer -ao pcm:nowaveheader:file=/tmp/aufifo 01.track.wav 02.track.wav 03.track.wav &

Or use MPlayer2:

user $mplayer2 -ac hwdts -af channels=8 -ao alsa:device=hw=1.3 -gapless-audio DTS/*.dts

Additional Tools

Additional tools which might be useful, but not utilized within this Wiki:

  • media-sound/shntool - A multi-purpose WAVE data processing and reporting utility, ie. splitting WAV files.
  • MPlayer - Media Player for Linux, as an option to FFmpeg
  • media-video/tsmuxer - Utility to create and demux TS and M2TS files

References

Properly configure ALSA for pass-through digital audio, including specifying default decoding codecs for hardware digital decoders when using MPlayer.

Retrieved from 'https://wiki.gentoo.org/index.php?title=FFmpeg_-_Extract_Blu-Ray_Audio&oldid=852170'