Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only 1 set of subtitles is copied, seems to be hard coded to English #6

Closed
mstrelan opened this issue Feb 19, 2013 · 4 comments
Closed

Comments

@mstrelan
Copy link
Contributor

Accidentally submitted this before writing a description, however I think the title sums it up. An important consideration would be handling "forced" subtitles, eg. when a show (like Breaking Bad) is primarily in English but has a few Spanish parts there are two English tracks - English (forced) and English. The former is just the Spanish bits and the latter is everything. Is this doable via ffmpeg?

@mdhiggins
Copy link
Owner

Currently the subtitle copying feature is a very basic/dirty implementation. The API that I'm using to handle ffmpeg didn't have any subtitle support so I just added a quick and dirty feature to copy the first subtitle track that was found. Some more aggressive additions to the FFMPEG wrapper would let this be improved upon but as of now it isn't possible.

As someone who is relatively new to python reverse engineering this wrapper is gonna be challenging; if you were looking for a project to undertake adding support for subtitles to that would be a major help to making this a cleaner implementation.

@mstrelan
Copy link
Contributor Author

I'm looking in to it now :)

It seems that in ffmpeg you can specify which audio, video and subtitle streams to copy using the "-map" parameter. See http://ffmpeg.org/ffmpeg.html#Subtitle-options_003a

To copy ALL streams simply add "-map 0". You still need "-scodec mov_text" as mp4s are too dumb to play srt/ass formats.

Now just trying to find the cleanest way to implement this for this project. Will post back shortly.

@mstrelan
Copy link
Contributor Author

I added another comment but it doesn't seem to have appeared, even though it says there are 2 comments. Anyway, it seems there is no clean way to achieve this using the ffmpeg wrapper script you're using. You can however alter the current hack to force ffmpeg to copy ALL streams, not just the first of each (audio, video, subtitle). Simply replace cmds.extend(['-metadata:s:s:0', 'language=eng']) with cmds.extend(['-map', '0']). See http://ffmpeg.org/ffmpeg.html#Subtitle-options_003a for more info on the -map parameter.

@mdhiggins
Copy link
Owner

Added some functionality to the ffmpeg wrapper so we can now read subtitle information from multiple streams. Also beefed up the audio reading to allow for multiple streams as well. Eventually we can use this info to intelligently generate our conversion string rather than just blindly copying everything. Lot of work still needs to be done though

@mdhiggins
Copy link
Owner

I made a 3.0 branch with a ton of new changes, I rewrote/beefed up a vast majority of the ffmpeg api so it can now handle multiple audio streams and subtitles (also multiple). I still need to figure out how to set forced and default tags in ffmpeg (maybe you can help here) but check out the new branch. I'm genuinely surprised I got everything working so quickly haha

Everything seems to be working on my end, if you could give it some testing and let me know if you find any bugs we can get it merged with the master branch quickly

@mstrelan
Copy link
Contributor Author

Awesome work. I've been off work the last few days as I've been sick, but
I'm back in the office now so will be slower to test things out :(

I don't know ffmpeg terribly well (nor python for that matter) but I will
definitely do some research in to this. I am not sure that mp4 even has an
option for forced subtitles.

On 20 February 2013 09:41, Michael Higgins notifications@github.com wrote:

I made a 3.0 branch with a ton of new changes, I rewrote/beefed up a vast
majority of the ffmpeg api so it can now handle multiple audio streams and
subtitles (also multiple). I still need to figure out how to set forced and
default tags in ffmpeg (maybe you can help here) but check out the new
branch. I'm genuinely surprised I got everything working so quickly haha


Reply to this email directly or view it on GitHubhttps://github.com//issues/6#issuecomment-13807255.

@mstrelan
Copy link
Contributor Author

Well done on the new branch. Not sure if my comments are working properly?

From what I have found there is apparently no way to enable forced subs in mp4s, see http://forum.doom9.org/showthread.php?p=1579492#post1579492 and also http://forum.doom9.org/showthread.php?t=155544

This is a real shame, because the only other option is to use burned-in subs. Instead I'd rather manually enable subs when they start speaking another language.

What I am wondering is why the generated ffmpeg command specifies each piece of metadata, instead of just using the map_metadata paramater (see http://ffmpeg.org/ffmpeg.html#Advanced-options ).

Can reduce
C:\Users\Michael\Sickbeard\sickbeard_mp4_automator\bin\ffmpeg.exe -i "D:\TV Shows\Game of Thrones\Season 2\Game of Thrones 2x05 The Ghost of Harrenhal.mkv" -map 0 -c:a:0 aac -ac:a:0 6 -b:a:0 640k -metadata:s:a:0 language=eng -strict experimental -vcodec copy -c:s:0 mov_text -metadata:s:s:0 disposition:default=1 -metadata:s:s:0 disposition:forced=0 -metadata:s:s:0 language=eng -c:s:1 mov_text -metadata:s:s:1 disposition:default=0 -metadata:s:s:1 disposition:forced=0 -metadata:s:s:0 language=eng -f mp4 -y D:\output.m4v

Down to
C:\Users\Michael\Sickbeard\sickbeard_mp4_automator\bin\ffmpeg.exe -i "D:\TV Shows\Game of Thrones\Season 2\Game of Thrones 2x05 The Ghost of Harrenhal.mkv" -map 0 -c:a:0 aac -ac:a:0 6 -b:a:0 640k -metadata:s:a:0 language=eng -strict experimental -vcodec copy -c:s:0 mov_text -map_metadata:s:s:0 0:s:s:0 -c:s:1 mov_text -map_metadata:s:s:1 0:s:s:1 -f mp4 -y D:\output.m4v

Probably even more reductions can be made, I'm not sure. I guess the more verbose option gives more control, but also has the potential to miss something?

I also wonder why the title of the subtitle streams doesn't seem to have an effect, my mkv streams are "English (forced)" and "English", but end up as "English" and "English" in the mp4 :( The ffmpeg output even suggests it's going to use that piece of metadata (when I use map_metadata)
Stream #0:2(eng): Subtitle: mov_text ([8][0][0][0] / 0x0008) (default) Metadata: title : English (Forced) Stream #0:3(eng): Subtitle: mov_text ([8][0][0][0] / 0x0008) Metadata: title : English

@mdhiggins
Copy link
Owner

3.0 branch has been merged with the master branch, changes are live and mapping is now handled dynamically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants