Opened 13 years ago
Last modified 3 years ago
#2260 new defect
FFmpeg doesn't auto-select subtitle codec for MP4
| Reported by: | slhck | Owned by: | |
|---|---|---|---|
| Priority: | normal | Component: | ffmpeg |
| Version: | git-master | Keywords: | mov mp4 |
| Cc: | colemarc | Blocked By: | |
| Blocking: | Reproduced by developer: | no | |
| Analyzed by developer: | no |
Description
FFmpeg doesn't seem to be able to auto-select the proper subtitle codec for MP4, which would be mov_text.
I expect FFmpeg to automatically choose the codec, similar to how it does with libx264 and libfaac.
ffmpeg -i in.mp4 -i subs.srt -c:v copy -c:a copy -map 0 -map 1 out.mp4
ffmpeg version 1.1.2 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 8 2013 22:55:29 with Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.1.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-ffplay --enable-libfdk-aac --enable-libopus --enable-libopenjpeg --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1/include/openjpeg-1.5 '
libavutil 52. 13.100 / 52. 13.100
libavcodec 54. 86.100 / 54. 86.100
libavformat 54. 59.106 / 54. 59.106
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 32.100 / 3. 32.100
libswscale 2. 1.103 / 2. 1.103
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2012-01-08 11:16:19
encoder : Lavf53.24.0
Duration: 00:03:31.58, start: 0.000000, bitrate: 2359 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2229 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
Metadata:
creation_time : 2012-01-08 11:16:19
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
Metadata:
creation_time : 2012-01-08 11:16:19
handler_name : SoundHandler
[srt @ 0x7fb8ea843c00] Estimating duration from bitrate, this may be inaccurate
Input #1, srt, from 'subs.srt':
Duration: N/A, bitrate: N/A
Stream #1:0: Subtitle: subrip
File 'out.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to 'out.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf53.24.0
Stream #0:0(eng): Video: h264, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 2229 kb/s, 25 fps, 90k tbn, 25 tbc
Metadata:
creation_time : 2012-01-08 11:16:19
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac, 48000 Hz, stereo, 125 kb/s
Metadata:
creation_time : 2012-01-08 11:16:19
handler_name : SoundHandler
Stream #0:2: Subtitle: none
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #1:0 -> #0:2 (subrip -> ?)
Encoder (codec none) not found for output stream #0:2
Encoding with -c:s mov_text works fine.
Change History (13)
comment:1 by , 13 years ago
| Version: | 1.1.2 → git-master |
|---|
comment:2 by , 13 years ago
| Keywords: | mov added; subtitles mp4 removed |
|---|
comment:3 by , 13 years ago
Oh, you're correct. The subtitle file had at the beginning of the video, and playing the file resulted in a black screen in QuickTime player (and crashed VLC).
Feel free to close this issue then.
(Any workaround for subtitles in MP4?)
follow-up: 5 comment:4 by , 13 years ago
| Blocked By: | → 1845 |
|---|
Instead of closing I'm going to consider this being blocked by #1845.
follow-up: 6 comment:5 by , 13 years ago
Replying to llogan:
Instead of closing I'm going to consider this being blocked by #1845.
I wonder if it isn't actually a bug that FFmpeg auto-selects ass for mkv if the input file contains subtitles: Many input files have subtitles that are not text based, trying to convert them (as is done by default) breaks re-encoding.
I am therefore mildly against changing the current mov behaviour.
comment:6 by , 13 years ago
Replying to cehoyos:
I wonder if it isn't actually a bug that FFmpeg auto-selects ass for mkv if the input file contains subtitles: Many input files have subtitles that are not text based, trying to convert them (as is done by default) breaks re-encoding.
I did not consider that. Thanks for pointing it out.
I am therefore mildly against changing the current mov behaviour.
I have no ideas/suggestions for now. Feel free to manage however you think is best.
follow-up: 8 comment:7 by , 9 years ago
I'm having a similar issue when trying to convert mkv container to mp4 without re-encoding.
An example file has the following streams:
Input #0, matroska,webm, from 'input.mkv':
Metadata:
CREATION_TIME : 2017-04-08T10:54:24Z
ENCODER : Lavf57.7.2
Duration: 00:22:23.34, start: 0.000000, bitrate: 964 kb/s
Chapter #0:0: start 0.033000, end 1343.300000
Metadata:
title : Chapter 1
Stream #0:0: Video: h264 (High), yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 704x480 [SAR 8:9 DAR 176:135], SAR 182:205 DAR 4004:3075, 23.98 fps, 23.98 tbr, 1k tbn, 180k tbc (default)
Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
Metadata:
title : English
Stream #0:2(eng): Subtitle: dvd_subtitle, 720x480
Stream #0:3(eng): Subtitle: ass
The command line I'd like to use fails with the following error:
ffmpeg -i input.mkv -map 0 -codec copy output.mp4 ... [mp4 @ 0x7fae14deed60] Could not find tag for codec ass in stream #3, codec not currently supported in container Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
It seems to work mostly with the following command line, but I have to manually specify the codec for that stream:
ffmpeg -i input.mkv -map 0 -codec copy -codec:3 mov_text output.mp4
It would be nice if ffmpeg would realize that the appropriate output codec for that subtitle track is mov_text.
comment:8 by , 9 years ago
Replying to domifm:
I'm having a similar issue when trying to convert mkv container to mp4 without re-encoding.
When you specify -c copy, you tell ffmpeg to copy the input file streams. It's therefore not ffmpeg's fault if those streams are not applicable for the output file.
This bug relates to what would happen if you did -c:v copy -c:a copy, having ffmpeg figure out how to convert the subtitle stream.
comment:9 by , 9 years ago
You are explicitly telling it not to automatically select codecs by writing -c copy.
comment:10 by , 9 years ago
| Blocked By: | 1845 |
|---|
With recent ffmpeg (testing 3.2.4 here), the error message now says:
$ ffmpeg -i video.mp4 -i subtitles.srt -c:v copy -c:a copy -map 0 -map 1 output.mp4 … Automatic encoder selection failed for output stream #0:2. Default encoder for format mp4 (codec none) is probably disabled. Please choose an encoder manually. Error selecting an encoder for stream 0:2
When using -c:s mov_text, the encoded video plays fine in QuickTime now. And #1845 seems to be fixed anyway.
So the mov_text codec autoselection for MOV/MP4 could now be implemented.
comment:11 by , 9 years ago
It's not as simple as using -c:s mov_text because there are other subtitle streams of other types that I want to keep.
If it could autoselect the codec when using -map 0 -c:v copy -c:a copy that would be great. Otherwise it is hard to batch convert files that have different numbering of the streams since each file has to be inspected and the stream numbers tailored.
comment:12 by , 9 years ago
If it could autoselect the codec when using -map 0 -c:v copy -c:a copy that would be great.
That's what it would do anyway.
If you do not specify -map 0 it will only take the first subtitle stream and re-encode it. (Or as currently implemented, not re-encode it, but fail.)
there are other subtitle streams of other types that I want to keep.
Then you need to specify -c:s:1 copy or whatever the stream index of the subtitle stream you want copied is.
comment:13 by , 3 years ago
| Cc: | added |
|---|---|
| Keywords: | mp4 added |
Six years after this issue is still present.
ffmpeg -i vidaud.mp4 -i subs.srt -map 0 -map 1 -c:v copy -c:a copy output.mp4
ffmpeg version 2022-11-28-git-becbb22eb0-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vidaud.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf59.34.102
Duration: 00:00:47.51, start: 0.000000, bitrate: 11153 kb/s
Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1620x1080 [SAR 1:1 DAR 3:2], 11020 kb/s, 24 fps, 24 tbr, 90k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](und): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
Metadata:
handler_name : SubtitleHandler
Input #1, srt, from 'subs.srt':
Duration: N/A, bitrate: N/A
Stream #1:0: Subtitle: subrip
Automatic encoder selection failed for output stream #0:2. Default encoder for format mp4 (codec none) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:2



Also broken in Git Master (git-2013-02-10-3acaea2)