Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Extract forced subtitles only
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 446

PostPosted: Mon Sep 15, 2014 4:00 pm    Post subject: Extract forced subtitles only Reply with quote

Hello,

I would like to be able to extract forced (dvdsub) subtitles from a mkv file. I don't think ffmpeg can do that. I need a command line application, not a GUI.

Any suggestions?
Back to top
View user's profile Send private message
lagalopex
Guru
Guru


Joined: 16 Oct 2004
Posts: 562

PostPosted: Mon Sep 15, 2014 4:09 pm    Post subject: Reply with quote

You can easily extract just the forced sub.
With ffmpeg just map that single stream.
Code:
$ ffmpeg -i src.mkv
...
Stream #0:3(eng): Subtitle: ... (default) (forced)
...
$ ffmpeg -i src.mkv -map 0:3 out.mkv


You can keep the same codec with "-c:s copy" or try to convert them.
dvdsub are bitmap subtitles (not text ones) so you cannot convert them to text-based formats.
Back to top
View user's profile Send private message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 446

PostPosted: Mon Sep 15, 2014 5:21 pm    Post subject: Reply with quote

Some subtitles are forced on the entry-by-entry basis, not on a stream-by-stream basis.

For instance, in an English language movie with some non-English dialog, they might have one English subtitle track. With all the English entries marked not-forced, but the ones that are translations into English marked as forced.
Back to top
View user's profile Send private message
beandog
Bodhisattva
Bodhisattva


Joined: 04 May 2003
Posts: 2072
Location: /usa/utah

PostPosted: Thu Sep 18, 2014 6:55 pm    Post subject: Re: Extract forced subtitles only Reply with quote

Nicias wrote:
Hello,

I would like to be able to extract forced (dvdsub) subtitles from a mkv file. I don't think ffmpeg can do that. I need a command line application, not a GUI.

Any suggestions?


mkvextract :)
_________________
If it ain't broke, tweak it. dvds | blurays | blog | wiki
Back to top
View user's profile Send private message
beandog
Bodhisattva
Bodhisattva


Joined: 04 May 2003
Posts: 2072
Location: /usa/utah

PostPosted: Thu Sep 18, 2014 6:59 pm    Post subject: Reply with quote

Code:
$ mkvinfo A\ Bullet\ for\ Bullock.mkv
+ EBML head
|+ EBML version: 1
|+ EBML read version: 1
|+ EBML maximum ID length: 4
|+ EBML maximum size length: 8
|+ Doc type: matroska
|+ Doc type version: 2
|+ Doc type read version: 2
+ Segment, size 351908101
|+ Seek head (subentries will be skipped)
|+ EbmlVoid (size: 4027)
|+ Segment information
| + Timecode scale: 1000000
| + Muxing application: libebml v1.3.0 + libmatroska v1.4.1
| + Writing application: mkvmerge v7.0.0 ('Where We Going') 64bit built on Aug 24 2014 18:15:55
| + Duration: 1273.952s (00:21:13.952)
| + Date: Tue Aug 26 03:58:00 2014 UTC
| + Title: A Bullet for Bullock
| + Segment UID: 0x18 0xb5 0xfb 0x5b 0xc0 0x5e 0x40 0x6e 0xff 0x1c 0x45 0x86 0x3c 0x13 0x78 0xc9
|+ Segment tracks
| + A track
|  + Track number: 1 (track ID for mkvmerge & mkvextract: 0)
|  + Track UID: 392831408
|  + Track type: video
|  + Lacing flag: 0
|  + MinCache: 1
|  + Codec ID: V_MPEG4/ISO/AVC
|  + CodecPrivate, length 46 (h.264 profile: High @L3.1)
|  + Default duration: 40.609ms (24.625 frames/fields per second for a video track)
|  + Video track
|   + Pixel width: 624
|   + Pixel height: 480
|   + Display width: 624
|   + Display height: 480
| + A track
|  + Track number: 2 (track ID for mkvmerge & mkvextract: 1)
|  + Track UID: 1261582995
|  + Track type: audio
|  + Codec ID: A_AC3
|  + Default duration: 32.000ms (31.250 frames/fields per second for a video track)
|  + Audio track
|   + Sampling frequency: 48000
|   + Channels: 2
| + A track
|  + Track number: 3 (track ID for mkvmerge & mkvextract: 2)
|  + Track UID: 794815275
|  + Track type: subtitles
|  + Default flag: 0
|  + Lacing flag: 0
|  + Codec ID: S_VOBSUB
|  + CodecPrivate, length 349
|  + Content encodings
|   + Content encoding
|    + Content compression
|+ EbmlVoid (size: 1160)
|+ Cluster

steve@tobe ~/dvds/episodes/Batman: The Animated Series $ mkvextract tracks "A Bullet for Bullock.mkv" 2:bullock
Extracting track 2 with the CodecID 'S_VOBSUB' to the file 'bullock'. Container format: VobSubs
Writing the VobSub index file 'bullock.idx'.
Progress: 100%


Creates bullock.idx and bullock.sub.
_________________
If it ain't broke, tweak it. dvds | blurays | blog | wiki
Back to top
View user's profile Send private message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 446

PostPosted: Thu Sep 18, 2014 7:04 pm    Post subject: Reply with quote

I know how to extract a particular track with mkvextract or ffmpeg.

Sometimes some entries in an unforced track are forced. I only want those.

For instance, in a WWII movie, the English subtitle track might have all of the dialog, but the entries for translated German dialog would be marked forced. I want to only extract those entries, not the whole track.
Back to top
View user's profile Send private message
beandog
Bodhisattva
Bodhisattva


Joined: 04 May 2003
Posts: 2072
Location: /usa/utah

PostPosted: Thu Sep 18, 2014 8:38 pm    Post subject: Reply with quote

Nicias wrote:
I know how to extract a particular track with mkvextract or ffmpeg.

Sometimes some entries in an unforced track are forced. I only want those.

For instance, in a WWII movie, the English subtitle track might have all of the dialog, but the entries for translated German dialog would be marked forced. I want to only extract those entries, not the whole track.


Ah, gotcha.

Seems like you'd have to examine the entire track itself, somehow.

Edit: a couple of things I'm curious about ... which DVD is it? is this a one-time thing you're doing, or are you gonna script it?

Interesting stuff I've found so far: https://trac.handbrake.fr/wiki/Subtitles http://www.makemkv.com/forum2/viewtopic.php?f=1&t=1760
_________________
If it ain't broke, tweak it. dvds | blurays | blog | wiki
Back to top
View user's profile Send private message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 446

PostPosted: Fri Sep 19, 2014 1:15 am    Post subject: Reply with quote

beandog wrote:
Nicias wrote:
I know how to extract a particular track with mkvextract or ffmpeg.

Sometimes some entries in an unforced track are forced. I only want those.

For instance, in a WWII movie, the English subtitle track might have all of the dialog, but the entries for translated German dialog would be marked forced. I want to only extract those entries, not the whole track.


Ah, gotcha.

Seems like you'd have to examine the entire track itself, somehow.

Edit: a couple of things I'm curious about ... which DVD is it? is this a one-time thing you're doing, or are you gonna script it?

Interesting stuff I've found so far: https://trac.handbrake.fr/wiki/Subtitles http://www.makemkv.com/forum2/viewtopic.php?f=1&t=1760

I noticed it on the DVD for Monument Men. Once I knew what I was looking for I found it on a few other of DVD's: The Avengers, a few episodes of MASH, The Wolverine. I plan on scripting it.

I poked around in ffmpeg, and found I could sort of do it with 4 lines of code. However, my patch produces corrupted dvdsub tracks. If I run them trough ffmpeg a second time, it cleans it up. I don't see what my 4 line patch is doing wrong, and I've asked the ffmpeg people and I've gotten no response. (You can see my patch and discussion with myself on ffmpeg-devel)

This is because my STB ignores the forced flag. So I plan on extracting these subtitles, putting them in a new track and then labeling it as "Dutch" (arbitrarily) then telling the STB to play any Dutch subtitles.

My current ffmpeg patch with resulting need to run ffmpeg twice is kinda hackish, but if I don't hear back from the ffmpeg people I'm going go with it. I'll post it here I suppose, or on github.
Back to top
View user's profile Send private message
beandog
Bodhisattva
Bodhisattva


Joined: 04 May 2003
Posts: 2072
Location: /usa/utah

PostPosted: Fri Sep 19, 2014 5:40 pm    Post subject: Reply with quote

Nicias wrote:
I noticed it on the DVD for Monument Men. Once I knew what I was looking for I found it on a few other of DVD's: The Avengers, a few episodes of MASH, The Wolverine. I plan on scripting it.


I've never even noticed that on DVDs before. I'm gonna have to look through some of mine to see if they have that too. Off the top of my head, I think the original Star Wars trilogy has some when Jabba is speaking.

Nicias wrote:
I poked around in ffmpeg, and found I could sort of do it with 4 lines of code. However, my patch produces corrupted dvdsub tracks. If I run them trough ffmpeg a second time, it cleans it up. I don't see what my 4 line patch is doing wrong, and I've asked the ffmpeg people and I've gotten no response. (You can see my patch and discussion with myself on ffmpeg-devel)

This is because my STB ignores the forced flag. So I plan on extracting these subtitles, putting them in a new track and then labeling it as "Dutch" (arbitrarily) then telling the STB to play any Dutch subtitles.

My current ffmpeg patch with resulting need to run ffmpeg twice is kinda hackish, but if I don't hear back from the ffmpeg people I'm going go with it. I'll post it here I suppose, or on github.


Yah, totally post it here, I'd love to see it.

I also saw that HandBrake has options in the CLI for forced subtitles. It uses libav for its backend as well, so maybe there's something in there that could help.
_________________
If it ain't broke, tweak it. dvds | blurays | blog | wiki
Back to top
View user's profile Send private message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 446

PostPosted: Fri Sep 19, 2014 6:16 pm    Post subject: Reply with quote

Yeah, I ran an automated test and found partially-forced subs on Star Wars and Return of the Jedi.

I found I could put it in the dvdsub decoding section and it worked perfectly, I'm posted that patch and I'm getting feedback. It might get in ffmpeg soon.
Back to top
View user's profile Send private message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 446

PostPosted: Mon Sep 22, 2014 7:43 pm    Post subject: Reply with quote

Ok, the option is now in ffmpeg.
Code:
ffmpeg -forced_subs_only 1 -i IN.mkv ...

Will only keep the forced subs.

I'm going to put together a script to extract these forced subs as separate tracks as well as incorporate it into my transcoding script. I'll add them to my git hub repo and announce it here when I'm done.
Back to top
View user's profile Send private message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 446

PostPosted: Mon Sep 22, 2014 10:12 pm    Post subject: Reply with quote

Ok, I've added the scripts to pull the forced subs and chuck them in a Dutch subtitle stream. (Dutch chosen arbitrarily) I've also rolled this into the transcoding script.

It is up at my github repo

https://github.com/Nicias/dvd_scripts
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum