├── src ├── subtitle │ ├── edit │ │ ├── README.md │ │ └── aegisub.md │ ├── background │ │ ├── README.md │ │ ├── type.md │ │ └── format.md │ ├── README.md │ ├── extract │ │ └── README.md │ ├── embed │ │ ├── config_text_attrib.md │ │ ├── README.md │ │ └── config_position.md │ └── convert │ │ └── README.md ├── video_process │ ├── watermark │ │ ├── README.md │ │ └── remove_watermark.md │ ├── property │ │ ├── README.md │ │ ├── adjust │ │ │ ├── README.md │ │ │ └── resolution.md │ │ └── get │ │ │ └── README.md │ ├── motion_gif │ │ ├── README.md │ │ ├── video_to_gif.md │ │ └── gif_to_video.md │ ├── README.md │ └── extract_audio.md ├── appendix │ ├── README.md │ ├── doc.md │ ├── reference.md │ └── help.md ├── audio_process │ ├── README.md │ └── extract_audio_segment.md ├── assets │ ├── favicon.ico │ └── img │ │ ├── ffserver_arch.png │ │ ├── aegisub_mac_dmg.png │ │ ├── aegisub_main_ui.png │ │ ├── aegisub_org_home.png │ │ ├── aegisub_copy_to_right.png │ │ ├── aegisub_open_ass_file.png │ │ ├── ass_subtitle_example.png │ │ ├── embed_ass_effect_demo.png │ │ ├── subtitle_ass_aligment.png │ │ ├── watermark_demo_after.png │ │ ├── watermark_demo_before.png │ │ ├── aegisub_adjust_property.png │ │ ├── aegisub_default_preview.png │ │ ├── aegisub_style_overwrite.png │ │ ├── ffmpeg_already_exists_y.png │ │ ├── ass_subtitle_file_example.png │ │ ├── adjust_video_size_bkg_white.png │ │ ├── aegisub_compare_susbtitle_diff.png │ │ ├── aegisub_style_manager_default.png │ │ ├── aegisub_subtitle_style_manager.png │ │ ├── aegisub_video_subtitle_effect.png │ │ ├── ffplay_play_video_show_delogo.png │ │ ├── subtitle_set_attribute_effect.png │ │ ├── watermark_debug_green_position.png │ │ └── adjust_video_size_multi_property.png ├── ffmpeg_overview │ ├── related.md │ └── README.md ├── use_ffmpeg │ ├── README.md │ └── python.md ├── ffmpeg_install │ └── README.md ├── SUMMARY.md ├── README.md └── ffmpeg_summary │ └── README.md ├── Makefile ├── .gitignore ├── README_current.json ├── book_current.json ├── README.md └── book.json /src/subtitle/edit/README.md: -------------------------------------------------------------------------------- 1 | # 编辑字幕 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include ../../common/gitbook_makefile.mk -------------------------------------------------------------------------------- /src/subtitle/background/README.md: -------------------------------------------------------------------------------- 1 | # 字幕背景知识 2 | -------------------------------------------------------------------------------- /src/video_process/watermark/README.md: -------------------------------------------------------------------------------- 1 | # 水印 2 | -------------------------------------------------------------------------------- /src/appendix/README.md: -------------------------------------------------------------------------------- 1 | # 附录 2 | 3 | 下面列出相关参考资料。 4 | -------------------------------------------------------------------------------- /src/video_process/property/README.md: -------------------------------------------------------------------------------- 1 | # 视频属性 2 | 3 | -------------------------------------------------------------------------------- /src/video_process/motion_gif/README.md: -------------------------------------------------------------------------------- 1 | # 动图gif 2 | 3 | -------------------------------------------------------------------------------- /src/audio_process/README.md: -------------------------------------------------------------------------------- 1 | # 音频处理 2 | 3 | 此处整理用ffmpeg处理音频文件。 4 | -------------------------------------------------------------------------------- /src/video_process/README.md: -------------------------------------------------------------------------------- 1 | # 视频处理 2 | 3 | 此处整理用ffmpeg处理视频文件。 4 | -------------------------------------------------------------------------------- /src/subtitle/README.md: -------------------------------------------------------------------------------- 1 | # 字幕处理 2 | 3 | 此处介绍,视频中的字幕相关处理,比如合并、嵌入、烧录,转换等等。 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | output/ 3 | debug/ 4 | 5 | *.zip 6 | 7 | .DS_Store 8 | 9 | !src/**/output -------------------------------------------------------------------------------- /src/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/favicon.ico -------------------------------------------------------------------------------- /src/assets/img/ffserver_arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/ffserver_arch.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_mac_dmg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_mac_dmg.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_main_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_main_ui.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_org_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_org_home.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_copy_to_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_copy_to_right.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_open_ass_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_open_ass_file.png -------------------------------------------------------------------------------- /src/assets/img/ass_subtitle_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/ass_subtitle_example.png -------------------------------------------------------------------------------- /src/assets/img/embed_ass_effect_demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/embed_ass_effect_demo.png -------------------------------------------------------------------------------- /src/assets/img/subtitle_ass_aligment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/subtitle_ass_aligment.png -------------------------------------------------------------------------------- /src/assets/img/watermark_demo_after.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/watermark_demo_after.png -------------------------------------------------------------------------------- /src/assets/img/watermark_demo_before.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/watermark_demo_before.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_adjust_property.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_adjust_property.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_default_preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_default_preview.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_style_overwrite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_style_overwrite.png -------------------------------------------------------------------------------- /src/assets/img/ffmpeg_already_exists_y.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/ffmpeg_already_exists_y.png -------------------------------------------------------------------------------- /src/assets/img/ass_subtitle_file_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/ass_subtitle_file_example.png -------------------------------------------------------------------------------- /src/assets/img/adjust_video_size_bkg_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/adjust_video_size_bkg_white.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_compare_susbtitle_diff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_compare_susbtitle_diff.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_style_manager_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_style_manager_default.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_subtitle_style_manager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_subtitle_style_manager.png -------------------------------------------------------------------------------- /src/assets/img/aegisub_video_subtitle_effect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/aegisub_video_subtitle_effect.png -------------------------------------------------------------------------------- /src/assets/img/ffplay_play_video_show_delogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/ffplay_play_video_show_delogo.png -------------------------------------------------------------------------------- /src/assets/img/subtitle_set_attribute_effect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/subtitle_set_attribute_effect.png -------------------------------------------------------------------------------- /src/assets/img/watermark_debug_green_position.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/watermark_debug_green_position.png -------------------------------------------------------------------------------- /src/assets/img/adjust_video_size_multi_property.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/media_process_ffmpeg/HEAD/src/assets/img/adjust_video_size_multi_property.png -------------------------------------------------------------------------------- /src/video_process/motion_gif/video_to_gif.md: -------------------------------------------------------------------------------- 1 | # 视频转动图gif 2 | 3 | ## 视频转成动图(gif) 4 | 5 | ```bash 6 | ffmpeg -i small.mp4 small.gif 7 | ``` 8 | 9 | ## 转化视频中的一部分为 GIF 10 | 11 | 从视频中第二秒开始,截取时长为3秒的片段转化为 gif 12 | 13 | ```bash 14 | ffmpeg -t 3 -ss 00:00:02 -i small.webm small-clip.gif 15 | ``` 16 | 17 | ## 转化高质量 GIF 18 | 19 | 默认转化是中等质量模式,若要转化出高质量的 gif,可以修改比特率 20 | 21 | ```bash 22 | ffmpeg -i small.mp4 -b 2048k small.gif 23 | ``` 24 | -------------------------------------------------------------------------------- /src/appendix/doc.md: -------------------------------------------------------------------------------- 1 | # 文档 2 | 3 | * ffmpeg的官网文档 4 | * ffmpeg Documentation 5 | * https://ffmpeg.org/ffmpeg.html 6 | * Documentation 7 | * https://www.ffmpeg.org/documentation.html 8 | * ffmpeg Documentation 9 | * https://www.ffmpeg.org/ffmpeg-all.html 10 | * FFmpeg Utilities Documentation 11 | * https://ffmpeg.org/ffmpeg-utils.html 12 | * FFmpeg Codecs Documentation 13 | * https://www.ffmpeg.org/ffmpeg-codecs.html 14 | -------------------------------------------------------------------------------- /src/subtitle/background/type.md: -------------------------------------------------------------------------------- 1 | # 字幕分类 2 | 3 | 根据字幕信息嵌入到视频中的方式,可以把字幕分为: 4 | 5 | * 软字幕 6 | * 特点 7 | * 过程可逆 8 | * 可以提取出字幕文件,查看字幕源代码 9 | * 包含 10 | * 内挂字幕 11 | * 一般指字幕文件与视频一同封装在MKV文件中,播放时需经过播放器处理解析显示(=VSFilter渲染) 12 | * 外挂字幕 13 | * 以单独的字幕文件形式存在,播放时经播放器处理解析显示(=VSFilter渲染)到视频上 14 | * 硬字幕=内嵌字幕 15 | * 指字幕被以图形方式硬编码到视频中 16 | * 变成视频数据本身=视频数据的一部分 17 | * 特点 18 | * 过程不可逆 19 | * 无法再把字幕提取出来 20 | * 播放时不需要额外的播放器读取解析显示(=VSFilter渲染)字幕 -------------------------------------------------------------------------------- /src/video_process/property/adjust/README.md: -------------------------------------------------------------------------------- 1 | # 视频属性调整 2 | 3 | ## 播放速率 4 | 5 | ### 加倍速播放视频 6 | 7 | ```bash 8 | ffmpeg -i input.mov -filter:v "setpts=0.5*PTS" output.mov 9 | ``` 10 | 11 | ### 慢倍速播放视频 12 | 13 | ```bash 14 | ffmpeg -i input.mov -filter:v "setpts=2.0*PTS" output.mov 15 | ``` 16 | 17 | ## 定义帧率 16fps 18 | 19 | ```bash 20 | ffmpeg -i input.mov -r 16 -filter:v "setpts=0.125*PTS" -an output.mov 21 | ``` 22 | 23 | ## 静音视频(移除视频中的音频) 24 | 25 | ```bash 26 | ffmpeg -i input.mov -an mute-output.mov 27 | ``` 28 | 29 | * 说明 30 | * `-an`就是禁止音频输出 31 | -------------------------------------------------------------------------------- /README_current.json: -------------------------------------------------------------------------------- 1 | { 2 | "latestVersion": "v1.0", 3 | "lastUpdate": "20210914", 4 | "gitRepoName": "media_process_ffmpeg", 5 | "bookName": "强大的音视频处理工具:FFmpeg", 6 | "bookDescription": "介绍音视频处理工具FFmpeg有哪些强大的功能。先对ffmpeg进行概览,包括可以用来干什么,与之相关的ffprobe、ffplay、ffserver等工具;再介绍如何安装ffmpeg;如何用ffmpeg处理音频,比如从音频中提取某段音频片段;以及各种视频处理,包括视频属性的获取和调整,包括调整视频宽高尺寸大小;以及动图gif处理,包括视频转动图、动图转视频;以及水印处理,包括去除视频水印;从视频中提取完整音频和音频片段;字幕相关处理,包括字幕的背景知识,包括软字幕和硬字幕、常见字幕格式ass和srt;以及如何用Aegisub编辑字幕;从视频中提取字幕、从srt转换出ass字幕;嵌入字幕,包括用流拷贝模式嵌入软字幕、用vf模式烧录嵌入硬字幕、且可以指定字幕位置、指定字幕文字属性等;整理ffmpeg使用的心得和常见问题;以及其他有哪些工具软件用到了ffmpeg、如何用Python调用ffmpeg;最后给出附录内容,包括help语法、文档资料等。" 7 | } -------------------------------------------------------------------------------- /src/ffmpeg_overview/related.md: -------------------------------------------------------------------------------- 1 | # FFmpeg相关 2 | 3 | ## ffmpeg与相关的ffprobe,ffplay,ffserver的区别 4 | 5 | * ffmpeg:处理音视频 6 | * ffprobe:检测音视频 -》 获取相关文件的属性和信息 7 | * ffplay:播放音视频及其他一些辅助功能 8 | * 辅助功能举例: 9 | * 播放视频并显示水印位置:便于发现水印位置是否准确 10 | ```bash 11 | ffplay -f lavfi -i "movie=course_59485_video_normalWatermark.mp4,delogo=x=490:y=30:w=130:h=50:show=1" 12 | ``` 13 | * 播放效果: 14 | * ![ffplay_play_video_show_delogo](../assets/img/ffplay_play_video_show_delogo.png) 15 | * -》方便看出要去除的水印的位置有偏差 16 | * 可以后续再调整参数值,让去除水印的区域更加准确 17 | * ffserver:搭建流媒体服务器 -》用来支持其他端去播放音视频 18 | * ![ffserver_arch](../assets/img/ffserver_arch.png) 19 | -------------------------------------------------------------------------------- /src/video_process/extract_audio.md: -------------------------------------------------------------------------------- 1 | # 从视频中提取音频 2 | 3 | 此处整理,从视频文件中提取音频相关内容。 4 | 5 | ## 从mp4中提取音频mp3 6 | 7 | ### 提取整个音频 8 | 9 | ```bash 10 | ffmpeg -i show_14322648_video.mp4 -b:a 128k show_14322648_audio.mp3 11 | ``` 12 | 13 | ### 提取音频片段 14 | 15 | ```bash 16 | ffmpeg -i show_157712932_video.mp4 -ss 00:00:11.270 -to 00:00:14.550 -b:a 128k show_157712932_audio_000011270_000014550.mp3 17 | ``` 18 | * 参数解释 19 | ```bash 20 | usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... 21 | 22 | -ss time_off set the start time offset 23 | -to time_stop record or transcode stop time 24 | 25 | -ab bitrate audio bitrate (please use -b:a) 26 | ``` 27 | -------------------------------------------------------------------------------- /src/video_process/motion_gif/gif_to_video.md: -------------------------------------------------------------------------------- 1 | # 动图转视频 2 | 3 | ## gif转mp4 4 | 5 | ```bash 6 | ffmpeg -f gif -i animation.gif animation.mp4 7 | ``` 8 | 9 | ## 特殊:gif转出来的mp4播放不了? 10 | 11 | 有些gif转化出来的mp4不能被Mac的`QuickTime Player.app` 播放,需要添加`pixel formal`参数 12 | 13 | ```bash 14 | ffmpeg -i input.gif -vf scale=420:-2,format=yuv420p out.mp4 15 | ``` 16 | 17 | * 说明 18 | * 使用 yunv420p 需要保证长宽为偶数,这里同时使用了`scale=420:-2` 19 | * [wiki中解释](https://trac.ffmpeg.org/wiki/Encode/H.264#Encodingfordumbplayers): QuickTime Player 对 H.264 视频只支持 YUV 色域 4:2:0 方式的二次插值算法 20 | 21 | ## gif转其他视频格式 22 | 23 | ```bash 24 | ffmpeg -f gif -i animation.gif animation.mpeg 25 | ffmpeg -f gif -i animation.gif animation.webm 26 | ``` 27 | -------------------------------------------------------------------------------- /src/subtitle/extract/README.md: -------------------------------------------------------------------------------- 1 | # 提取字幕 2 | 3 | 从视频中提取字幕文件 4 | 5 | * 前提 6 | * 原视频中有字幕(的流)= 有soft`软字幕` 7 | * 特殊情况: 8 | * 有种字幕是被合并编码成视频数据本身的情况,是没有字幕的 9 | * 这种视频 表面上看有字幕显示出来,但是无法提取出字幕的 10 | 11 | 12 | ## 从视频中提取srt字幕 13 | 14 | 命令: 15 | 16 | ```bash 17 | ffmpeg -i video_file.mp4 -map 0:s:0 subtitle.srt 18 | ``` 19 | 20 | 参数含义: 21 | 22 | * `-i video_file.mp4`: 23 | * input输入文件是video_file.mp4 24 | * `-map 0:s:0 subtitle.srt`的含义: 25 | * `-map`:高级参数 26 | * `0:s:0`: 27 | * `0` -> `input_file_id`=`文件id`,输入的文件索引编号 28 | * 此处就一个文件,所以`0`表示此处输入的mp4视频:video_file.mp4 29 | * `:s` -> `:stream_specifier`, 流stream选择的是字幕subtitle 30 | * `:0` -> `:stream_specifier` 第`0`个字幕 31 | * 此处只有一个字幕,就是这个唯一的字幕 32 | * `subtitle.srt`:输出的字幕文件名 33 | -------------------------------------------------------------------------------- /src/use_ffmpeg/README.md: -------------------------------------------------------------------------------- 1 | # 用到ffmpeg的 2 | 3 | 此处整理,内部用到了ffmpeg的一些相关内容: 4 | 5 | * `pydub`:Python的音频处理库 6 | * jiaaro/pydub: Manipulate audio with a simple and easy high level interface 7 | * https://github.com/jiaaro/pydub 8 | * 底层是用ffmpeg去实现音视频的处理的 9 | * `audioread`:Python的音频解析库 10 | * beetbox/audioread: cross-library (GStreamer + Core Audio + MAD + FFmpeg) audio decoding for Python 11 | * https://github.com/beetbox/audioread 12 | * 底层是通过ffmpeg去解析出音频信息 13 | * `Gifski` 14 | * GitHub 15 | * sindresorhus/Gifski: 🌈 Convert videos to high-quality GIFs on your Mac 16 | * https://github.com/sindresorhus/Gifski 17 | * 举例 18 | * 把多张PNG图片,转换成gif动图: 19 | ```bash 20 | TMPFILE="$(mktemp /tmp/XXXXXXXXXXX).mov"; \ 21 | ffmpeg -f image2 -framerate 30 -i image_%06d.png -c:v prores_ks -profile:v 5 "$TMPFILE" \ 22 | && open -a Gifski "$TMPFILE" 23 | ``` 24 | -------------------------------------------------------------------------------- /book_current.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "强大的音视频处理工具:FFmpeg", 3 | "description": "介绍音视频处理工具FFmpeg有哪些强大的功能。先对ffmpeg进行概览,包括可以用来干什么,与之相关的ffprobe、ffplay、ffserver等工具;再介绍如何安装ffmpeg;如何用ffmpeg处理音频,比如从音频中提取某段音频片段;以及各种视频处理,包括视频属性的获取和调整,包括调整视频宽高尺寸大小;以及动图gif处理,包括视频转动图、动图转视频;以及水印处理,包括去除视频水印;从视频中提取完整音频和音频片段;字幕相关处理,包括字幕的背景知识,包括软字幕和硬字幕、常见字幕格式ass和srt;以及如何用Aegisub编辑字幕;从视频中提取字幕、从srt转换出ass字幕;嵌入字幕,包括用流拷贝模式嵌入软字幕、用vf模式烧录嵌入硬字幕、且可以指定字幕位置、指定字幕文字属性等;整理ffmpeg使用的心得和常见问题;以及其他有哪些工具软件用到了ffmpeg、如何用Python调用ffmpeg;最后给出附录内容,包括help语法、文档资料等。", 4 | "pluginsConfig": { 5 | "autocover": { 6 | "title": "Gitbook演示" 7 | }, 8 | "github-buttons": { 9 | "buttons": [ 10 | { 11 | "repo": "media_process_ffmpeg" 12 | } 13 | ] 14 | }, 15 | "sitemap-general": { 16 | "prefix": "https://book.crifan.com/books/media_process_ffmpeg/website/" 17 | }, 18 | "toolbar-button": { 19 | "url": "https://book.crifan.com/books/media_process_ffmpeg/pdf/media_process_ffmpeg.pdf" 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/video_process/watermark/remove_watermark.md: -------------------------------------------------------------------------------- 1 | # 去除视频水印 2 | 3 | 用ffmpeg去除视频水印 4 | 5 | 举例: 6 | 7 | ```bash 8 | ffmpegCmd=ffmpeg -i course_16335_video_normalWatermark_864w360h.mp4 -vf "delogo=x=714:y=28:w=130:h=50" -c:a copy course_16335_video_normalWatermark_864w360h_removedWatermarked.mp4 9 | ``` 10 | 11 | 参数解释: 12 | * `x`和`y`是以**左上角**为原点的坐标 13 | * `w`和`h`是水印的矩形区域的宽度和高度 14 | 15 | 效果: 16 | 17 | * 去水印前 18 | * ![watermark_demo_before](../../assets/img/watermark_demo_before.png) 19 | * 去水印后 20 | * ![watermark_demo_after](../../assets/img/watermark_demo_after.png) 21 | 22 | ## 调试:如何确定水印的区域 23 | 24 | 另外,在去除水印之前,可以借助于ffplay去播放,给水印区域加上绿色框: 25 | 26 | ```bash 27 | ffplay -f lavfi -i "movie=video_file.mp4,delogo=x=11:y=22:w=33:h=44:show=1" 28 | ``` 29 | 30 | 便于识别水印位置对不对。 31 | 32 | 举例: 33 | 34 | ```bash 35 | ffplay -f lavfi -i "movie=course_59485_video_normalWatermark.mp4,delogo=x=490:y=30:w=130:h=50:show=1" 36 | ``` 37 | 38 | 可看到右上角的区域,加上了绿色边框: 39 | 40 | ![watermark_debug_green_position](../../assets/img/watermark_debug_green_position.png) 41 | 42 | 可以看出水印矩形区域的位置明显不对,和希望的位置有偏差,然后继续去调整`x`、`y`、`w`、`h`参数即可。 43 | -------------------------------------------------------------------------------- /src/subtitle/embed/config_text_attrib.md: -------------------------------------------------------------------------------- 1 | # 指定字幕文字属性 2 | 3 | 此处介绍嵌入字幕时,指定字幕文字的各种属性,比如`字体大小`、`字体类型`、`颜色`、`透明度`等 4 | 5 | * srt字幕:加force_style参数 6 | ```bash 7 | ffmpeg -i video.mp4 -vf "subtitles=subs.srt:force_style='Fontsize=24,PrimaryColour=&H0000ff&'" -c:a copy output.mp4 8 | ``` 9 | * ass字幕:在ass字幕中设置参数 10 | ```bash 11 | Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow 12 | ``` 13 | 14 | 具体设置成什么值,以及效果如何,可借助于软件Aegisub去设置和预览 15 | 16 | ### 举例1 17 | 18 | ```bash 19 | Style: Transparent,PingFang SC,20,&H00FFFFFF,&H000000FF,&HBC5E5E5E,&H8B000000,0,0,0,0,100,100,0,0,3,0,1,2,10,10,10,134 20 | ``` 21 | 22 | 实现了字幕效果: 23 | 24 | * 字体:PingFang SC 25 | * 字体大小:20 26 | * 字幕的背景半透明效果:后面很多参数组合的效果 27 | 28 | 如图: 29 | 30 | ![subtitle_set_attribute_effect](../../assets/img/subtitle_set_attribute_effect.png) 31 | 32 | ### 举例2:ass设置半透明的背景 33 | 34 | ```bash 35 | Style: Default,Arial,16,&H00FFFFFF,&H000000FF,&H80000000,&H80000000,-1,0,0,0,100,100,0,0,4,0,0,2,10,10,10,1 36 | ``` 37 | 38 | 即可达到要的字幕有个半透明的背景色了。 39 | 40 | 其中`16`指的是`字体大小`,可以根据需要更改为自己要的值。 41 | -------------------------------------------------------------------------------- /src/ffmpeg_install/README.md: -------------------------------------------------------------------------------- 1 | # FFmpeg安装 2 | 3 | ## Mac 4 | 5 | ## 只安装ffmpeg 6 | 7 | ```bash 8 | brew install ffmpeg 9 | ``` 10 | 11 | 如果想要加上很多其他`filter`=`功能模块`,则可以加上对应参数: 12 | 13 | ```bash 14 | brew reinstall ffmpeg \ 15 | --with-tools \ 16 | --with-fdk-aac \ 17 | --with-freetype \ 18 | --with-fontconfig \ 19 | --with-libass \ 20 | --with-libvorbis \ 21 | --with-libvpx \ 22 | --with-opus \ 23 | --with-x265 24 | ``` 25 | 26 | ## 安装ffmpeg,和相关ffprobe,ffplay,甚至ffserver 27 | 28 | 去官网 29 | 30 | [Download FFmpeg](https://ffmpeg.org/download.html) 31 | 32 | https://ffmpeg.org/download.html 33 | 34 | 提到的: 35 | 36 | [static FFmpeg binaries for macOS 64-bit](https://evermeet.cx/ffmpeg/) 37 | 38 | 去下载最新版本: 39 | 40 | * `ffmpeg`:https://evermeet.cx/ffmpeg/ffmpeg-4.2.7z 41 | * `ffprobe`:https://evermeet.cx/ffmpeg/ffprobe-4.2.7z 42 | * `ffplay`:https://evermeet.cx/ffmpeg/ffplay-4.2.7z 43 | * `ffserver`:https://evermeet.cx/ffmpeg/ffserver-3.4.2.7z 44 | 45 | 分别下载后,解压得到二进制文件,再拷贝到合适目录。 46 | 47 | 比如Mac中的: 48 | 49 | `/usr/local/bin` 50 | 51 | 即可。 52 | 53 | 问:如何确认已安装好? 54 | 55 | 用which去确认 56 | 57 | ```bash 58 | which ffmpeg 59 | which ffprobe 60 | which ffplay 61 | which ffserver 62 | ``` 63 | 64 | 去确认能找到 65 | 66 | 以及顺带去看看版本 67 | 68 | ```bash 69 | ffmpeg -version 70 | ffprobe -version 71 | ffplay -version 72 | ffserver -version 73 | ``` 74 | -------------------------------------------------------------------------------- /src/use_ffmpeg/python.md: -------------------------------------------------------------------------------- 1 | # Python 2 | 3 | 此处整理,用Python调用ffmpeg,实现音视频处理期间的相关内容。 4 | 5 | ## ffmpeg相关库函数 6 | 7 | 之前已把相关的,Python中调用ffmpeg去处理音视频相关的功能,封装成函数: 8 | 9 | https://github.com/crifan/crifanLibPython/blob/master/python3/crifanLib/thirdParty/crifanFfmpeg.py 10 | 11 | 其中就有: 12 | 13 | * `removeVideoWatermark`:去除视频水印 14 | * `detectVideoDimension`:获取视频属性 15 | 16 | 需要的,可以直接拿去用。 17 | 18 | ## 用Python调用ffmpeg 19 | 20 | ### 用python代码调用ffmpeg去从mp4中(根据字幕信息)截图mp3音频片段 21 | 22 | ```bash 23 | import subprocess 24 | # extract audio segment from video 25 | # ffmpeg -i show_157712932_video.mp4 -ss 00:00:11.270 -to 00:00:14.550 -b:a 128k show_157712932_audio_000011270_000014550.mp3 26 | if not os.path.exists(curAudioSegmentFullpath): 27 | ffmpegCmd = "ffmpeg -i %s -ss %s -to %s -b:a 128k %s" % (showVideoFullpath, startTimeStr, endTimeStr, curAudioSegmentFullpath) 28 | subprocess.call(ffmpegCmd, shell=True) 29 | ``` 30 | 31 | ## 心得:加`-nostdin`避免后台模式运行时卡死 32 | 33 | Python代码中调用ffmpeg去处理视频,比如: 34 | 35 | ```bash 36 | ffmpeg -i input_video.mp4 -vf "delogo=x=474:y=6:w=162:h=90" -c:a copy input_video_removedWatermark.mp4 37 | ``` 38 | 39 | 然后正常运行Python时: 40 | 41 | ```bash 42 | python3 processCourseVideo.py 43 | ``` 44 | 45 | 没问题。 46 | 47 | 后台运行时: 48 | 49 | ```bash 50 | python3 processCourseVideo.py & 51 | ``` 52 | 53 | 结果会卡死。 54 | 55 | 后来发现:需要给`ffmpeg`加`-nostdin`参数: 56 | 57 | ```bash 58 | ffmpeg -nostdin -i input_video.mp4 -vf "delogo=x=474:y=6:w=162:h=90" -c:a copy input_video_removedWatermark.mp4 59 | ``` 60 | 61 | 能避免卡死。 62 | 63 | 详见: 64 | 65 | 【已解决】后台运行Python代码导致subprocess.check_call调用ffmpeg卡死 66 | -------------------------------------------------------------------------------- /src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # 强大的音视频处理工具:FFmpeg 2 | 3 | * [前言](README.md) 4 | * [FFmpeg概览](ffmpeg_overview/README.md) 5 | * [FFmpeg相关](ffmpeg_overview/related.md) 6 | * [FFmpeg安装](ffmpeg_install/README.md) 7 | * [音频处理](audio_process/README.md) 8 | * [提取音频片段](audio_process/extract_audio_segment.md) 9 | * [视频处理](video_process/README.md) 10 | * [视频属性](video_process/property/README.md) 11 | * [获取](video_process/property/get/README.md) 12 | * [调整](video_process/property/adjust/README.md) 13 | * [尺寸调整](video_process/property/adjust/resolution.md) 14 | * [动图gif](video_process/motion_gif/README.md) 15 | * [视频转动图](video_process/motion_gif/video_to_gif.md) 16 | * [动图转视频](video_process/motion_gif/gif_to_video.md) 17 | * [水印](video_process/watermark/README.md) 18 | * [去除水印](video_process/watermark/remove_watermark.md) 19 | * [提取音频](video_process/extract_audio.md) 20 | * [字幕处理](subtitle/README.md) 21 | * [背景知识](subtitle/background/README.md) 22 | * [字幕分类](subtitle/background/type.md) 23 | * [字幕格式](subtitle/background/format.md) 24 | * [编辑字幕](subtitle/edit/README.md) 25 | * [Aegisub](subtitle/edit/aegisub.md) 26 | * [提取字幕](subtitle/extract/README.md) 27 | * [转换字幕](subtitle/convert/README.md) 28 | * [嵌入字幕](subtitle/embed/README.md) 29 | * [指定字幕位置](subtitle/embed/config_position.md) 30 | * [指定字幕文字属性](subtitle/embed/config_text_attrib.md) 31 | * [ffmpeg使用心得](ffmpeg_summary/README.md) 32 | * [用到ffmpeg的](use_ffmpeg/README.md) 33 | * [Python](use_ffmpeg/python.md) 34 | * [附录](appendix/README.md) 35 | * [help语法](appendix/help.md) 36 | * [文档](appendix/doc.md) 37 | * [参考资料](appendix/reference.md) 38 | -------------------------------------------------------------------------------- /src/ffmpeg_overview/README.md: -------------------------------------------------------------------------------- 1 | # FFmpeg概览 2 | 3 | * `FFmpeg` 4 | * 是什么:一个,功能极其强大的,音视频处理相关的库 5 | 6 | ## ffmpeg能用来干什么? 7 | 8 | 可以用`ffmpeg`做很多和音视频相关的处理。 9 | 10 | 绝大多数和音频视频字幕等相关的操作,ffmpeg都支持。 11 | 12 | 列举我之前遇到过的一些,供参考: 13 | 14 | * 解析出视频的信息 15 | * 举例 16 | * 查看字幕属性信息 17 | * `ffmpeg -i xxx.mp4` 18 | * 输出字幕信息: 19 | * `Stream #0:2(zho): Subtitle: mov_text (tx3g / 0x67337874), 1280x108, 0 kb/s (default)` 20 | * 分辨率=宽x高 21 | * 用ffmpeg相关的ffprobe 22 | * `ffprobe -v error -select_streams v:0 -show_entries stream=height,width -of csv=s=x:p=0 input.mp4` 23 | * 输出:`1280x720` 24 | * 视频去水印 25 | * `ffmpeg -i input.mp4 -vf "delogo=x=324:y=28:w=140:h=53" -c:a copy input_removedWatermarked.mp4` 26 | * 从视频中提取音频并分割成多个音频片段 27 | * 前提: 28 | * 首先要有字幕文件:可以指定多个时间段 29 | * 对于每个时间段,用ffmpeg提取指定时间段的音频 30 | * `ffmpeg -i input.mp4 -ss 00:00:11.270 -to 00:00:14.550 -b:a 128k output_audio_000011270_000014550.mp3` 31 | * 给视频加字幕=把字幕嵌入合并到视频中 32 | * srt字幕 33 | * 软字幕 内挂字幕 34 | * `ffmpeg -i video_no_subtitle.mp4 -i subtitle.srt -codec copy -map 0 video_with_soft_subtitle.mp4` 35 | * ass字幕 36 | * 硬字幕 内嵌字幕=嵌入ass字幕到视频中 37 | * `ffmpeg -i input_video.mp4 -vf ass=subtitle.ass input_video_with_ass_subtitle.mp4` 38 | * 从视频中提取出字幕 39 | * `ffmpeg -i video_with_soft_subtitle.mp4 -map 0:s:0 extracted_subtitle.srt` 40 | * 字幕类型转换 41 | * srt转换为ass 42 | * `ffmpeg -i subtitle.srt subtitle.ass` 43 | 44 | 另外还有: 45 | 46 | * `ffmpeg`被其他工具调用:用于解析和操作音视频 47 | * Python的音频处理库:`pydub` 48 | * https://github.com/jiaaro/pydub 49 | * Python的音频解析库:`audioread` 50 | * https://github.com/beetbox/audioread 51 | -------------------------------------------------------------------------------- /src/subtitle/convert/README.md: -------------------------------------------------------------------------------- 1 | # 转换字幕 2 | 3 | ## 从srt转换出ass字幕文件 4 | 5 | ```bash 6 | ffmpeg -i subtitle.srt subtitle.ass 7 | ``` 8 | 9 | 举例: 10 | 11 | ```bash 12 | ➜ ffmpeg_edit_subtitle ffmpeg -i subtitle.srt subtitle.ass 13 | ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers 14 | built with Apple LLVM version 9.0.0 (clang-900.0.39.2) 15 | configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --disable-jack --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma 16 | libavutil 55. 78.100 / 55. 78.100 17 | libavcodec 57.107.100 / 57.107.100 18 | libavformat 57. 83.100 / 57. 83.100 19 | libavdevice 57. 10.100 / 57. 10.100 20 | libavfilter 6.107.100 / 6.107.100 21 | libavresample 3. 7. 0 / 3. 7. 0 22 | libswscale 4. 8.100 / 4. 8.100 23 | libswresample 2. 9.100 / 2. 9.100 24 | libpostproc 54. 7.100 / 54. 7.100 25 | Input #0, srt, from 'subtitle.srt': 26 | Duration: N/A, bitrate: N/A 27 | Stream #0:0: Subtitle: subrip 28 | Output #0, ass, to 'subtitle.ass': 29 | Metadata: 30 | encoder : Lavf57.83.100 31 | Stream #0:0: Subtitle: ass (ssa) 32 | Metadata: 33 | encoder : Lavc57.107.100 ssa 34 | Stream mapping: 35 | Stream #0:0 -> #0:0 (subrip (srt) -> ass (ssa)) 36 | Press [q] to stop, [?] for help 37 | size= 33kB time=00:26:17.56 bitrate= 0.2kbits/s speed=3.6e+05x 38 | video:0kB audio:0kB subtitle:23kB other streams:0kB global headers:1kB muxing overhead: 42.551056% 39 | ``` 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 强大的音视频处理工具:FFmpeg 2 | 3 | * 最新版本:`v1.0` 4 | * 更新时间:`20210914` 5 | 6 | ## 简介 7 | 8 | 介绍音视频处理工具FFmpeg有哪些强大的功能。先对ffmpeg进行概览,包括可以用来干什么,与之相关的ffprobe、ffplay、ffserver等工具;再介绍如何安装ffmpeg;如何用ffmpeg处理音频,比如从音频中提取某段音频片段;以及各种视频处理,包括视频属性的获取和调整,包括调整视频宽高尺寸大小;以及动图gif处理,包括视频转动图、动图转视频;以及水印处理,包括去除视频水印;从视频中提取完整音频和音频片段;字幕相关处理,包括字幕的背景知识,包括软字幕和硬字幕、常见字幕格式ass和srt;以及如何用Aegisub编辑字幕;从视频中提取字幕、从srt转换出ass字幕;嵌入字幕,包括用流拷贝模式嵌入软字幕、用vf模式烧录嵌入硬字幕、且可以指定字幕位置、指定字幕文字属性等;整理ffmpeg使用的心得和常见问题;以及其他有哪些工具软件用到了ffmpeg、如何用Python调用ffmpeg;最后给出附录内容,包括help语法、文档资料等。 9 | 10 | ## 源码+浏览+下载 11 | 12 | 本书的各种源码、在线浏览地址、多种格式文件下载如下: 13 | 14 | ### Gitbook源码 15 | 16 | * [crifan/media_process_ffmpeg: 强大的音视频处理工具:FFmpeg](https://github.com/crifan/media_process_ffmpeg) 17 | 18 | #### 如何使用此Gitbook源码去生成发布为电子书 19 | 20 | 详见:[crifan/gitbook_template: demo how to use crifan gitbook template and demo](https://github.com/crifan/gitbook_template) 21 | 22 | ### 在线浏览 23 | 24 | * [强大的音视频处理工具:FFmpeg book.crifan.com](https://book.crifan.com/books/media_process_ffmpeg/website) 25 | * [强大的音视频处理工具:FFmpeg crifan.github.io](https://crifan.github.io/media_process_ffmpeg/website) 26 | 27 | ### 离线下载阅读 28 | 29 | * [强大的音视频处理工具:FFmpeg PDF](https://book.crifan.com/books/media_process_ffmpeg/pdf/media_process_ffmpeg.pdf) 30 | * [强大的音视频处理工具:FFmpeg ePub](https://book.crifan.com/books/media_process_ffmpeg/epub/media_process_ffmpeg.epub) 31 | * [强大的音视频处理工具:FFmpeg Mobi](https://book.crifan.com/books/media_process_ffmpeg/mobi/media_process_ffmpeg.mobi) 32 | 33 | ## 版权说明 34 | 35 | 此电子书教程的全部内容,如无特别说明,均为本人原创和整理。其中部分内容参考自网络,均已备注了出处。如有发现侵犯您版权,请通过邮箱联系我 `admin 艾特 crifan.com`,我会尽快删除。谢谢合作。 36 | 37 | ## 鸣谢 38 | 39 | 感谢我的老婆**陈雪**的包容理解和悉心照料,才使得我`crifan`有更多精力去专注技术专研和整理归纳出这些电子书和技术教程,特此鸣谢。 40 | 41 | ## 更多其他电子书 42 | 43 | 本人`crifan`还写了其他`100+`本电子书教程,感兴趣可移步至: 44 | 45 | [crifan/crifan_ebook_readme: Crifan的电子书的使用说明](https://github.com/crifan/crifan_ebook_readme) 46 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # 强大的音视频处理工具:FFmpeg 2 | 3 | * 最新版本:`v1.0` 4 | * 更新时间:`20210914` 5 | 6 | ## 简介 7 | 8 | 介绍音视频处理工具FFmpeg有哪些强大的功能。先对ffmpeg进行概览,包括可以用来干什么,与之相关的ffprobe、ffplay、ffserver等工具;再介绍如何安装ffmpeg;如何用ffmpeg处理音频,比如从音频中提取某段音频片段;以及各种视频处理,包括视频属性的获取和调整,包括调整视频宽高尺寸大小;以及动图gif处理,包括视频转动图、动图转视频;以及水印处理,包括去除视频水印;从视频中提取完整音频和音频片段;字幕相关处理,包括字幕的背景知识,包括软字幕和硬字幕、常见字幕格式ass和srt;以及如何用Aegisub编辑字幕;从视频中提取字幕、从srt转换出ass字幕;嵌入字幕,包括用流拷贝模式嵌入软字幕、用vf模式烧录嵌入硬字幕、且可以指定字幕位置、指定字幕文字属性等;整理ffmpeg使用的心得和常见问题;以及其他有哪些工具软件用到了ffmpeg、如何用Python调用ffmpeg;最后给出附录内容,包括help语法、文档资料等。 9 | 10 | ## 源码+浏览+下载 11 | 12 | 本书的各种源码、在线浏览地址、多种格式文件下载如下: 13 | 14 | ### Gitbook源码 15 | 16 | * [crifan/media_process_ffmpeg: 强大的音视频处理工具:FFmpeg](https://github.com/crifan/media_process_ffmpeg) 17 | 18 | #### 如何使用此Gitbook源码去生成发布为电子书 19 | 20 | 详见:[crifan/gitbook_template: demo how to use crifan gitbook template and demo](https://github.com/crifan/gitbook_template) 21 | 22 | ### 在线浏览 23 | 24 | * [强大的音视频处理工具:FFmpeg book.crifan.com](https://book.crifan.com/books/media_process_ffmpeg/website) 25 | * [强大的音视频处理工具:FFmpeg crifan.github.io](https://crifan.github.io/media_process_ffmpeg/website) 26 | 27 | ### 离线下载阅读 28 | 29 | * [强大的音视频处理工具:FFmpeg PDF](https://book.crifan.com/books/media_process_ffmpeg/pdf/media_process_ffmpeg.pdf) 30 | * [强大的音视频处理工具:FFmpeg ePub](https://book.crifan.com/books/media_process_ffmpeg/epub/media_process_ffmpeg.epub) 31 | * [强大的音视频处理工具:FFmpeg Mobi](https://book.crifan.com/books/media_process_ffmpeg/mobi/media_process_ffmpeg.mobi) 32 | 33 | ## 版权说明 34 | 35 | 此电子书教程的全部内容,如无特别说明,均为本人原创和整理。其中部分内容参考自网络,均已备注了出处。如有发现侵犯您版权,请通过邮箱联系我 `admin 艾特 crifan.com`,我会尽快删除。谢谢合作。 36 | 37 | ## 鸣谢 38 | 39 | 感谢我的老婆**陈雪**的包容理解和悉心照料,才使得我`crifan`有更多精力去专注技术专研和整理归纳出这些电子书和技术教程,特此鸣谢。 40 | 41 | ## 更多其他电子书 42 | 43 | 本人`crifan`还写了其他`100+`本电子书教程,感兴趣可移步至: 44 | 45 | [crifan/crifan_ebook_readme: Crifan的电子书的使用说明](https://github.com/crifan/crifan_ebook_readme) 46 | -------------------------------------------------------------------------------- /src/subtitle/embed/README.md: -------------------------------------------------------------------------------- 1 | # 嵌入字幕 2 | 3 | 用ffmpeg去`嵌入字幕`=`写入字幕`=`合并字幕`=`烧录字幕` 4 | 5 | 分2类: 6 | 7 | ## 软字幕=内挂字幕 8 | 9 | * 别称:`软字幕`=`soft subs`=`soft subtitles` 10 | * ffmpeg处理逻辑:`stream copy`**流拷贝**模式 11 | * 举例: 12 | ```bash 13 | ffmpeg -i input.mkv -i subtitles.ass -codec copy -map 0 -map 1 output.mkv 14 | 15 | ffmpeg -i infile.mp4 -f srt -i infile.srt -c:v copy -c:a copy -c:s mov_text outfile.mp4 16 | ``` 17 | 18 | ## 硬字幕=内嵌字幕 19 | 20 | * 别称:`硬字幕`=`hardsubs`=`hard subs`=`hard subtitles`=`burn in subtitles` 21 | * ffmpeg处理逻辑:用`-vf`加上**字幕文件** 22 | * 前提:ffmpeg支持ass 23 | * 即:ffmpeg编译参数中包含:`--enable-libass` 24 | * 举例 25 | ```bash 26 | # ffmpeg -version 27 | ffmpeg version 4.2-tessus https://evermeet.cx/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers 28 | built with Apple LLVM version 10.0.1 (clang-1001.0.46.4) 29 | configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg ... --enable-libass ... 30 | ``` 31 | * 举例 32 | 1. 嵌入srt字幕 33 | ```bash 34 | ffmpeg -i input.mp4 -vf "subtitles=subtitle.srt" output.mp4 35 | ``` 36 | * 注 37 | * (1)-vf后面参数,可以不加双引号: 38 | ```bash 39 | ffmpeg -i input.mp4 -vf subtitles=subtitle.srt output.mp4 40 | ``` 41 | * 不过为了区别后续其他参数,最好像上面一样加上双引号,比较容易和其他参数区别开 42 | * (2)如果srt字幕内在在视频文件中 43 | * 比如视频是mkv的容器,内挂有srt字幕,则可以: 44 | ```bash 45 | ffmpeg -i input.mkv -vf subtitles=input.mkv output.mp4 46 | ``` 47 | 2. 嵌入ass字幕 48 | ```bash 49 | ffmpeg -i input.mp4 -vf "ass=subtitle.ass" output.mp4 50 | ``` 51 | * 举例 52 | ```bash 53 | ffmpeg -i CTT_Folge_01_CH_Subs_DefaultZhcnButNotShow.mp4 -vf ass=subtitle_fontLarggerBackgroundAlpha-4.ass fontPingFangSC20HalfTransparent.mp4 54 | ``` 55 | * 特殊 56 | * 另外ffmpeg也支持:`Picture-based subtitles`=基于图片的字幕 57 | * 命令举例: 58 | ```bash 59 | ffmpeg -i input.mkv -filter_complex "[0:v][0:s]overlay[v]" -map "[v]" -map 0:a output.mkv 60 | ``` 61 | * 参数说明: 62 | * 如果是多个stream流,可以把`[0:s]`换成对应的`[0:s:0]`或`[0:s:1]` 63 | * 注意: 64 | * (1)当视频有多个音频流,此种方式可能会破坏编码,则用下面方式去修复: 65 | ```bash 66 | ffmpeg -i input.ts -filter_complex "[0:v][0:s]overlay[v]" -map "[v]" -map 0:a:0 output.mkv 67 | ``` 68 | * (2)Windows环境:注意设置字体的路径 69 | -------------------------------------------------------------------------------- /src/subtitle/embed/config_position.md: -------------------------------------------------------------------------------- 1 | # 指定字幕位置 2 | 3 | * 最简单但常见的需求:无需操心字幕的具体位置,只需要保证字幕在视频底部 4 | * 则可以直接嵌入字幕,其中字幕文件是srt或ass均可 5 | ```bash 6 | ffmpeg -i input.mp4 -vf subtitles=input.srt output.mp4 7 | ffmpeg -i input.mp4 -vf ass=subtitle.ass output.mp4 8 | ``` 9 | * 高级需求:指定字幕的具体的位置(不同区域,具体边距等) 10 | * 前提:必须是ass文件(才能用参数指定字幕位置),srt无法指定字幕位置 11 | * 如果是srt文件,则需要先去转换成ass文件 12 | ```bash 13 | ffmpeg -i input.srt output.ass 14 | ``` 15 | 16 | ## 嵌入ass字幕到视频中 17 | 18 | ```bash 19 | ffmpeg -i input.mp4 -vf "ass=input.ass" output.mp4 20 | ``` 21 | 22 | * 其中: 23 | * ass字幕文件input.ass中,有对应的位置的参数配置 24 | ```ini 25 | [V4+ Styles] 26 | Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding 27 | 28 | Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0 29 | ``` 30 | * 其中: 31 | * `Alignment`:默认为`2` = 底部居中 32 | * 就满足了我们希望的:字幕在底部居中的位置 33 | 34 | ### 微调左右间距和底部间距 35 | 36 | * 再去微调左右间距和底部间距时 37 | * 再去改动: 38 | * `MarginL, MarginR, MarginV` 39 | * 比如: 40 | ```ini 41 | MarginL, MarginR, MarginV 42 | 20,20,10 43 | ``` 44 | * 即可实现: 45 | * `MarginL`=`MarginR`:左右间距`20` 46 | * `MarginV`:底部向上间距`10` 47 | 48 | ## 嵌入ass字幕举例 49 | 50 | * 字幕文件:`input/5d41d82f52247ce73d40475b_cfgPosition.ass` 51 | * ass文件中相关参数 52 | ```ini 53 | Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding 54 | 55 | Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,20,20,10,0 56 | ``` 57 | * 参数说明 58 | * 字幕位置主要影响因素 59 | * 字幕主体所在区域 60 | * `Alignment` 61 | * 默认为`2` = 底部居中 62 | * 其中值: `1-9` 63 | * 逻辑:和键盘中数字的排布一致 64 | * 见图: 65 | * ![subtitle_ass_aligment](../../assets/img/subtitle_ass_aligment.png) 66 | * 字幕位置次要影响因素 67 | * 字幕的边距 68 | * (字幕距离)左右的边距:`MarginL`和`MarginR`:`20` 69 | * (字幕距离)底部的边距:`10` 70 | * 命令 71 | ```bash 72 | ffmpeg -i input/5d41d82f52247ce73d40475b_extendedAll.mp4 -vf "ass=input/5d41d82f52247ce73d40475b_cfgPosition.ass" output/5d41d82f52247ce73d40475b_addedAss_marginV10LR20.mp4 73 | ``` 74 | * 效果 75 | * ![embed_ass_effect_demo](../../assets/img/embed_ass_effect_demo.png) 76 | -------------------------------------------------------------------------------- /src/appendix/reference.md: -------------------------------------------------------------------------------- 1 | # 参考资料 2 | 3 | * 【已解决】嵌入ASS字幕到mp4视频中如何指定字幕的位置 4 | * 【已解决】把视频画面增加高度再合并字幕到指定位置 5 | * 【已解决】ffmpeg保持视频宽度不变去增加扩大视频高度 6 | * 【已解决】ffmpeg合并字幕到视频下方指定位置 7 | * 【整理】ASS字幕文件格式详解 8 | * 【已解决】ffprobe作用及用法和其于ffmpeg的区别 9 | * 【已解决】ffmpeg查看视频的基本信息包括字幕信息 10 | * 【已解决】Mac中用ffmpeg调整mp4默认字幕为中文 11 | * 【已解决】Mac中用ffmpeg从mp4视频中提取mp3音频 12 | * 【已解决】Mac中安装ffmpeg及相关ffplay和ffprobe等工具 13 | * 【已解决】用ffmpeg去除mp4视频水印 14 | * 【已解决】Python代码其中可利用ffmpeg检测视频真实分辨率即宽度和高度 15 | * 【已解决】mac中下载和安装最新版的ffmpeg 16 | * 【已解决】ffmpeg从mp4视频提取出srt和ass字幕文件 17 | * 【已解决】用Aegisub字幕编辑器去调整字体大小和字幕背景半透明效果 18 | * 【已解决】ass字幕文件中如何设置字幕的半透明背景色 19 | * 【已解决】ffmpeg集成srt字幕到视频的字幕流中即软字幕 20 | * 【已解决】调节ass字幕配置字幕字体大小和背景色再用ffmpeg嵌入视频中 21 | * 【已解决】后台运行Python代码导致subprocess.check_call调用ffmpeg卡死 22 | * 【已解决】用Python代码从视频中提取出音频mp3文件 23 | * 24 | * [【基本解决】Mac中提取mp4视频中的字幕](http://www.crifan.com/mac_extract_mp4_video_subtitle) 25 | * 【[已解决】Mac中brew reinstall ffmpeg出错:Error: Calling keg_only :provided_pre_mountain_lion is disabled! There is no replacement](https://www.crifan.com/brew_reinstall_ffmpeg_error_calling_keg_only_provided_pre_mountain_lion_disabled_there_no_replacement) 26 | * 27 | * [【基本解决】Python中把wma、wav等格式音频转换为mp3](http://www.crifan.com/python_convert_wma_wav_audio_to_mp3_format) 28 | * [【已解决】Mac中播放某mp4视频默认没有字幕](https://www.crifan.com/by_default_there_no_subtitles_for_playing_certain_mp4_videos_on_mac) 29 | * [【基本解决】Handbrake压制mp4时添加SRT字幕文件](https://www.crifan.com/handbrake_adds_srt_subtitle_files_when_suppressing_mp4) 30 | * [【已解决】ffmpeg嵌入硬编码烧录ass字幕到视频中即字幕成为视频内容本身](https://www.crifan.com/ffmpeg_embedding_hard_coded_ass_captions_into_video_means_captions_become_video_content_itself) 31 | * [【已解决】Mac中尝试给mp4内嵌字幕出错:AVFilterGraph No such filter ass](https://www.crifan.com/avfiltergraph_no_such_filter_ass_avfiltergraph_no_such_filter_ass) 32 | * [【已解决】Mac中用ffmpeg调整mp4默认字幕为中文](https://www.crifan.com/mac_uses_ffmpeg_adjust_mp4_default_subtitles_chinese) 33 | * [【已解决】ffmpeg集成srt字幕到视频的字幕流中即软字幕](https://www.crifan.com/ffmpeg_integrates_srt_captions_into_video_captions_stream_namely_soft_captions) 34 | * [【已解决】Mac中找软件编辑mp4视频的默认字幕为中文](https://www.crifan.com/mac_find_software_edit_mp4_videos_with_chinese_subtitles_by_default) 35 | * [【已解决】用ffmpeg从mp4视频中提取出整个mp3以及根据时间段去分割mp3](https://www.crifan.com/use_ffmpeg_extract_entire_mp3_from_mp4_video_segment_mp3_according_time_period) 36 | * 37 | * [Stream-copy ffmpeg Documentation](https://www.ffmpeg.org/ffmpeg-all.html#Stream-copy) 38 | * [toc-Main-options](https://www.ffmpeg.org/ffmpeg-all.html#toc-Main-options) 39 | * [sindresorhus/Gifski: 🌈 Convert videos to high-quality GIFs on your Mac](https://github.com/sindresorhus/Gifski) 40 | * [使用 ffmpeg 实现 MP4 与 GIF 的互转 - 任平生的学习笔记](http://note.rpsh.net/posts/2015/04/21/mac-osx-ffmpeg-mp4-gif-convert/) 41 | * [HowToBurnSubtitlesIntoVideo – FFmpeg](https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo) 42 | * [FFmpeg Filters Documentation - subtitles](http://ffmpeg.org/ffmpeg-filters.html#subtitles-1) 43 | * [FFmpeg Filters Documentation - ass](http://ffmpeg.org/ffmpeg-filters.html#ass) 44 | * [enable libass - Page 3 - FFmpeg](https://ffmpeg.zeranoe.com/forum/viewtopic.php?f=10&t=318&start=20) 45 | * [SubStation Alpha - 维基百科,自由的百科全书](https://zh.wikipedia.org/wiki/SubStation_Alpha) 46 | * [ffserver – FFmpeg](https://trac.ffmpeg.org/wiki/ffserver) 47 | * [ffmpeg——ffserver的一个简单demo - Eyrane的博客 - CSDN博客](https://blog.csdn.net/u012868357/article/details/80240639) 48 | * [ffmpeg+ffserver搭建流媒体服务器 - 静之深 - 博客园](https://www.cnblogs.com/jingzhishen/p/3735314.html) 49 | * [ffmpeg Documentation](https://ffmpeg.org/ffmpeg.html) 50 | * [Documentation](https://www.ffmpeg.org/documentation.html) 51 | * [ffmpeg Documentation](https://www.ffmpeg.org/ffmpeg-all.html) 52 | * [FFmpeg Utilities Documentation](https://ffmpeg.org/ffmpeg-utils.html) 53 | * [FFmpeg Codecs Documentation](https://www.ffmpeg.org/ffmpeg-codecs.html) 54 | * -------------------------------------------------------------------------------- /src/subtitle/edit/aegisub.md: -------------------------------------------------------------------------------- 1 | # Aegisub 2 | 3 | * `Aegisub` 4 | * 概述:字幕编辑工具 5 | * 主页 6 | * Aegisub Advanced Subtitle Editor 7 | * http://www.aegisub.org 8 | 9 | ## 用Aegisub编辑字幕 10 | 11 | 从[官网](http://www.aegisub.org) 12 | 13 | ![aegisub_org_home](../../assets/img/aegisub_org_home.png) 14 | 15 | 下载对应版本: 16 | 17 | `Aegisub-3.2.2.dmg` 18 | 19 | ![aegisub_mac_dmg](../../assets/img/aegisub_mac_dmg.png) 20 | 21 | 去安装,然后打开 22 | 23 | ![aegisub_main_ui](../../assets/img/aegisub_main_ui.png) 24 | 25 | 先去打开你的字幕文件,此处的ass文件: 26 | 27 | ![aegisub_open_ass_file](../../assets/img/aegisub_open_ass_file.png) 28 | 29 | 字幕-》样式管理器-》去编辑 当前脚本 中的,比如默认有个:Default 的样式 30 | 31 | ![aegisub_subtitle_style_manager](../../assets/img/aegisub_subtitle_style_manager.png) 32 | 33 | ![aegisub_style_manager_default](../../assets/img/aegisub_style_manager_default.png) 34 | 35 | 就出来字幕预览了: 36 | 37 | ![aegisub_default_preview](../../assets/img/aegisub_default_preview.png) 38 | 39 | 参数解释: 40 | 41 | * 半透明效果 42 | * 先勾选 边框-》不透明效果 43 | * 再去:颜色-》 点击:边框 或 阴影,弹出设置框,改动你要的颜色,尤其是调整 透明度 44 | 45 | 从左边的 样式库 中 默认的样式:Default,选中,点击下面的 复制到当前脚本 46 | 47 | ![aegisub_copy_to_right](../../assets/img/aegisub_copy_to_right.png) 48 | 49 | ![aegisub_style_overwrite](../../assets/img/aegisub_style_overwrite.png) 50 | 51 | 然后再去放大,即可以看到效果了: 52 | 53 | ![aegisub_video_subtitle_effect](../../assets/img/aegisub_video_subtitle_effect.png) 54 | 55 | 继续编辑字幕 56 | 57 | ![aegisub_adjust_property](../../assets/img/aegisub_adjust_property.png) 58 | 59 | ![aegisub_compare_susbtitle_diff](../../assets/img/aegisub_compare_susbtitle_diff.png) 60 | 61 | 直到调节出你要的效果。 62 | 63 | 编辑好ass后,另存为,得到最终的ass文件。 64 | 65 | 具体过程详见: 66 | 67 | 【已解决】用Aegisub字幕编辑器去调整字体大小和字幕背景半透明效果 68 | 69 | ## 举例 70 | 71 | * 输入=编辑前 72 | 73 | 此处之前从某mp4视频中用ffmpeg提取出srt,在用ffmpeg从srt转换出ass字幕 74 | 75 | ```bash 76 | [Script Info] 77 | ; Script generated by FFmpeg/Lavc58.18.100 78 | ScriptType: v4.00+ 79 | PlayResX: 384 80 | PlayResY: 288 81 | 82 | [V4+ Styles] 83 | Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding 84 | Style: Default,Arial,36,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0 85 | ``` 86 | 87 | * 编辑字幕 88 | 89 | 用Aegisub编辑字幕,,调整出我要的效果后,另存为保存出的ass文件 90 | 91 | 把其配置: 92 | 93 | ```bash 94 | Style: Transparent,PingFang SC,20,&H00FFFFFF,&H000000FF,&HBC5E5E5E,&H8B000000,0,0,0,0,100,100,0,0,3,0,1,2,10,10,10,134 95 | ``` 96 | 97 | 换进来即可 98 | 99 | * 输出=编辑后 100 | 101 | ```bash 102 | [Script Info] 103 | ; Script generated by FFmpeg/Lavc58.18.100 104 | ScriptType: v4.00+ 105 | PlayResX: 384 106 | PlayResY: 288 107 | 108 | [V4+ Styles] 109 | Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding 110 | Style: Transparent,PingFang SC,20,&H00FFFFFF,&H000000FF,&HBC5E5E5E,&H8B000000,0,0,0,0,100,100,0,0,3,0,1,2,10,10,10,134 111 | 112 | [Events] 113 | Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text 114 | Dialogue: 0,0:00:23.24,0:00:27.20,Transparent,,0,0,0,,大家好,欢迎来到xxx 115 | ``` 116 | 117 | * 核心配置 118 | 119 | 就一句: 120 | 121 | ```bash 122 | Style: Transparent,PingFang SC,20,&H00FFFFFF,&H000000FF,&HBC5E5E5E,&H8B000000,0,0,0,0,100,100,0,0,3,0,1,2,10,10,10,134 123 | ``` 124 | 125 | 起到了配置字幕属性,实现了效果: 126 | 127 | * 字体:PingFang SC 128 | * 字体大小:20 129 | * 字幕的背景半透明效果:后面很多参数组合的效果 130 | 131 | ## 常见问题 132 | 133 | ### 当导入视频时会提示:载入视频的分辨率与当前脚本指定的分辨率不匹配 134 | 135 | * 不要用默认选择:直接设为视频分辨率 136 | * 会导致预览看到的视频很小,字幕很小 137 | * 后续调整字幕的大小后,预览中视频里的字幕仍旧很小,导致字幕字体大小无法生效 138 | * 重新选这个:重设脚本分辨率 139 | * 但是也会导致另存为的ass文件中,有视频方面的设置 140 | * 我是后来自己参考原始的配置,改回去为原始的配置的 141 | 142 | -------------------------------------------------------------------------------- /src/video_process/property/adjust/resolution.md: -------------------------------------------------------------------------------- 1 | # 尺寸调整 2 | 3 | ## 缩放视频尺寸 4 | 5 | ```bash 6 | ffmpeg -i big.mov -vf scale=360:-1 small.mov 7 | ``` 8 | 9 | * 注意 10 | * `scale`值必须是偶数,这里的`-1`表示保持长宽比,根据宽度值自适应高度 11 | * 如果要求压缩出来的视频尺寸长宽都保持为偶数,可以使用`-2` 12 | 13 | ## extend扩大视频高度(和宽度) 14 | 15 | * 注意:此处改变视频宽高,是`调整`=`extend`=`enlarge`=`扩大`或`缩小`,不是`等比例缩放`=`resize` 16 | 17 | 思路:用`ffmpeg`的`pad`参数去指定要扩大的宽度和高度 18 | 19 | 参数详解: 20 | 21 | 22 | * `pad`=`padding`:增加视频区域,即宽度和(或)高度 23 | * `width`和`height`:(增加了padding后的)输出的视频的宽度和高度 24 | * 值的方式 25 | * 固定的数值 26 | * 表达式 27 | * 可以借用内置支持的常量或变量 28 | * 比如 29 | * 输入的原始视频的 30 | * 宽度:`in_w`=`iw` 31 | * 高度:`in_h`=`ih` 32 | * 输出的padding后的视频的 33 | * 宽度:`out_w`=`ow` 34 | * 高度:`out_h`=`oh` 35 | * x和y: 36 | * 原始视频,放在输出后的视频的位置 37 | * 默认:`0`和`0` 38 | * 特殊 39 | * 如果(`x`或`y`)是负数,则效果是(水平方面或垂直方向)自动居中 40 | 41 | ### 用法举例 42 | 43 | * 输入:原始视频 480x360 44 | * 输出 45 | 46 | #### 希望:宽度不变,高度在下面增加100,背景色是白色 47 | 48 | 命令: 49 | 50 | ```bash 51 | ffmpeg -i input.mp4 -vf "pad=width=0:height=460:x=0:y=0:color='White" output.mp4 52 | ``` 53 | 54 | 参数说明: 55 | 56 | * 高度 57 | * 可以用数值:`460` 58 | * 也可以用表达式:`ih+100` 59 | ```bash 60 | ffmpeg -i input.mp4 -vf "pad=width=0:height=ih+100:x=0:y=0:color='White" output.mp4 61 | ``` 62 | 63 | 效果: 64 | 65 | ![adjust_video_size_bkg_white](../../../assets/img/adjust_video_size_bkg_white.png) 66 | 67 | #### 希望:调整多个属性 68 | 69 | 希望: 70 | 71 | * 高度:上面增加`50`,下面增加`100` 72 | * 总增加高度=`50+100`=`150` 73 | * 宽度:左右都增加`30`,原视频居中 74 | * 总增加宽度=`30*2`=`60` 75 | * 背景色:`LawnGreen` 76 | * 透明度:`0.2` 77 | 78 | 命令: 79 | 80 | * pad中的值用手动计算出的值: 81 | ```bash 82 | ffmpeg -i input.mp4 -vf "pad=width=540:height=510:x=30:y=50:color='LawnGreen@0.5" output.mp4 83 | ``` 84 | * 或:pad中的值尽量用表达式: 85 | ```bash 86 | ffmpeg -i input.mp4 -vf "pad=width=iw+60:height=ih+150:x=-1:y=50:color='LawnGreen@0.5" output.mp4 87 | ``` 88 | 89 | 效果: 90 | 91 | ![adjust_video_size_multi_property](../../../assets/img/adjust_video_size_multi_property.png) 92 | 93 | 附录: 94 | 95 | 前面折腾期间的命令记录,包括出错的命令: 96 | 97 | ```bash 98 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=640:height=360:x=0:y=40:color=black" output/5d41d82f52247ce73d40475b_afterPad.mp4 99 | 100 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=640:height=400:x=0:y=360:color=black" output/5d41d82f52247ce73d40475b_afterPad_191610.mp4 101 | 102 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=0:height=400:x=0:y=360:color=black" output/5d41d82f52247ce73d40475b_afterPad_autoWidth.mp4 103 | 104 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=0:height=400:x=0:y=360:color=0x00" output/5d41d82f52247ce73d40475b_afterPad_autoWidth_transparent.mp4 105 | 106 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=0:height=400:x=0:y=360:color='0x00" output/5d41d82f52247ce73d40475b_afterPad_autoWidth_transparent.mp4 107 | 108 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=0:height=400:x=0:y=360:color='White@0.0" output/5d41d82f52247ce73d40475b_afterPad_autoWidth_transparent.mp4 109 | 110 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=0:height=460:x=0:y=360:color='White" output/5d41d82f52247ce73d40475b_afterPad_autoWidth_moreHeight.mp4 111 | 112 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=iw:height=ih+100:x=0:y=ih:color='SeaGreen@0.2" output/5d41d82f52247ce73d40475b_afterPad_autoWH_SeaGreen.mp4 113 | 114 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=iw:height=ih+80:x=0:y=0:color='SeaGreen@0.2" output/5d41d82f52247ce73d40475b_afterPad_autoWH_SeaGreen_y0.mp4 115 | 116 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=iw+60:height=ih+150:x=-1:y=50:color='LawnGreen@0.5" output/5d41d82f52247ce73d40475b_upDownAllPad_LawnGreen.mp4 117 | 118 | ffmpeg -i input/5d41d82f52247ce73d40475b.mp4 -vf "pad=width=0:height=460:x=0:y=0:color='White" output/5d41d82f52247ce73d40475b_down100_white.mp4 119 | ``` 120 | 121 | 供参考。 122 | -------------------------------------------------------------------------------- /book.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "强大的音视频处理工具:FFmpeg", 3 | "description": "介绍音视频处理工具FFmpeg有哪些强大的功能。先对ffmpeg进行概览,包括可以用来干什么,与之相关的ffprobe、ffplay、ffserver等工具;再介绍如何安装ffmpeg;如何用ffmpeg处理音频,比如从音频中提取某段音频片段;以及各种视频处理,包括视频属性的获取和调整,包括调整视频宽高尺寸大小;以及动图gif处理,包括视频转动图、动图转视频;以及水印处理,包括去除视频水印;从视频中提取完整音频和音频片段;字幕相关处理,包括字幕的背景知识,包括软字幕和硬字幕、常见字幕格式ass和srt;以及如何用Aegisub编辑字幕;从视频中提取字幕、从srt转换出ass字幕;嵌入字幕,包括用流拷贝模式嵌入软字幕、用vf模式烧录嵌入硬字幕、且可以指定字幕位置、指定字幕文字属性等;整理ffmpeg使用的心得和常见问题;以及其他有哪些工具软件用到了ffmpeg、如何用Python调用ffmpeg;最后给出附录内容,包括help语法、文档资料等。", 4 | "pluginsConfig": { 5 | "autocover": { 6 | "title": "Gitbook演示" 7 | }, 8 | "github-buttons": { 9 | "buttons": [ 10 | { 11 | "repo": "media_process_ffmpeg", 12 | "user": "crifan", 13 | "type": "star", 14 | "count": true, 15 | "size": "small" 16 | }, 17 | { 18 | "user": "crifan", 19 | "type": "follow", 20 | "width": "120", 21 | "count": false, 22 | "size": "small" 23 | } 24 | ] 25 | }, 26 | "sitemap-general": { 27 | "prefix": "https://book.crifan.com/books/media_process_ffmpeg/website/" 28 | }, 29 | "toolbar-button": { 30 | "url": "https://book.crifan.com/books/media_process_ffmpeg/pdf/media_process_ffmpeg.pdf", 31 | "icon": "fa-file-pdf-o", 32 | "label": "下载PDF" 33 | }, 34 | "google-adsense": { 35 | "ads": [ 36 | { 37 | "client": "ca-pub-6626240105039250" 38 | } 39 | ] 40 | }, 41 | "callouts": { 42 | "showTypeInHeader": false 43 | }, 44 | "theme-default": { 45 | "showLevel": true 46 | }, 47 | "disqus": { 48 | "shortName": "crifan" 49 | }, 50 | "prism": { 51 | "css": [ 52 | "prism-themes/themes/prism-atom-dark.css" 53 | ] 54 | }, 55 | "sharing": { 56 | "douban": false, 57 | "facebook": true, 58 | "google": false, 59 | "hatenaBookmark": false, 60 | "instapaper": false, 61 | "line": false, 62 | "linkedin": false, 63 | "messenger": false, 64 | "pocket": false, 65 | "qq": true, 66 | "qzone": false, 67 | "stumbleupon": false, 68 | "twitter": true, 69 | "viber": false, 70 | "vk": false, 71 | "weibo": true, 72 | "whatsapp": false, 73 | "all": [ 74 | "douban", 75 | "facebook", 76 | "google", 77 | "instapaper", 78 | "line", 79 | "linkedin", 80 | "messenger", 81 | "pocket", 82 | "qq", 83 | "qzone", 84 | "stumbleupon", 85 | "twitter", 86 | "viber", 87 | "vk", 88 | "weibo", 89 | "whatsapp" 90 | ] 91 | }, 92 | "tbfed-pagefooter": { 93 | "copyright": "crifan.com,使用署名4.0国际(CC BY 4.0)协议发布", 94 | "modify_label": "最后更新:", 95 | "modify_format": "YYYY-MM-DD HH:mm:ss" 96 | }, 97 | "ga": { 98 | "token": "UA-28297199-1" 99 | }, 100 | "donate": { 101 | "wechat": "https://www.crifan.com/files/res/crifan_com/crifan_wechat_pay.jpg", 102 | "alipay": "https://www.crifan.com/files/res/crifan_com/crifan_alipay_pay.jpg", 103 | "title": "", 104 | "button": "打赏", 105 | "alipayText": "支付宝打赏给Crifan", 106 | "wechatText": "微信打赏给Crifan" 107 | } 108 | }, 109 | "author": "Crifan Li ", 110 | "language": "zh-hans", 111 | "gitbook": "3.2.3", 112 | "root": "./src", 113 | "links": { 114 | "sidebar": { 115 | "主页": "http://www.crifan.com" 116 | } 117 | }, 118 | "plugins": [ 119 | "google-adsense", 120 | "theme-comscore", 121 | "anchors", 122 | "-lunr", 123 | "-search", 124 | "search-plus", 125 | "disqus", 126 | "-highlight", 127 | "prism", 128 | "prism-themes", 129 | "github-buttons", 130 | "splitter", 131 | "-sharing", 132 | "sharing-plus", 133 | "tbfed-pagefooter", 134 | "expandable-chapters-small", 135 | "ga", 136 | "donate", 137 | "sitemap-general", 138 | "copy-code-button", 139 | "callouts", 140 | "toolbar-button" 141 | ] 142 | } -------------------------------------------------------------------------------- /src/video_process/property/get/README.md: -------------------------------------------------------------------------------- 1 | # 获取视频属性 2 | 3 | ## 用ffprobe获取视频分辨率 宽度和高度 4 | 5 | ```bash 6 | ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 video_file.mp4 7 | ``` 8 | 9 | 举例: 10 | 11 | ```bash 12 | # ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 course_1608_video_normalWatermark_477w360h.mp4 13 | 480x360 14 | ``` 15 | 16 | ## 查看视频基本信息 17 | 18 | 通过: 19 | 20 | ```bash 21 | ffmpeg -i xxx.mp4 22 | ``` 23 | 24 | 即可看到mp4视频的信息,其中包括了字幕的信息: 25 | 26 | ```bash 27 | Stream #0:2(zho): Subtitle: mov_text (tx3g / 0x67337874), 1280x108, 0 kb/s (default) 28 | Metadata: 29 | creation_time : 2018-10-13T03:27:31.000000Z 30 | handler_name : SubtitleHandler 31 | ``` 32 | 33 | 其中: 34 | 35 | * `Stream #0:2`:字幕也是一个stream流,index是0:2 36 | * `zho`:(应该)表示是中文 37 | * `mov_text`:后来才听说,好像指的是`Apple Mov Text`格式的? 38 | 39 | ### 举例1 40 | 41 | ```bash 42 | ➜ ffmpeg_edit_subtitle ffmpeg -i CTT_Folge_01_CH_Subs_DefaultZhcnButNotShow.mp4 43 | ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers 44 | built with Apple LLVM version 9.0.0 (clang-900.0.39.2) 45 | configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --disable-jack --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma 46 | libavutil 55. 78.100 / 55. 78.100 47 | libavcodec 57.107.100 / 57.107.100 48 | libavformat 57. 83.100 / 57. 83.100 49 | libavdevice 57. 10.100 / 57. 10.100 50 | libavfilter 6.107.100 / 6.107.100 51 | libavresample 3. 7. 0 / 3. 7. 0 52 | libswscale 4. 8.100 / 4. 8.100 53 | libswresample 2. 9.100 / 2. 9.100 54 | libpostproc 54. 7.100 / 54. 7.100 55 | Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'CTT_Folge_01_CH_Subs_DefaultZhcnButNotShow.mp4': 56 | Metadata: 57 | major_brand : mp42 58 | minor_version : 512 59 | compatible_brands: isomiso2avc1mp41 60 | creation_time : 2018-10-13T03:27:31.000000Z 61 | encoder : HandBrake 1.1.2 2018090500 62 | Duration: 00:26:52.03, start: -0.001333, bitrate: 1762 kb/s 63 | Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1599 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc (default) 64 | Metadata: 65 | creation_time : 2018-10-13T03:27:31.000000Z 66 | handler_name : VideoHandler 67 | Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 157 kb/s (default) 68 | Metadata: 69 | creation_time : 2018-10-13T03:27:31.000000Z 70 | handler_name : Stereo 71 | Stream #0:2(zho): Subtitle: mov_text (tx3g / 0x67337874), 1280x108, 0 kb/s (default) 72 | Metadata: 73 | creation_time : 2018-10-13T03:27:31.000000Z 74 | handler_name : SubtitleHandler 75 | At least one output file must be specified 76 | ``` 77 | 78 | 看到字幕了:`Stream #0:2(zho)` 79 | 80 | zho应该是中文 81 | 82 | 且显示已经是default了,即默认是中文字幕(而不是之前的英文字幕) 83 | 84 | ### 举例2 85 | 86 | ```bash 87 | ffmpeg -i 1xx-我来保证你们的安全.mp4 88 | ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers 89 | built with Apple LLVM version 9.0.0 (clang-900.0.39.2) 90 | configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --disable-jack --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma 91 | libavutil 55. 78.100 / 55. 78.100 92 | libavcodec 57.107.100 / 57.107.100 93 | libavformat 57. 83.100 / 57. 83.100 94 | libavdevice 57. 10.100 / 57. 10.100 95 | libavfilter 6.107.100 / 6.107.100 96 | libavresample 3. 7. 0 / 3. 7. 0 97 | libswscale 4. 8.100 / 4. 8.100 98 | libswresample 2. 9.100 / 2. 9.100 99 | libpostproc 54. 7.100 / 54. 7.100 100 | Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1xxx-我来保证你们的安全.mp4': 101 | Metadata: 102 | major_brand : isom 103 | minor_version : 0 104 | compatible_brands: isomiso2avc1 105 | creation_time : 2018-01-28T05:46:37.000000Z 106 | Duration: 00:01:26.24, start: 0.000000, bitrate: 606 kb/s 107 | Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 541 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) 108 | Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 62 kb/s (default) 109 | Metadata: 110 | creation_time : 2018-01-28T05:46:35.000000Z 111 | At least one output file must be specified 112 | ``` 113 | 114 | 中并没有`Subtitle`的信息 115 | 116 | -> 看来这个视频本身就不包含独立的字幕 117 | 118 | -> 没法用ffmpeg去提取字幕了 119 | -------------------------------------------------------------------------------- /src/audio_process/extract_audio_segment.md: -------------------------------------------------------------------------------- 1 | # 提取音频片段 2 | 3 | 此处整理,从完整的音频文件中,提取其中一段,即提取音频片段。 4 | 5 | ## 从mp3中提取某个时间段的mp3 6 | 7 | ```bash 8 | ffmpeg -i show_14322648_audio.mp3 -acodec copy -ss 00:00:03.110 -to 00:00:06.110 show_14322648_audio_000003110_000006110.mp3 9 | ``` 10 | * 参数解释 11 | * `-i`:input 输入文件 12 | * `-acodec copy`: 13 | * `-acodec` = `audio codec`:音频编码器 14 | * == `-c copy` 15 | * 等价于: 16 | ```bash 17 | ffmpeg -i show_14322648_audio.mp3 -c copy -ss 00:00:03.110 -to 00:00:06.110 show_14322648_audio_000003110_000006110_cCopy.mp3 18 | ``` 19 | 20 | ### 官网文档 21 | 22 | * [Stream-copy ffmpeg Documentation](https://www.ffmpeg.org/ffmpeg-all.html#Stream-copy) 23 | > **3.2 Stream copy** 24 | > 25 | >     Stream copy is a mode selected by supplying the copy parameter to the -codec option. It makes ffmpeg omit the decoding and encoding step for the specified stream, so it does only demuxing and muxing. It is useful for changing the container format or modifying container-level metadata 26 | * [toc-Main-options](https://www.ffmpeg.org/ffmpeg-all.html#toc-Main-options) 27 | > **-t duration (input/output)** 28 | > 29 | >     When used as an input option (before -i), limit the duration of data read from the input file. 30 | When used as an output option (before an output url), stop writing the output after its duration reaches duration. 31 | duration must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual. 32 | -to and -t are mutually exclusive and -t has priority. 33 | > 34 | > **-to position (input/output)** 35 | > 36 | >     Stop writing the output or reading the input at position. position must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual. 37 | > 38 | >     -to and -t are mutually exclusive and -t has priority. 39 | > 40 | > **-ss position (input/output)** 41 | > 42 | >     When used as an input option (before -i), seeks in this input file to position. Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded. When doing stream copy or when -noaccurate_seek is used, it will be preserved. 43 | > 44 | >     When used as an output option (before an output url), decodes but discards input until the timestamps reach position. 45 | > 46 | >     position must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual. 47 | 48 | ### 输出举例 49 | 50 | ```bash 51 | ➜ splitAudio git:(master) ffmpeg -i show_14322648_audio.mp3 -c copy -ss 00:00:03.110 -to 00:00:06.110 show_14322648_audio_000003110_000006110_cCopy.mp3 52 | ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers 53 | built with Apple LLVM version 10.0.0 (clang-1000.11.45.2) 54 | configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-nonfree 55 | libavutil 56. 14.100 / 56. 14.100 56 | libavcodec 58. 18.100 / 58. 18.100 57 | libavformat 58. 12.100 / 58. 12.100 58 | libavdevice 58. 3.100 / 58. 3.100 59 | libavfilter 7. 16.100 / 7. 16.100 60 | libavresample 4. 0. 0 / 4. 0. 0 61 | libswscale 5. 1.100 / 5. 1.100 62 | libswresample 3. 1.100 / 3. 1.100 63 | libpostproc 55. 1.100 / 55. 1.100 64 | Input #0, mp3, from 'show_14322648_audio.mp3': 65 | Metadata: 66 | major_brand : isom 67 | minor_version : 0 68 | compatible_brands: isomiso2avc1 69 | encoder : Lavf58.12.100 70 | Duration: 00:00:48.27, start: 0.025057, bitrate: 128 kb/s 71 | Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s 72 | Metadata: 73 | encoder : Lavc58.18 74 | Output #0, mp3, to 'show_14322648_audio_000003110_000006110_cCopy.mp3': 75 | Metadata: 76 | major_brand : isom 77 | minor_version : 0 78 | compatible_brands: isomiso2avc1 79 | TSSE : Lavf58.12.100 80 | Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s 81 | Metadata: 82 | encoder : Lavc58.18 83 | Stream mapping: 84 | Stream #0:0 -> #0:0 (copy) 85 | Press [q] to stop, [?] for help 86 | size= 47kB time=00:00:02.97 bitrate= 129.5kbits/s speed=1.76e+03x 87 | video:0kB audio:47kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.173211% 88 | ``` 89 | -------------------------------------------------------------------------------- /src/subtitle/background/format.md: -------------------------------------------------------------------------------- 1 | # 字幕格式 2 | 3 | ## ASS 4 | 5 | * Advanced SubStation Alpha=ASS 6 | * 一句话描述:一种比SSA更先进的字幕脚本格式 7 | * 之前的格式 SSA 8 | * 全称:SubStation Alpha 9 | * 或 Sub Station Alpha 10 | * 由 CS Low(亦作 Kotus)创建 11 | * 特点 12 | * 比传统字幕(如SRT)更加强大先进的字幕文件格式。 13 | * 该格式在Windows平台上可以经播放器由VSFilter渲染进行播放。这是一款广受欢迎且已停止开发的字幕编辑制作工具。 14 | * 最新版本:V4.00 15 | * 基于:SSA 4.00+编码构建 16 | * 特点: 17 | * 在SSA编写风格的基础上增添更多的效果和指令 18 | * 使用现状 19 | * 该字幕格式常被字幕组所应用 20 | * 目前有很多播放器支持渲染SSA、ASS字幕 21 | * 最新版本:V4.00+ 22 | * ASS字幕分类 23 | * 软字幕 24 | * 特点 25 | * 过程可逆 26 | * 可以提取、取出和查看源代码的 27 | * 包含 28 | * 内挂字幕 29 | * 一般指字幕文件与视频一同封装在MKV文件中,播放时需经过VSFilter渲染 30 | * 外挂字幕 31 | * 字幕文件以单独形式存在,播放时经VSFilter渲染到视频上 32 | * 内嵌字幕 33 | * 指字幕被以图形方式硬编码到视频中 34 | * 变成视频数据本身=视频数据的一部分 35 | * 特点 36 | * 过程不可逆 37 | * 无法再把字幕提取出来 38 | * 播放时不需VSFilter等渲染 39 | * 常用字幕制作软件 40 | * Aegisub 41 | * Jubler 42 | * VisualSubSync 43 | * subtitleeditor 44 | * Sabbu 45 | * Sub Station Alpha tool 46 | * Subtitle Workshop 47 | * Subtitle Processor 48 | * Miyu 49 | * Gaupol 50 | * ASS格式详解 51 | * 脚本说明 52 | * Script Info: 脚本的一般全局信息: 53 | * Title:标题 54 | * Original Script:脚本原作 55 | * Script Updated By:脚本优化 56 | * Script Type:类型 57 | * 用于兼容性设置 58 | * SSA=4.00 59 | * ASS=4.00+ 60 | * PlayResX & PlayResY:屏幕宽高 61 | * PlayDepth:决定颜色数量 62 | * Timer:定时器 63 | * V4 Styles: 定义文字样式,在events部分可以直接调用这些样式。 64 | * PrimaryColour:第一颜色,即文字本身的颜色 65 | * SecondaryColour:第二颜色 66 | * 在卡拉OK时使用,卡拉OK指令会用第一颜色填充第二颜色。 67 | * TertiaryColour:边框色,文字边框的颜色 68 | * ASS中称为OutlineColour 69 | * BackColour:阴影颜色,文字阴影的颜色 70 | * MarginL, MarginR. 左右缩进。文字距离视频最左最右的最小距离。 71 | * MarginV: 上下缩进。 72 | * 文字热点(对齐点)距离视频上下的最小间距离。这取决于文字对齐方式,如果该文字使用中对齐,则上下缩进值无效。需要时文字可用\n或\N命令换行。ASS文件中,Script Info部分的一个参数“WrapStyle”也可以改变此值 73 | * Outline:边框样式 74 | * 文字可以设定为有边框,无边框,或拥有不透明边框(矩形背景) 75 | * Shadow:阴影距离 76 | * 文字的阴影到文字的距离大小 77 | * AlphaLevel.:透明度(0至255有效) 78 | * Encoding:ASCII码中的文字编码方式 79 | * Alignment:对齐方式 80 | * 含义:画面中位置的对齐方式,按照数字键盘区布局 81 | * 取值范围:1-9 82 | * 具体效果,参考此图: 83 | * 84 | * 默认:2 85 | * 底部居中 86 | * Events: 字幕的主体部分 87 | * 字幕的出现时间和样式、对样式的修改和特效 88 | * 语法格式为: 89 | * {\命令(参数,多个参数用逗号隔开)} 90 | * 例如 91 | * {\move(80,80,200,200,150,300)} 92 | * 只有一个参数的命令不需要括号 (如. {\kf89}) 93 | * 注意 94 | * 一对大括号内可以放置多个语句 95 | * 如 96 | * {\bord8\be1} 97 | * \N 和 \n 命令不需要在两边加大括号就可使用 98 | 99 | ### ass字幕文件举例 100 | 101 | 举例1: 102 | 103 | ![ass_subtitle_example](../../assets/img/ass_subtitle_example.png) 104 | 105 | 举例2:`input/5d41d82f52247ce73d40475b.ass` 106 | 107 | 内容是 108 | 109 | ```ini 110 | [Script Info] 111 | ; Script generated by FFmpeg/Lavc58.54.100 112 | ScriptType: v4.00+ 113 | PlayResX: 384 114 | PlayResY: 288 115 | 116 | [V4+ Styles] 117 | Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding 118 | Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0 119 | 120 | [Events] 121 | Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text 122 | Dialogue: 0,0:00:02.68,0:00:09.16,Default,,0,0,0,,I'm a policeman in the town. All day long,I walk around!\N我是镇上的警察 整天都在巡视 123 | Dialogue: 0,0:00:09.18,0:00:15.86,Default,,0,0,0,,I'm a policeman in the town. All day long, I walk around!\N我是镇上的警察 整天都在巡视 124 | ... 125 | Dialogue: 0,0:02:04.21,0:02:10.82,Default,,0,0,0,,It's my job. It's what I do. It's my job. I like it, too!\N牛奶员我的工作 这就是我的工作 牛奶员我的工作 我也很喜欢这份工作 126 | ``` 127 | 128 | ![ass_subtitle_file_example](../../assets/img/ass_subtitle_file_example.png) 129 | 130 | ## srt 131 | 132 | * `srt`=`subtitle` 133 | 134 | ### 举例 135 | 136 | 中英文双字幕: 137 | 138 | ```ini 139 | 1 140 | 00:00:02,000 --> 00:00:06,700 141 | Careful now, I don't want to hurt you. 142 | 现在要小心了 我可不想伤到你啊 143 | 144 | 2 145 | 00:00:10,500 --> 00:00:14,550 146 | So Mr. Teacher guy, as the real Dragon Warrior, 147 | 那么 这个作为神龙斗士老师的你 148 | 149 | 3 150 | 00:00:14,560 --> 00:00:17,950 151 | I say to you, Shakabooey! 152 | 我想对你说 滚你的 153 | 154 | 4 155 | 00:00:24,500 --> 00:00:28,030 156 | So, guess you can start planning my parade now. 157 | 那 我想你们可以开始我的游行了是吧 158 | ``` 159 | 160 | 英文(单字幕): 161 | 162 | ```ini 163 | 1 164 | 00:00:02,310 --> 00:00:04,677 165 | I am a little turtle 166 | 167 | 2 168 | 00:00:04,752 --> 00:00:07,540 169 | I crawl so slow 170 | 171 | 3 172 | 00:00:07,670 --> 00:00:12,120 173 | I carry my house wherever I go. 174 | 175 | 4 176 | 00:00:12,210 --> 00:00:16,927 177 | When I get tired, I put in my head, 178 | ``` 179 | -------------------------------------------------------------------------------- /src/appendix/help.md: -------------------------------------------------------------------------------- 1 | # help语法 2 | 3 | 贴出(后来重新安装的支持了ass等库的)ffmpeg的help帮助信息: 4 | 5 | ```bash 6 | ➜ ~ ffmpeg --help 7 | ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers 8 | built with Apple LLVM version 10.0.0 (clang-1000.11.45.2) 9 | configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-nonfree 10 | libavutil 56. 14.100 / 56. 14.100 11 | libavcodec 58. 18.100 / 58. 18.100 12 | libavformat 58. 12.100 / 58. 12.100 13 | libavdevice 58. 3.100 / 58. 3.100 14 | libavfilter 7. 16.100 / 7. 16.100 15 | libavresample 4. 0. 0 / 4. 0. 0 16 | libswscale 5. 1.100 / 5. 1.100 17 | libswresample 3. 1.100 / 3. 1.100 18 | libpostproc 55. 1.100 / 55. 1.100 19 | Hyper fast Audio and Video encoder 20 | usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... 21 | 22 | Getting help: 23 | -h -- print basic options 24 | -h long -- print more options 25 | -h full -- print all options (including all format and codec specific options, very long) 26 | -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf 27 | See man ffmpeg for detailed description of the options. 28 | 29 | Print help / information / capabilities: 30 | -L show license 31 | -h topic show help 32 | -? topic show help 33 | -help topic show help 34 | --help topic show help 35 | -version show version 36 | -buildconf show build configuration 37 | -formats show available formats 38 | -muxers show available muxers 39 | -demuxers show available demuxers 40 | -devices show available devices 41 | -codecs show available codecs 42 | -decoders show available decoders 43 | -encoders show available encoders 44 | -bsfs show available bit stream filters 45 | -protocols show available protocols 46 | -filters show available filters 47 | -pix_fmts show available pixel formats 48 | -layouts show standard channel layouts 49 | -sample_fmts show available audio sample formats 50 | -colors show available color names 51 | -sources device list sources of the input device 52 | -sinks device list sinks of the output device 53 | -hwaccels show available HW acceleration methods 54 | 55 | Global options (affect whole program instead of just one file: 56 | -loglevel loglevel set logging level 57 | -v loglevel set logging level 58 | -report generate a report 59 | -max_alloc bytes set maximum size of a single allocated block 60 | -y overwrite output files 61 | -n never overwrite output files 62 | -ignore_unknown Ignore unknown stream types 63 | -filter_threads number of non-complex filter threads 64 | -filter_complex_threads number of threads for -filter_complex 65 | -stats print progress report during encoding 66 | -max_error_rate maximum error rate ratio of errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success. 67 | -bits_per_raw_sample number set the number of bits per raw sample 68 | -vol volume change audio volume (256=normal) 69 | 70 | Per-file main options: 71 | -f fmt force format 72 | -c codec codec name 73 | -codec codec codec name 74 | -pre preset preset name 75 | -map_metadata outfile[,metadata]:infile[,metadata] set metadata information of outfile from infile 76 | -t duration record or transcode "duration" seconds of audio/video 77 | -to time_stop record or transcode stop time 78 | -fs limit_size set the limit file size in bytes 79 | -ss time_off set the start time offset 80 | -sseof time_off set the start time offset relative to EOF 81 | -seek_timestamp enable/disable seeking by timestamp with -ss 82 | -timestamp time set the recording timestamp ('now' to set the current time) 83 | -metadata string=string add metadata 84 | -program title=string:st=number... add program with specified streams 85 | -target type specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-") 86 | -apad audio pad 87 | -frames number set the number of frames to output 88 | -filter filter_graph set stream filtergraph 89 | -filter_script filename read stream filtergraph description from a file 90 | -reinit_filter reinit filtergraph on input parameter changes 91 | -discard discard 92 | -disposition disposition 93 | 94 | Video options: 95 | -vframes number set the number of video frames to output 96 | -r rate set frame rate (Hz value, fraction or abbreviation) 97 | -s size set frame size (WxH or abbreviation) 98 | -aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777) 99 | -bits_per_raw_sample number set the number of bits per raw sample 100 | -vn disable video 101 | -vcodec codec force video codec ('copy' to copy stream) 102 | -timecode hh:mm:ss[:;.]ff set initial TimeCode value. 103 | -pass n select the pass number (1 to 3) 104 | -vf filter_graph set video filters 105 | -ab bitrate audio bitrate (please use -b:a) 106 | -b bitrate video bitrate (please use -b:v) 107 | -dn disable data 108 | 109 | Audio options: 110 | -aframes number set the number of audio frames to output 111 | -aq quality set audio quality (codec-specific) 112 | -ar rate set audio sampling rate (in Hz) 113 | -ac channels set number of audio channels 114 | -an disable audio 115 | -acodec codec force audio codec ('copy' to copy stream) 116 | -vol volume change audio volume (256=normal) 117 | -af filter_graph set audio filters 118 | 119 | Subtitle options: 120 | -s size set frame size (WxH or abbreviation) 121 | -sn disable subtitle 122 | -scodec codec force subtitle codec ('copy' to copy stream) 123 | -stag fourcc/tag force subtitle tag/fourcc 124 | -fix_sub_duration fix subtitles duration 125 | -canvas_size size set canvas size (WxH or abbreviation) 126 | -spre preset set the subtitle options to the indicated preset 127 | ``` 128 | 129 | 供参考。 130 | -------------------------------------------------------------------------------- /src/ffmpeg_summary/README.md: -------------------------------------------------------------------------------- 1 | # ffmpeg使用心得 2 | 3 | 此处整理ffmpeg的一些使用心得。 4 | 5 | ## 报错:[AVFilterGraph @ 0x7fa224608740] No such filter: 'ass' 6 | 7 | ```bash 8 | ffmpeg -i CTT_Folge_01_CH_Subs_DefaultZhcnButNotShow.mp4 -vf "ass=subtitle.ass" addedAssSubtitle.mp4 9 | ``` 10 | 11 | 报错: 12 | 13 | ```bash 14 | [AVFilterGraph @ 0x7fa224608740] No such filter: 'ass' 15 | ``` 16 | 17 | 原因:此处ffmpeg(没有subtitles,也)没有ass的filter 18 | 19 | 办法: 20 | 21 | 重新安装支持了ass的ffmpeg 22 | 23 | 具体步骤: 24 | 25 | Mac 26 | 27 | ```bash 28 | brew reinstall ffmpeg --with-libass 29 | ``` 30 | 31 | ## 报错:Error: Calling keg_only :provided_pre_mountain_lion is disabled! There is no replacement 32 | 33 | 重新安装ffmpeg期间: 34 | 35 | ```bash 36 | ffmpeg_edit_subtitle brew reinstall ffmpeg \ 37 | --with-tools \ 38 | --with-fdk-aac \ 39 | --with-freetype \ 40 | --with-fontconfig \ 41 | --with-libass \ 42 | --with-libvorbis \ 43 | --with-libvpx \ 44 | --with-opus \ 45 | --with-x265 46 | ``` 47 | 48 | 报错: 49 | 50 | ```bash 51 | Error: Calling keg_only :provided_pre_mountain_lion is disabled! There is no replacement. 52 | ``` 53 | 54 | 解决办法: 55 | 56 | 先去更新brew再升级ffmpeg 57 | 58 | ```bash 59 | brew update && brew upgrade ffmpeg 60 | ``` 61 | 62 | 再去: 63 | 64 | ```bash 65 | brew reinstall ffmpeg 加上你的要的参数 66 | ``` 67 | 68 | 即: 69 | 70 | ```bash 71 | brew reinstall ffmpeg \ 72 | --with-tools \ 73 | --with-fdk-aac \ 74 | --with-freetype \ 75 | --with-fontconfig \ 76 | --with-libass \ 77 | --with-libvorbis \ 78 | --with-libvpx \ 79 | --with-opus \ 80 | --with-x265 81 | ``` 82 | 83 | ## ffmpeg不显示头部信息 84 | 85 | 用ffmpeg去处理视频等过程中,每次运行命令,都会输出ffmpeg版本等信息 86 | 87 | 举例: 88 | 89 | ```bash 90 | # ffmpeg -nostdin -i /root/xxx/course/32145/course_32145_video.mp4 -vf "delogo=x=474:y=6:w=162:h=90" -c:a copy /root/xxx/course/32145/course_32145_video_removedWatermark.mp4 91 | ffmpeg version 4.2-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers 92 | built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 93 | configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg 94 | libavutil 56. 31.100 / 56. 31.100 95 | libavcodec 58. 54.100 / 58. 54.100 96 | libavformat 58. 29.100 / 58. 29.100 97 | libavdevice 58. 8.100 / 58. 8.100 98 | libavfilter 7. 57.100 / 7. 57.100 99 | libswscale 5. 5.100 / 5. 5.100 100 | libswresample 3. 5.100 / 3. 5.100 101 | libpostproc 55. 5.100 / 55. 5.100 102 | Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/root/xxx/course/32145/course_32145_video.mp4': 103 | Metadata: 104 | major_brand : isom 105 | minor_version : 512 106 | compatible_brands: isomiso2avc1mp41 107 | creation_time : 2015-11-16T08:09:13.000000Z 108 | encoder : Lavf57.71.100 109 | Duration: 00:00:46.00, start: 0.000000, bitrate: 678 kb/s 110 | Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 544 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) 111 | Metadata: 112 | creation_time : 2015-11-16T08:09:13.000000Z 113 | handler_name : VideoHandler 114 | Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default) 115 | Metadata: 116 | creation_time : 2015-11-16T08:09:13.000000Z 117 | handler_name : SoundHandler 118 | Stream mapping: 119 | Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) 120 | Stream #0:1 -> #0:1 (copy) 121 | [libx264 @ 0xce0e540] using SAR=1/1 122 | [libx264 @ 0xce0e540] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512 123 | [libx264 @ 0xce0e540] profile Progressive High, level 3.0, 4:2:0, 8-bit 124 | [libx264 @ 0xce0e540] 264 - core 157 r2969 d4099dd - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 125 | Output #0, mp4, to 126 | ...... 127 | ``` 128 | 129 | 中的: 130 | 131 | ```bash 132 | ffmpeg version 4.2-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers 133 | built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 134 | configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg 135 | libavutil 56. 31.100 / 56. 31.100 136 | libavcodec 58. 54.100 / 58. 54.100 137 | libavformat 58. 29.100 / 58. 29.100 138 | libavdevice 58. 8.100 / 58. 8.100 139 | libavfilter 7. 57.100 / 7. 57.100 140 | libswscale 5. 5.100 / 5. 5.100 141 | libswresample 3. 5.100 / 3. 5.100 142 | libpostproc 55. 5.100 / 55. 5.100 143 | ``` 144 | 145 | 这部分内容。 146 | 147 | 如果觉得很麻烦,想要禁止其输出,可以加上参数: 148 | 149 | `-hide_banner` 150 | 151 | 用于禁止显示banner,即可。 152 | 153 | ## ffmpeg不显示输出的众多的普通的信息 154 | 155 | 另外,如果对于处理期间输出的众多内容,不想要显示,则可以加: 156 | 157 | `-loglevel error` 158 | 159 | 用于设置当输出的信息,超过error,才显示 160 | 161 | 而上面信息都是属于普通的info级别,低于error,所以就不显示 162 | 163 | 起到控制不显示普通的输出的信息的效果了 164 | 165 | 注: 166 | 167 | ffmpeg输出信息的等级: 168 | 169 | * `quiet` 170 | * `panic` 171 | * `fatal` 172 | * `error` 173 | * `warning` 174 | * `info` 175 | * `verbose` 176 | * `debug` 177 | 178 | ## ffmpeg强制覆盖输出文件 179 | 180 | ffmpeg强制覆盖输出文件 = 不需要当每次检测到已存在文件再提示你是否要覆盖 181 | 182 | 用ffmpeg时,如果输出文件已存在,默认不会覆盖,会提示你: 183 | 184 | ```bash 185 | File xxx.mp4 already exists. Overwrite ? [y/N] 186 | ``` 187 | 188 | 要输入y,才可以继续: 189 | 190 | ![ffmpeg_already_exists_y](../assets/img/ffmpeg_already_exists_y.png) 191 | 192 | 如果不想要提示,而是强制覆盖源文件,则可以加上参数: 193 | 194 | `-y` 195 | 196 | 相关参数含义: 197 | 198 | ```bash 199 | # ffmpeg --help 200 | ... 201 | -y overwrite output files 202 | ``` 203 | --------------------------------------------------------------------------------