Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Solved: New problem: Ffmpeg and delayed subtitle stream
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
keet
Guru
Guru


Joined: 09 Sep 2008
Posts: 417

PostPosted: Thu Sep 12, 2013 3:23 am    Post subject: Solved: New problem: Ffmpeg and delayed subtitle stream Reply with quote

Hello, I am working on converting my D.V.D.s to .mkv files so that I will be able to archive them easily without needing to worry about finding the discs, or finding them scratched, et cetera. I am very frustrated now because of one particular problem: subtitles. I just want to make a nice .mkv file with subtitles that are merged into the video stream, because my U.S.B. player can't handle them on a separate stream. I would like to do it at near lossless quality. I have no problem without subtitles, but doing it with subtitles either doesn't work, or the subtitles stay on the screen long after the talking is over, or other problems happen. This is the closest I have come. With this, the subtitles stay on the screen after the talking is done, which is too suboptimal:

Code:
ffmpeg -i file.vob -filter_complex "[0:0][0:4]overlay" -map 0:0 -c:v libx264 -preset veryslow -crf 18 -map 0:9 -c:a libfdk_aac -cutoff 19000 -vbr 5 -ac 2 file.mkv


Also, the subtitles here are opaque, whereas in the original they are translucent, but I can accept that.

I had this working in mencoder with this command:

Code:
mencoder file.vob -vf crop=704:448:10:14,pp=lb -aid 129 -sid 3 -ovc x264 -x264encopts pass=2:bitrate=2000:threads=auto -oac faac -faacopts br=256 -o file.avi


However, I have not been able to make an .mp4 or .mkv file successfully with mencoder; no matter what I try, it always warns me that it is A.V.I.

I have found lots of information about extracting subtitles to .srt files and such using avidemux, mkvmerge, and other programs, but isn't there a way to do this without too much trouble and too many external utilities on the command line? I also found a conversion script in another thread, but I am not sure how to apply it here.

Thank you very much.


Last edited by keet on Fri Sep 20, 2013 11:33 pm; edited 4 times in total
Back to top
View user's profile Send private message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 397

PostPosted: Thu Sep 12, 2013 12:48 pm    Post subject: Reply with quote

If the "other thread" with the conversion script is mine, you should be able to use it pretty much as is. Use the version at the pastebin. I think it is up to date: http://pastebin.com/jT2jsK5d

This is how you use it.

1) Save that as a file like backup-dvd.sh

2) make it executeable

3) edit a few places
3a) /dev/sr0 should be your dvd drive.
3b) the /var/srv/media/vidoes/NO-BACKUP-holding/ripping part is where the mkv's will end up. Change that to suit you
3c) TMPDIR holds the vobs before they become DVD's. You will need probably 15 GB free there
3d) SUBDIR is where the subtitles go. 1G there should be sufficient.
(Note that 3b,3c,3d should be on different physical media if possible. I keep 3d in ram.)

4) insert DVD

5) type ./backup-dvd.sh

6) profit

The resulting files will have all the subtitles in there, as separate tracks, so you can switch them on and off, but all one file. No transcoding is done.

If you want I can show you how to only keep english subtitles/audio tracks.
Back to top
View user's profile Send private message
HolgerB
n00b
n00b


Joined: 07 Sep 2011
Posts: 49

PostPosted: Fri Sep 13, 2013 12:12 pm    Post subject: Reply with quote

keet,

re-encoding all your movies to make subtitles work sound like a real PITA to me. May be you should try to get another player which supports native VOBSUB subtitles inside an MKV and convert all your DVDs to MKV via a simple script and MakeMKV ?

There are a lot of hardware players. Even a Raspi with MPEG2 license and XBMC installed should playback MKVs based on DVD structures with perfect original subtitles.

Personally I try to avoid re-encoding things as much as possible since you always loose quality.

Just my 2 cents,
Holger
Back to top
View user's profile Send private message
Ant P.
Advocate
Advocate


Joined: 18 Apr 2009
Posts: 2592
Location: UK

PostPosted: Fri Sep 13, 2013 3:10 pm    Post subject: Reply with quote

If it's lossless you're after then you should try using -c:a copy (if not for the subtitle problem, -c:v copy would work here too).
Back to top
View user's profile Send private message
keet
Guru
Guru


Joined: 09 Sep 2008
Posts: 417

PostPosted: Sun Sep 15, 2013 5:57 pm    Post subject: Reply with quote

I am not re-encoding all my movies to make subtitles; rather, I am trying to find a good formula that works, and stay with it when I encode/transcode things in the future.

I found that my player (it's a 삼성 BD-C5500) supports .mp4 files will with libx264 and libfdk_aac, which seem to be two of the highest-quality encoders that ffmpeg supports, so I am happy with that. Switching containers (mp4/mkv), if I want to do that, seems easy enough. It seems like the particular video that I am having trouble with uses dvdsub for the subtitle, for which ffmpeg has a bit of a bug in that it keeps the subtitles on the screen after they should disappear (http://ffmpeg.org/pipermail/ffmpeg-user/2012-November/011666.html). That list posts a patch. For some reason, even though ffmpeg 2.0.1 is out, only 1.0.7 is marked as stable in portage, so I will unmask/keyword and try 2.0.1 and see whether that gives better results.

On the other hand, libav is out at 9.9, which is Gentoo in only keyworded and not masked. From what I have read, though, the fork was a bit of a nasty one. I am not really sure which to choose here. I read somewhere that ffmpeg applies patches from libav, but I am really not sure. Is there much of a difference between the two? I have read a thread or two about them here, so I can check again if ffmpeg really stops working for me, or if libav is really better for some reason.

These parameters seem to work rather well for giving more or less lossless output with a significantly reduced filesize, right?

Code:
ffmpeg -i original /
   -vf crop=700:450:10:10 / #or whatever to get rid of the black edges
   -filter_complex [0:0][0:4]overlay / #if it has dvdsub subtitles, since those seem not to work so well
   -map 0:V -c:v libx264 -tune X -crf 19 -preset veryslow / #high quality and lower filesize
   -map 0:A -c:a libfdk_aac -cutoff 19000 -vbr 5 /
   -map 0:S -c:s copy / #if it has subtitles that work properly for me
   new.mp4


Thanks for your help and comments.
Back to top
View user's profile Send private message
Ant P.
Advocate
Advocate


Joined: 18 Apr 2009
Posts: 2592
Location: UK

PostPosted: Sun Sep 15, 2013 10:42 pm    Post subject: Reply with quote

If ffmpeg does what you need then there's no compelling reason to switch.

If you do choose to do so, the one difference you need to pay attention to is that ffmpeg takes security seriously while libav relies on its hostile reverse-engineering policy; you'll often see other distros like Ubuntu weeks or even months behind on fixing CVEs that you wouldn't have to worry about in Gentoo.
Back to top
View user's profile Send private message
keet
Guru
Guru


Joined: 09 Sep 2008
Posts: 417

PostPosted: Wed Sep 18, 2013 2:08 am    Post subject: Reply with quote

I think that I have it figured it out for the most part. The one video that I was having trouble uses dvdsub subtitles, which seem particularly troublesome for some reason, but I found an overlay method that works well enough. I also found that my player can't handle files above a certain bitrate, so I will probably keep one main near-lossless copy of some things along with a quarter/half-resolution copy that my player can handle. It also has trouble fast-forwarding and rewinding with the .mkv container, but since I am mostly interested in only one stream each for audio and video, it is ok for me to use .mp4.
Back to top
View user's profile Send private message
keet
Guru
Guru


Joined: 09 Sep 2008
Posts: 417

PostPosted: Fri Sep 20, 2013 10:58 pm    Post subject: Reply with quote

I have a new problem that I am researching, but if anyone here knows the solution, I would appreciate being told.

One of the videos has a subtitle stream that starts several minutes into the video. Thus, ffmpeg -i does not detect it; only after encoding after several minutes does it see the subtitle stream. It is too late even for the maximum value of -analyzeduration to help. I want to include these subtitles properly, preferably hardcoded. ' -filter_complex "[0:0][0:2]overlay"' worked on the other one after I upgraded to Ffmpeg 2, so that will probably work fine here, too, if I can find a way to include the subtitles despite the delay, preferably using only ffmpeg and no external programs or utilities.

Thanks again!

Edit: I figured it out; setting analyzeduration and probesize to their maximum durations made it work.
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