请忍耐一下;我仍在学习 ffmpeg 的复杂性,并且遇到了字幕问题。
因此,我尝试将视频容器从 mkv 更改为 mp4,并同时将字幕硬编码到视频中,以便我的 Playstation 可以接受它们。
mkv结构如下:
ffmpeg version git-2013-09-23-34b429d Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 23 2013 18:16:42 with gcc 4.7 (Ubuntu/Linaro 4.7.3-1ubuntu1)
configuration: --prefix=/home/seb/ffmpeg_build --extra-cflags=-I/home/seb/ffmpeg_build/include --extra-ldflags=-L/home/seb/ffmpeg_build/lib --bindir=/home/seb/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
libavutil 52. 46.100 / 52. 46.100
libavcodec 55. 33.100 / 55. 33.100
libavformat 55. 18.102 / 55. 18.102
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 87.100 / 3. 87.100
libswscale 2. 5.100 / 2. 5.100
libswresample 0. 17.103 / 0. 17.103
libpostproc 52. 3.100 / 52. 3.100
[matroska,webm @ 0xa52ce60] Could not find codec parameters for stream 2 (Subtitle: hdmv_pgs_subtitle): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, matroska,webm, from 'entirely-innocent-video.mkv':
Metadata:
creation_time : 2014-11-15 09:27:00
Duration: 02:10:24.29, start: 0.000000, bitrate: 3838 kb/s
<--BLAH BLAH BLAH CHAPTERS -->
Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709), 1280x690 [SAR 1:1 DAR 128:69], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
BPS : 3196139
BPS-eng : 3196139
DURATION : 02:10:24.233000000
DURATION-eng : 02:10:24.233000000
NUMBER_OF_FRAMES: 187594
NUMBER_OF_FRAMES-eng: 187594
NUMBER_OF_BYTES : 3125917529
NUMBER_OF_BYTES-eng: 3125917529
_STATISTICS_WRITING_APP: mkvmerge v7.3.0 ('Nouages') 32bit built on Oct 22 2014 18:44:01
_STATISTICS_WRITING_APP-eng: mkvmerge v7.3.0 ('Nouages') 32bit built on Oct 22 2014 18:44:01
_STATISTICS_WRITING_DATE_UTC: 2014-11-15 09:27:00
_STATISTICS_WRITING_DATE_UTC-eng: 2014-11-15 09:27:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 640 kb/s (default)
Metadata:
BPS : 640000
BPS-eng : 640000
DURATION : 02:10:24.288000000
DURATION-eng : 02:10:24.288000000
NUMBER_OF_FRAMES: 244509
NUMBER_OF_FRAMES-eng: 244509
NUMBER_OF_BYTES : 625943040
NUMBER_OF_BYTES-eng: 625943040
_STATISTICS_WRITING_APP: mkvmerge v7.3.0 ('Nouages') 32bit built on Oct 22 2014 18:44:01
_STATISTICS_WRITING_APP-eng: mkvmerge v7.3.0 ('Nouages') 32bit built on Oct 22 2014 18:44:01
_STATISTICS_WRITING_DATE_UTC: 2014-11-15 09:27:00
_STATISTICS_WRITING_DATE_UTC-eng: 2014-11-15 09:27:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:2(eng): Subtitle: hdmv_pgs_subtitle (default) (forced)
Metadata:
BPS : 840
BPS-eng : 840
DURATION : 01:40:03.622000000
DURATION-eng : 01:40:03.622000000
NUMBER_OF_FRAMES: 252
NUMBER_OF_FRAMES-eng: 252
NUMBER_OF_BYTES : 630808
NUMBER_OF_BYTES-eng: 630808
_STATISTICS_WRITING_APP: mkvmerge v7.3.0 ('Nouages') 32bit built on Oct 22 2014 18:44:01
_STATISTICS_WRITING_APP-eng: mkvmerge v7.3.0 ('Nouages') 32bit built on Oct 22 2014 18:44:01
_STATISTICS_WRITING_DATE_UTC: 2014-11-15 09:27:00
_STATISTICS_WRITING_DATE_UTC-eng: 2014-11-15 09:27:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
然后我使用以下命令:
ffmpeg -i entirely-innocent-video -c:v copy -c:a copy -c:s mov_text entirely-innocent-video.mp4
据我所知,应该对视频进行重新编码,保持音频和视频不变,但在字幕中进行硬编码...但是它没有...它失败并显示以下消息:
Error while opening encoder for output stream #0:2 - maybe incorrect parameters such as bit_rate, rate, width or height
我就是搞不懂为什么!我尝试了 -c:s mov_text 命令的各种排列组合,但还是不断收到错误消息!
我猜想它与以下消息有关:
[matroska,webm @ 0xa52ce60] Could not find codec parameters for stream 2 (Subtitle: hdmv_pgs_subtitle): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
但是我对 ffmpeg 的经验还不够,不知道从哪里开始做任何事情......
你们当中有哪位聪明且经验丰富的人能帮我解开发生了什么事吗?:)
谢谢!
塞布
答案1
我认为 HDMV 演示图形流字幕 ( hdmv_pgs_subtitle
) 是基于图像的,而不是基于文本的,因此无法转换为文本,因为ffmpeg
目前不支持光学字符识别 (OCR)轉換。
硬字幕
您将能够创建硬字幕,但这意味着您必须重新编码视频:
ffmpeg -i in.mkv -filter_complex "[0:v][0:s]overlay[v]" -map "[v]" -map 0:a \
-c:a copy out.mp4
您可能需要使用scale
筛选如果字幕流大于您的视频,则调整其大小以使其适合(否则它们将在框架之外呈现并且不可见):
ffmpeg -i in.mkv -filter_complex "[0:s]scale=1280:-1[sub];[0:v][sub]overlay[v]" \
-map "[v]" -map 0:a -c:a copy out.mp4
或者你也可以直接用overlay
如果您不想扩展它们。
控制台ffmpeg
输出应显示输入的字幕帧大小,或者使用ffprobe
:
$ ffprobe -v error -of flat=s=_ -select_streams s:0 -show_entries stream=height,width input.mkv
streams_stream_0_width=1920
streams_stream_0_height=108
另请参阅:
软字幕
也许更好的选择是搜索合适的现有软字幕文件。我从来没有这样做过,显然我也懒得去研究它,所以我不知道是否有可用的。
请注意,MP4 不适合软字幕,因此mov_text
您的设备或播放器可能无法播放。