lisamelton / video_transcoding

Tools to transcode, inspect and convert videos.
MIT License
2.39k stars 160 forks source link

Possible issue with subtitle scanning #227

Closed khaosx closed 6 years ago

khaosx commented 6 years ago

I'm trying to encode some media files in such a way as to retain up to two subtitle tracks. The first track would be the full subtitle track for the movie. The second would be a forced track. I do not want to burn the subs to the file, but I would like for the second track to retain its forced flag. I have tried the following command:

transcode-video --quick --no-log --no-auto-burn --add-subtitle all --force-subtitle scan --crop $crop_value

That yielded a file with all the correct tracks, but the two subtitles were flagged wrong. The first track was flagged default and forced, the second was unflagged. The ultimate goal would be neither flagged default, and the second flagged forced.

Any assistance would be appreciated!

Here's the media info output on my input file:

General Unique ID : 327012155398765868428982579473175652336 (0xF604400ED17D06EC87BBB99D6CE9A7F0) Complete name : /Volumes/Data/Workflows/Transcode/Convert/Movies/1080_Quick/movie.mkv Format : Matroska Format version : Version 2 File size : 23.7 GiB Duration : 1h 45mn Overall bit rate mode : Variable Overall bit rate : 32.3 Mbps Movie name : movie Encoded date : UTC 2018-10-24 19:26:50 Writing application : MakeMKV v1.12.3 darwin(x64-release) Writing library : libmakemkv v1.12.3 (1.3.5/1.4.7) darwin(x64-release)

Video ID : 1 ID in the original source medium : 4113 (0x1011) Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4.1 Format settings : CABAC / 4 Ref Frames Format settings, CABAC : Yes Format settings, ReFrames : 4 frames Codec ID : V_MPEG4/ISO/AVC Duration : 1h 45mn Bit rate mode : Variable Bit rate : 27.8 Mbps Maximum bit rate : 33.0 Mbps Width : 1 920 pixels Height : 1 080 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 23.976 (24000/1001) fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.559 Stream size : 20.4 GiB (86%) Language : English Default : No Forced : No Color range : Limited Color primaries : BT.709 Transfer characteristics : BT.709 Matrix coefficients : BT.709 Original source medium : Blu-ray

Audio ID : 2 ID in the original source medium : 4352 (0x1100) Format : MLP FBA Format/Info : Meridian Lossless Packing FBA Commercial name : Dolby TrueHD Codec ID : A_TRUEHD Duration : 1h 45mn Bit rate mode : Variable Bit rate : 4 467 Kbps Maximum bit rate : 6 534 Kbps Channel(s) : 8 channels Channel layout : L R C LFE Ls Rs Lb Rb Sampling rate : 48.0 KHz Frame rate : 1 200.000 fps (40 SPF) Bit depth : 24 bits Compression mode : Lossless Stream size : 3.28 GiB (14%) Title : Surround 7.1 Language : English Default : Yes Forced : No Original source medium : Blu-ray

Text #1 ID : 3 ID in the original source medium : 4608 (0x1200) Format : PGS Codec ID : S_HDMV/PGS Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs Duration : 1h 38mn Bit rate : 29.1 Kbps Count of elements : 1952 Stream size : 20.5 MiB (0%) Language : English Default : No Forced : No Original source medium : Blu-ray

Text #2 ID : 5 ID in the original source medium : 4613 (0x1205) Format : PGS Codec ID : S_HDMV/PGS Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs Duration : 1h 12mn Bit rate : 864 bps Count of elements : 74 Stream size : 459 KiB (0%) Language : English Default : No Forced : Yes Original source medium : Blu-ray

lisamelton commented 6 years ago

@khaosx Thanks for the nice handoff from our Twitter conversation! And the detailed information.

Yes, that second subtitle track is definitely supposed to be forced (or at least foreign audio) based on the "Count of elements" attribute.

Just so you know, whenever a subtitle track has the forced flag set, it should also have the default flag set. This is to ensure backward compatibility with various playback software.

I'm not sure why HandBrake is identifying the first track as forced during its scan phase. But, as I've warned people before, HandBrake's scanning algorithm is far from perfect. That's why I advise people to do these things manually.

What happens when if you use --force-subtitle 2 instead of scan? Does it work then?

khaosx commented 6 years ago

Strangely, no. Random bits o' log from the revised job:

[20:10:31] libhb: scan thread found 1 valid title(s)

yada yada, then:

[20:10:31] work: mixdown not specified, track 1 setting mixdown 5.1 Channels [20:10:31] work: bitrate not specified, track 1 setting bitrate 640 Kbps [20:10:31] work: mixdown not specified, track 2 setting mixdown Dolby Pro Logic II [20:10:31] work: bitrate not specified, track 2 setting bitrate 160 Kbps [20:10:31] job configuration: [20:10:31] source [20:10:31] + /Volumes/Data/Workflows/Transcode/Convert/Movies/1080_Quick/Star Trek III The Search for Spock Remux-1080p.mkv [20:10:31] + title 1, chapter(s) 1 to 11 [20:10:31] + container: matroska,webm [20:10:31] destination [20:10:31] + Star Trek III The Search for Spock Remux-1080p.mkv [20:10:31] + container: Matroska (libavformat) [20:10:31] + chapter markers [20:10:31] video track [20:10:31] + decoder: h264 [20:10:31] + filters [20:10:31] + Framerate Shaper (mode=0) [20:10:31] + frame rate: same as source (around 23.976 fps) [20:10:31] + Crop and Scale (width=1920:height=818:crop-top=128:crop-bottom=134:crop-left=0:crop-right=0) [20:10:31] + source: 1920 1080, crop (128/134/0/0): 1920 818, scale: 1920 818 [20:10:31] + Output geometry [20:10:31] + storage dimensions: 1920 x 818 [20:10:31] + pixel aspect ratio: 1 : 1 [20:10:31] + display dimensions: 1920 x 818 [20:10:31] + encoder: H.264 (libx264) [20:10:31] + preset: medium [20:10:31] + options: vbv-maxrate=6000:vbv-bufsize=12000:crf-max=25:qpmax=34:analyse=none:ref=1:rc-lookahead=30 [20:10:31] + profile: high [20:10:31] + level: 4.0 [20:10:31] + quality: 1.00 (RF) [20:10:31] subtitle track 1, English [PGS] (track 1, id 0x3, Picture) -> Passthrough, Default [20:10:31] subtitle track 2, English [PGS] (track 0, id 0x2, Picture) -> Passthrough

Output file reports:

Text #1 ID : 4 Format : PGS Codec ID : S_HDMV/PGS Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs Language : English Default : Yes Forced : Yes

Text #2 ID : 5 Format : PGS Codec ID : S_HDMV/PGS Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs Language : English Default : No Forced : No

I'm feeding all of this through a convoluted script of my own to set up and manage batch conversion. I'm going to just run it straight from the command line without the no-log and see what that yields. I'll post it tomorrow morning. Thanks for looking at this - I'm at 90% capacity on my NAS, so the long delayed encoding of my raw files is going to have to commence soon :)

lisamelton commented 6 years ago

@khaosx OK, I'm not sure why this is not working for you. I'm trying both approaches, scan and explicitly choosing a subtitle to force, on a similar movie and... it's working correctly in both cases.

So I'm stumped.

Is there any way you could upload a fragment of your original movie somewhere? Some way that would obviously not violate copyright law?

khaosx commented 6 years ago

This is what happens when a coder and an operations guy walk into a bar, programmatically scan the menu, and don't get a result of "Beer" in the column they expect it to be in.

Setting aside this issue, I did a quick check for quality between --quick and normal (23 min vs 66 min, same size, no visible quality differences, quick had a slightly higher overall bitrate, in case you're keeping score), and realized that the first track in the output file (default and forced) is actually track 2 of the input. Both outputs played perfectly, with forced subs playing by default unless the full track is selected in the playback software. So, either Handbrake or the transcode gem is changing the order of the tracks when it muxes them in. In fact, the log clearly says "Hey dummy, here's what I'm doing":

[20:10:31] subtitle track 1, English [PGS] (track 1, id 0x3, Picture) -> Passthrough, Default [20:10:31] subtitle track 2, English [PGS] (track 0, id 0x2, Picture) -> Passthrough

It's not what I expected, but it does accomplish my objective. Go ahead and close this one unless you're just curious and want to see the logs. I'll hold on to them and paste them up if you need me to.

lisamelton commented 6 years ago

@khaosx LOL! Just so you know, I'm gonna use that joke sometime, sir. :)

Yes, that's transcode-video reordering the tracks, placing the forced track first. When I was trying this myself last night, it appears I was using an input where the forced track was already first.

What I'm really annoyed at is that I didn't notice the reordering the the log you included. Thank god you noticed that! And did some more testing. Thank you!

Also, I'm glad you like the results of --quick. I use it all the time myself. It's very, very difficult to notice any quality difference between it and the default medium preset. And, yes,--quick will often be slightly higher in bitrate. That's because it's less efficient at compression, which is one way it gets its speed.

OK, I will close this. I'm so glad everything worked out! I don't need the logs at this time. Thank you so much for opening this and entertaining us both.