lisamelton / other_video_transcoding

Other tools to transcode videos.
MIT License
564 stars 26 forks source link

Issue with subtitle track when converting to mp4 #71

Closed hisaac closed 4 years ago

hisaac commented 4 years ago

Hello!

I just used other_video_transcoding for the first time to convert a video. The first pass converted it to mkv, but I'd like to convert the same video to mp4 to compare. Problem is, I get an error message when I try to convert to mp4. Here are the exact commands I'm using:

The working command, converting to mkv:

other-transcode --add-subtitle all --crop auto --hevc --main-audio 1=stereo ../1-ripped/Eyes\ Wide\ Shut\ orig.mkv

The non-working command, the only difference here being the addition of the --mp4 flag:

other-transcode --add-subtitle all --crop auto --hevc --main-audio 1=stereo --mp4 ../1-ripped/Eyes\ Wide\ Shut\ orig.mkv

The error message I receive:

[mp4 @ 0x7fa864033c00] Could not find tag for codec hdmv_pgs_subtitle in stream #2, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --

I'm not super familiar with video conversion like this, so I'm not sure how to resolve this. Does mp4 not support certain types of subtitles? Any advice?


My environment:

Here's the full shell output if that's helpful:

❯ other-transcode --add-subtitle all --crop auto --hevc --main-audio 1=stereo --mp4 ../1-ripped/Eyes\ Wide\ Shut\ orig.mkv
Verifying "ffprobe" availability...
Verifying "ffmpeg" availability...
Verifying "mkvpropedit" availability...
Finding encoders...
Trying "hevc_videotoolbox" video encoder...
Scanning media...
Detecting crop...
...
...
crop = 1920:1080:0:0
duration = 02:39:01.536
Stream mapping:
 0 = libx265 / 6000 Kbps
 1 = aac_at / 256 Kbps / stereo
 3 = hdmv_pgs_subtitle
 4 = hdmv_pgs_subtitle
Command line:
ffmpeg -loglevel error -stats -hwaccel auto -i ../1-ripped/Eyes\ Wide\ Shut\ orig.mkv -map 0:0 -c:v libx265 -pix_fmt:v yuv420p10le -b:v 6000k -maxrate:v 18000k -bufsize:v 18000k -color_primaries:v bt709 -color_trc:v bt709 -colorspace:v bt709 -metadata:s:v title\= -disposition:v default -tag:v hvc1 -map 0:1 -c:a:0 aac_at -aac_at_mode:a:0 cvbr -b:a:0 256k -ac:a:0 2 -metadata:s:a:0 title\= -disposition:a:0 default -map 0:3 -c:s:0 copy -disposition:s:0 0 -map 0:4 -c:s:1 copy -disposition:s:1 0 -metadata:g title\= -movflags disable_chpl Eyes\ Wide\ Shut\ orig.mp4
Transcoding...
x265 [info]: HEVC encoder version 3.4
x265 [info]: build info [Mac OS X][clang 11.0.3][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main 10 profile, Level-4 (High tier)
x265 [info]: Thread pool created using 12 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 3 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias  : 23 / 250 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : ABR-6000 kbps / 0.60
x265 [info]: VBV/HRD buffer / max-rate / init    : 18000 / 18000 / 0.750
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp
x265 [info]: tools: b-intra strong-intra-smoothing lslices=6 deblock sao
[mp4 @ 0x7fa864033c00] Could not find tag for codec hdmv_pgs_subtitle in stream #2, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --

encoded 0 frames
/Users/<home directory>/.rbenv/versions/2.7.1/bin/other-transcode: transcoding failed: Eyes Wide Shut orig.mp4
samhutchins commented 4 years ago

Apologies if this is too "back to basics". In short: MP4 files are more restrictive about the formats supported for video, audio, and subtitles. MKV is more flexible, but less supported in that you often need to install 3rd party software to play them.

Longer version:

A video file can (broadly) be thought of the following parts:

The video stream The audio stream(s) The subtitle stream(s) The container

The container is the file format, mp4 and mkv are 2 example of containers (there's also MOV, AVI, and many others).

Containers have different features, and one of the nice things about the MKV container as compared to MP4 is its broader support for different stream codecs.

On to subtitle codec:

Broadly speaking, there are 2 categories: text-based and image-based. The subtitles on DVDs and Blu-Rays are image-based. In this case, it's a Blu-Ray subtitle (PGS subtitles), and this is not a supported codec in MP4 files. In order to include the subtitles you'll need to use the MKV container

MP4 supports text based subtitles, like .srt, and I think it supports the DVD image-based subtitle, but I'm not sure.

hisaac commented 4 years ago

Thank you for the detailed explanation @samhutchins. I guess for now I'll just use mkv, or I just skip the embedded subtitles and download an .srt file from somewhere instead.

lisamelton commented 4 years ago

@samhutchins Thanks for that brilliant summary of the issue!

@hisaac Yes, I'm afraid you can't add image-based subtitles to MP4 output. It's a limitation of both the format and ffmpeg. I'll close this now but feel free to open other issues when you encounter problems.