如何在保持纵横比的同时在 hls 输出上构建带有刻录文本的 ffmpeg
how to build ffmpeg with burn text on hls output while maintaining the aspect ratio
我的 objective 是在输出的 hls 视频上的特定时间范围内刻录文本(水印),我还必须仅更改高度并保持我能够做到的纵横比但是刻录文本部分不起作用。首先我使用的 ffmpeg 是 14.04 ubuntu,详细信息是 here. I don't think this build supports subtitle (docs) filter which I could have used for my purpose as described here。当我将 ffmpeg 输入终端时,这是输出
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ffmpeg
ffmpeg version N-78590-g5590ab4 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
libavutil 55. 18.100 / 55. 18.100
libavcodec 57. 24.103 / 57. 24.103
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 32.100 / 6. 32.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
我试过了
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" -profile:v baseline -level 4.0 -vf scale="trunc(360*a/2)*2:360, subtitles='subtitles.srt'" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
出现错误
[Parsed_subtitles_1 @ 0x2f1b7e0] Shaper: FriBidi 0.19.6 (SIMPLE) HarfBuzz-ng 0.9.27 (COMPLEX)
[Parsed_subtitles_1 @ 0x2f1b7e0] Unable to open subtitles.srt
[AVFilterGraph @ 0x2f1ac00] Error initializing filter 'subtitles' with args 'subtitles.srt'
Error opening filters!
然后我试了这个
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" -profile:v baseline -level 4.0 -vf "scale='trunc(360*a/2)*2:360', drawtext:drawtext" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
根据答案here 得到这个错误
[AVFilterGraph @ 0x2695c20] No such filter: 'drawtext:drawtext'
Error opening filters!
我也尝试了从 here 获得的静态构建,但仍然无法正常工作。我尝试了这个静态构建:
ffmpeg version N-63893-gc69defd Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 16 2014 05:38:01 with gcc 4.6 (Debian 4.6.3-1)
configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
libavutil 52. 89.100 / 52. 89.100
libavcodec 55. 66.101 / 55. 66.101
libavformat 55. 43.100 / 55. 43.100
libavdevice 55. 13.101 / 55. 13.101
libavfilter 4. 8.100 / 4. 8.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ./ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" -profile:v baseline -level 4.0 -vf scale="trunc(360*a/2)*2:360, subtitles='subtitle.srt'" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
但出现错误
Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory
如能提供这方面的帮助,我们将不胜感激。我没有太多的编译经验,否则我会像文档中提到的那样支持 libass here
尝试第一个可能的答案后的控制台输出:
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ls
bbb_sunflower_1080p_30fps_normal.mp4 ffmpeg_log_multiprocess.txt ffmpeg.static.64bit.latest input_sintel_trailer_720p.mp4 watermark.png
encoding_script.sh ffmpeg_log_simple.txt ffprobe subtitle.srt
ffmpeg ffmpeg_log.txt fontconfig videos
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ffmpeg -threads 4 -i input_sintel_trailer_720p.mp4 -profile:v baseline -level 4.0 -vf "scale=-2:360,subtitles='subtitle.srt'" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
ffmpeg version N-78590-g5590ab4 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
libavutil 55. 18.100 / 55. 18.100
libavcodec 57. 24.103 / 57. 24.103
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 32.100 / 6. 32.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input_sintel_trailer_720p.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01 00:00:00
title : Sintel Trailer
artist : Durian Open Movie Team
encoder : Lavf52.62.0
copyright : (c) copyright Blender Foundation | durian.blender.org
description : Trailer for the Sintel open movie project
Duration: 00:00:52.21, start: 0.000000, bitrate: 1165 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1033 kb/s, 24 fps, 24 tbr, 24 tbn, 48 tbc (default)
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name : SoundHandler
[Parsed_subtitles_1 @ 0x2bdb700] Shaper: FriBidi 0.19.6 (SIMPLE) HarfBuzz-ng 0.9.27 (COMPLEX)
[Parsed_subtitles_1 @ 0x2bdb700] Using font provider fontconfig
[libx264 @ 0x2bc8b60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x2bc8b60] profile Constrained Baseline, level 4.0
Output #0, hls, to 'videos/4444/index_4444_360_.m3u8':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
description : Trailer for the Sintel open movie project
title : Sintel Trailer
artist : Durian Open Movie Team
copyright : (c) copyright Blender Foundation | durian.blender.org
encoder : Lavf57.25.100
Stream #0:0(und): Video: h264 (libx264), yuv420p, 640x360, q=-1--1, 24 fps, 24 tbn, 24 tbc (default)
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name : VideoHandler
encoder : Lavc57.24.103 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1(und): Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name : SoundHandler
encoder : Lavc57.24.103 aac
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory
[aac @ 0x2bc9ac0] Qavg: -nan
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$
使用更新的 ffmpeg build #N-78590,它确实按照横幅启用了 libass
,尝试这些命令:
使用绘图文本
ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" \
-profile:v baseline -level 4.0 \
-vf "scale=-2:360,drawtext="fontfile=/path/to/font.ttf:fontcolor=white:fontsize=30:text='Your Text':x=(W-tw)/2:y=H-th-30"" \
-start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
使用字幕
ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" \
-profile:v baseline -level 4.0 \
-vf "scale=-2:360,subtitles='/path/to/subtitles.srt'" \
-start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
在@Mulvya 和来自 ffmpeg 组的 Mortiz 的一些指导之后,我终于能够得到我正在寻找的解决方案,我正在为任何正在寻找类似东西的人粘贴。我使用的 ffmpeg 很好(你可以得到我使用 here), there is a new static build which also works you can get it here 的 ffmpeg,正如 mortiz 所指出的,但是我使用的命令中的一些小错误是问题,对我有用的命令:
ffmpeg -threads 4 -i input_sintel_trailer_720p.mp4 -profile:v baseline -level 4.0 -vf "scale=-2:360,subtitles=subtitle.ass:force_style='FontName=Aaargh/Aaargh.ttf,PrimaryColour=&HAA00FF00" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls index_sub_ass_360_.m3u8
请注意,我使用 .ass 字幕文件来设置字幕的某些样式。对于搜索它的任何人,这里是 .ass 文件,其中包含两种不同字幕的两种不同样式:
[Script Info]
; Script generated by FFmpeg/Lavc57.24.103
ScriptType: v4.00+
PlayResX: 384
PlayResY: 288
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,5,10,10,10,0
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:10.00,0:00:10.04,Default,,0,0,0,,Senator, we're making\Nour final approach into Coruscant.
Dialogue: 0,0:00:30.00,0:00:30.05,Default,,0,0,0,,Very good, Lieutenant.
此外,我正在覆盖颜色和字体,正如 Mulvya 所提到的,"scale=-2:360" 部分保持纵横比。此外,我想参考一些帮助我达到这一点的重要链接:
ffmpeg 字幕文档 here
.ass 格式说明 here
带线程的 ffmpeg here
如果对那种外观感兴趣,我还为不同格式的 hls 视频创建了一个主列表 here
我与 mortiz 的讨论 here
使用 ffmpeg 检查将 .srt 转换为 .ass 字幕文件 this
希望这会有所帮助。
我的 objective 是在输出的 hls 视频上的特定时间范围内刻录文本(水印),我还必须仅更改高度并保持我能够做到的纵横比但是刻录文本部分不起作用。首先我使用的 ffmpeg 是 14.04 ubuntu,详细信息是 here. I don't think this build supports subtitle (docs) filter which I could have used for my purpose as described here。当我将 ffmpeg 输入终端时,这是输出
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ffmpeg
ffmpeg version N-78590-g5590ab4 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
libavutil 55. 18.100 / 55. 18.100
libavcodec 57. 24.103 / 57. 24.103
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 32.100 / 6. 32.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
我试过了
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" -profile:v baseline -level 4.0 -vf scale="trunc(360*a/2)*2:360, subtitles='subtitles.srt'" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
出现错误
[Parsed_subtitles_1 @ 0x2f1b7e0] Shaper: FriBidi 0.19.6 (SIMPLE) HarfBuzz-ng 0.9.27 (COMPLEX)
[Parsed_subtitles_1 @ 0x2f1b7e0] Unable to open subtitles.srt
[AVFilterGraph @ 0x2f1ac00] Error initializing filter 'subtitles' with args 'subtitles.srt'
Error opening filters!
然后我试了这个
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" -profile:v baseline -level 4.0 -vf "scale='trunc(360*a/2)*2:360', drawtext:drawtext" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
根据答案here 得到这个错误
[AVFilterGraph @ 0x2695c20] No such filter: 'drawtext:drawtext'
Error opening filters!
我也尝试了从 here 获得的静态构建,但仍然无法正常工作。我尝试了这个静态构建:
ffmpeg version N-63893-gc69defd Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 16 2014 05:38:01 with gcc 4.6 (Debian 4.6.3-1)
configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
libavutil 52. 89.100 / 52. 89.100
libavcodec 55. 66.101 / 55. 66.101
libavformat 55. 43.100 / 55. 43.100
libavdevice 55. 13.101 / 55. 13.101
libavfilter 4. 8.100 / 4. 8.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ./ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" -profile:v baseline -level 4.0 -vf scale="trunc(360*a/2)*2:360, subtitles='subtitle.srt'" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
但出现错误
Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory
如能提供这方面的帮助,我们将不胜感激。我没有太多的编译经验,否则我会像文档中提到的那样支持 libass here
尝试第一个可能的答案后的控制台输出:
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ls
bbb_sunflower_1080p_30fps_normal.mp4 ffmpeg_log_multiprocess.txt ffmpeg.static.64bit.latest input_sintel_trailer_720p.mp4 watermark.png
encoding_script.sh ffmpeg_log_simple.txt ffprobe subtitle.srt
ffmpeg ffmpeg_log.txt fontconfig videos
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$ ffmpeg -threads 4 -i input_sintel_trailer_720p.mp4 -profile:v baseline -level 4.0 -vf "scale=-2:360,subtitles='subtitle.srt'" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
ffmpeg version N-78590-g5590ab4 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
libavutil 55. 18.100 / 55. 18.100
libavcodec 57. 24.103 / 57. 24.103
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 32.100 / 6. 32.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input_sintel_trailer_720p.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01 00:00:00
title : Sintel Trailer
artist : Durian Open Movie Team
encoder : Lavf52.62.0
copyright : (c) copyright Blender Foundation | durian.blender.org
description : Trailer for the Sintel open movie project
Duration: 00:00:52.21, start: 0.000000, bitrate: 1165 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1033 kb/s, 24 fps, 24 tbr, 24 tbn, 48 tbc (default)
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name : SoundHandler
[Parsed_subtitles_1 @ 0x2bdb700] Shaper: FriBidi 0.19.6 (SIMPLE) HarfBuzz-ng 0.9.27 (COMPLEX)
[Parsed_subtitles_1 @ 0x2bdb700] Using font provider fontconfig
[libx264 @ 0x2bc8b60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x2bc8b60] profile Constrained Baseline, level 4.0
Output #0, hls, to 'videos/4444/index_4444_360_.m3u8':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
description : Trailer for the Sintel open movie project
title : Sintel Trailer
artist : Durian Open Movie Team
copyright : (c) copyright Blender Foundation | durian.blender.org
encoder : Lavf57.25.100
Stream #0:0(und): Video: h264 (libx264), yuv420p, 640x360, q=-1--1, 24 fps, 24 tbn, 24 tbc (default)
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name : VideoHandler
encoder : Lavc57.24.103 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1(und): Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name : SoundHandler
encoder : Lavc57.24.103 aac
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory
[aac @ 0x2bc9ac0] Qavg: -nan
(ffmpeg)aameer@falcon:~/Documents/projects/ffmpeg$
使用更新的 ffmpeg build #N-78590,它确实按照横幅启用了 libass
,尝试这些命令:
使用绘图文本
ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" \
-profile:v baseline -level 4.0 \
-vf "scale=-2:360,drawtext="fontfile=/path/to/font.ttf:fontcolor=white:fontsize=30:text='Your Text':x=(W-tw)/2:y=H-th-30"" \
-start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
使用字幕
ffmpeg -threads 4 -i "input_sintel_trailer_720p.mp4" \
-profile:v baseline -level 4.0 \
-vf "scale=-2:360,subtitles='/path/to/subtitles.srt'" \
-start_number 0 -hls_time 10 -hls_list_size 0 -f hls videos/4444/index_4444_360_.m3u8
在@Mulvya 和来自 ffmpeg 组的 Mortiz 的一些指导之后,我终于能够得到我正在寻找的解决方案,我正在为任何正在寻找类似东西的人粘贴。我使用的 ffmpeg 很好(你可以得到我使用 here), there is a new static build which also works you can get it here 的 ffmpeg,正如 mortiz 所指出的,但是我使用的命令中的一些小错误是问题,对我有用的命令:
ffmpeg -threads 4 -i input_sintel_trailer_720p.mp4 -profile:v baseline -level 4.0 -vf "scale=-2:360,subtitles=subtitle.ass:force_style='FontName=Aaargh/Aaargh.ttf,PrimaryColour=&HAA00FF00" -start_number 0 -hls_time 10 -hls_list_size 0 -f hls index_sub_ass_360_.m3u8
请注意,我使用 .ass 字幕文件来设置字幕的某些样式。对于搜索它的任何人,这里是 .ass 文件,其中包含两种不同字幕的两种不同样式:
[Script Info]
; Script generated by FFmpeg/Lavc57.24.103
ScriptType: v4.00+
PlayResX: 384
PlayResY: 288
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,5,10,10,10,0
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:10.00,0:00:10.04,Default,,0,0,0,,Senator, we're making\Nour final approach into Coruscant.
Dialogue: 0,0:00:30.00,0:00:30.05,Default,,0,0,0,,Very good, Lieutenant.
此外,我正在覆盖颜色和字体,正如 Mulvya 所提到的,"scale=-2:360" 部分保持纵横比。此外,我想参考一些帮助我达到这一点的重要链接:
ffmpeg 字幕文档 here .ass 格式说明 here 带线程的 ffmpeg here 如果对那种外观感兴趣,我还为不同格式的 hls 视频创建了一个主列表 here 我与 mortiz 的讨论 here 使用 ffmpeg 检查将 .srt 转换为 .ass 字幕文件 this 希望这会有所帮助。