视频应用
mplayer
mplayer -vo caca video.avi
注:参数caca表示彩色字符模式,aa表示黑白字符模式。
ffmpeg
压缩手机拍摄的视频的大小的例子:
-
-r 20
:帧率设置为20。 -
-vf scale=-1:720
:分辨率为720p。
ffmpeg -i video001.mp4 -vf scale=720:-1 -r 20 video-001.mp4
修改画质
改变帧率
改变帧率-r 20
:表示帧率设置为 20fps
ffmpeg -i Desktop/吉他.mp4 -r 20 Desktop/output1.mp4
改变分辨率
改变分辨率-s vga
: 指定分辨率,vga
代表600*480
,也可以换成其他的值
ffmpeg -i Desktop/1.mov -s vga Desktop/1.mp4
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
保持高质量的同时调整视频大小, 使用crf=18withlibx264的slow预设对其进行编码:
ffmpeg -i input.mp4 -vf scale=1280:720 -preset slow -crf 18 output.mp4
改变码率
视频的原码率是2.1Mb/s
,压缩为1.5Mb/s
-
-b:v 1.5M
: 指定码率 -
-b:v
:指定视频的码率 -
-b:a
: 指定音频的码率 -
1.5M
:码率的值 1.5M 表示 1.5Mb/s
ffmpeg -i Desktop/1.mov -b:v 1.5M Desktop/1.mp4 ffmpeg -i vin/VID_20200104_195552.mp4 -b:v 2.1M vout/VID_20200104_195552.mp4 ffmpeg -i vin/VID_20201017_183526.mp4 -b:v 2.1M vout/VID_20201017_183526.mp4 ffmpeg -i vin/VID_20201021_141548.mp4 -b:v 2.1M vout/VID_20201021_141548.mp4 ffmpeg -i vin/VID_20201021_141826.mp4 -b:v 2.1M vout/VID_20201021_141826.mp4 ffmpeg -i vin/VID_20210506_150919.mp4 -b:v 2.1M vout/VID_20210506_150919.mp4 ffmpeg -i vin/VID_20210506_150928.mp4 -b:v 2.1M vout/VID_20210506_150928.mp4 ffmpeg -i vin/VID_20210507_111104.mp4 -b:v 2.1M vout/VID_20210507_111104.mp4 ffmpeg -i vin/VID_20210507_111417.mp4 -b:v 2.1M vout/VID_20210507_111417.mp4
转换视频或图片大小
# 指定转换之后的大小 ffmpeg -i input_img.jpg -vf scale=1024:720 output_img.jpg # 指定一个维度,另一个维度自动计算 ffmpeg -i input_img.jpg -vf scale=1024:-1 output_img.jpg
强制覆盖输出文件
# -y用户强制覆盖输出文件,例如: ffmpeg -i input_video.mp4 -y output_video.avi ffmpeg -i input_img.jpg -vf scale=1024:-1 -y output_img.jpg
提取部分
把图片合并为视频
带序号的多张图片,每张是一帧,如Selection_001.jpg
到Selection_100.jpg
:
ffmpeg -f image2 -i frames/Selection_%03d.jpg output.mp4
提取一帧图片
提取视频中某一帧并保存到图片:
# -ss指定秒数 ffmpeg -ss 2 -i test.mp4 output_img.png
提取视频或者音频
提取视频或者音频的一段:
# -ss指定起始时间,-t指定时长 ffmpeg -i input.mp4 -ss 00:00:30.0 -t 00:00:10.0 output.mp4 ffmpeg -i input.mp4 -ss 30 -t 10 output.mp4
-
-ss
指定时间HH:MM:SS.MILLISECONDS
的格式。 -
-t
指定范围。例如,-ss 40 -t 10
指示 FFmpeg 从第 40 秒开始提取 10 秒的视频。 -
-to
指定范围。例如,-ss 40 -to 70
指示 FFmpeg 从第 40 秒到第 70 秒提取 30 秒的视频。 -
注意:如果你同时使用
-t
和-to
,那么只有-t将被使用。
转换视频格式
视频格式
ffmpeg -i input_video.mp4 output_video.avi
图片合并为视频
将多个图片合并为视频:
# 图片文件名需要满足一定的pattern ffmpeg -framerate 15 -i img_%012d.png -vcodec libx264 -pix_fmt yuv420p -vf hflip output_video.mp4
多个视频连接
先把每个视频转为h264:
ffmpeg -i 001.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input01.ts ffmpeg -i 002.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input02.ts ffmpeg -i 003.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input03.ts
再合并到一起:
ffmpeg -i "concat:input01.ts|input02.ts|input03.ts" -c copy -bsf:a aac_adtstoasc -movflags +faststart output.mp4
保存 QuickTime/MP4 格式容器的时候,建议加上-movflags +faststart
。
这样分享文件给别人的时候可以边下边看。
如果文件数量多,可以写入到文件中:
file 'input01.ts' file 'input02.ts' file 'input03.ts' file 'input04.ts' file 'input05.ts'
然后指定文件:
ffmpeg -f concat -i filelist.txt -c copy -bsf:a aac_adtstoasc -movflags +faststart output.mp4
合并视频与音频
在一些视频网站,720P 以上清晰度的音视频往往是分离存储的。我们可以利用 FFmpeg 将它们合并。 合并音视频
ffmpeg -i xxxxx_videoonly.mp4 -i xxxxx_audioonly.mp4 -c:v copy -c:a aac -strict experimental xxxxx.mp4
你也可以: 替换掉原视频中已有的音频
ffmpeg -i xxxxx_videoonly.mp4 -i xxxxx_audioonly -c:v copy -c:a aac -strict experimental-map 0:v:0 -map 1:a:0 xxxxx.mp4
如果你想分离(抽取)一个画面静止的视频中的音频
ffmpeg -i xxxxx.mp4 -vn -y -acodec copy xxxxx_audio.m4a
不想要声音?去掉视频中的音频(将视频静音)
ffmpeg -i xxxxx.mp4 -an xxxxx_audioonly.mp4
画面合并
横向合并两个视频
(只能保留前一个视频的音频,如果想同时保留两个视频的音频可以把音频事先分离出来合并。如果高度不同,使用-shortest
参数来保证高度相同)
ffmpeg -i xxxxx.mp4 -i yyyyy.mp4 -lavfi hstack output.mp4
合并多个视频
(以三个为例,更多自行添加更多 -i 并修改 intputs 数量)
ffmpeg -i xxxxx.mp4 -i yyyyy.mp4 -i zzzzz.mp4 -lavfi hstack=inputs=3 output.mp4
纵向合并视频
ffmpeg -i xxxxx.mp4 -i yyyyy.mp4 -lavfi vstack output.mp4
多个视频合并成监控画面
将多个视频合并成网格状(类似监控画面)
如果碰上只有三个视频这样的情况,可以生成一张纯黑图像来补位
ffmpeg -f lavfi -i color=c=black:s=1280x720 -vframes 1 black.png
修改 1280x720 为 1920x1080 或其它值来改变纯黑图像的大小。
ffmpeg -i top_left.mp4 -i top_right.mp4 -i bottom_left.mp4 -i bottom_right.mp4 \-lavfi "[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack"-shortest xxxxx.mp4
上面创建的是正常的2x2网格视频。
如果只有三个视频,需要把第一个视频摆放在第一行的中间,第二、三个视频摆放在第二行呢?
ffmpeg -f lavfi -i color=c=black:s=640x720 -vframes 1 black.png ffmpeg -i black.png -i top_center.mp4 -i bottom_left.mp4 -i bottom_right.mp4 -lavfi "[0:v][1:v][0:v]hstack=inputs=3[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack" -shortest 3_videos_2x2_grid.mp4
Bilibili App缓存位置
缓存目录在:/Android/data/tv.danmaku.bili/download
视频管理
emby
http://localhost:8096/
emby file format
Movie
- extras
- specials
- shorts
- scenes
- featurettes
- behind the scenes
- deleted scenes
- interviews
- trailers
mkdir "Gone in Sixty Seconds 极速60秒 (2000)" "Gone in Sixty Seconds 极速60秒 (2000) - 双语字幕.HR-HDTV.AC3.1024X576.X264-人人影视制作.mkv"
mv Apocalypse\ Now\ \(1979\)\ -\ Redux\ 双语字幕.HR-HDTV.AC3.1024X576.x264-人人影视制作.mkv Apocalypse\ Now\ Redux\ \(1979\)\ -\ 双语字幕.HR-HDTV.AC3.1024X576.x264-人人影视制作.mkv
mkdir "Apocalypse Now Redux (1979)"
"Apocalypse Now Redux (1979) - 双语字幕.HR-HDTV.AC3.1024X576.x264-人人影视制作.mkv"
/Movies /Home Alone (1990) Home Alone (1990) - 1080p.mkv Home Alone (1990) - 4K.mkv Home Alone (1990) - 720p.mp4 Home Alone (1990) - extended edition.mp4 Home Alone (1990) - directors cut.mp4 Home Alone (1990) - 3D.hsbs.mp4 /extras deleted-scenes.mkv - 1080p.mkv deleted-scenes.mkv - 4K.mkv deleted-scenes.mkv - 720p.mp4 /behind the scenes video1.mkv - 1080p.mkv video1.mkv - 4K.mkv video1.mkv - 720p.mp4 /interviews video1.mkv - 1080p.mkv video1.mkv - 4K.mkv video1.mkv - 720p.mp4
TV Serise
Undone (2019) ├── clearlogo.png ├── fanart.jpg ├── landscape.jpg ├── poster.jpg ├── season01-poster.jpg ├── Season 01 │ ├── season01-poster.jpg │ ├── season.nfo │ ├── Undone S01E01.mkv │ ├── Undone S01E01.nfo │ ├── Undone S01E01-thumb.jpg │ ├── Undone S01E02.mkv │ ├── Undone S01E02.nfo │ ├── Undone S01E02-thumb.jpg │ ├── Undone S01E03.mkv │ ├── Undone S01E03.nfo │ ├── Undone S01E03-thumb.jpg │ ├── Undone S01E04.mkv │ ├── Undone S01E04.nfo │ ├── Undone S01E04-thumb.jpg │ ├── Undone S01E05.mkv │ ├── Undone S01E05.nfo │ ├── Undone S01E05-thumb.jpg │ ├── Undone S01E06.mkv │ ├── Undone S01E06.nfo │ ├── Undone S01E06-thumb.jpg │ ├── Undone S01E07.mkv │ ├── Undone S01E07.nfo │ ├── Undone S01E07-thumb.jpg │ ├── Undone S01E08.mkv │ ├── Undone S01E08.nfo │ └── Undone S01E08-thumb.jpg └── tvshow.nfo
连续剧如果有特典和特别集的话,要放在以下的目录下:
- Season 0
- Season 00
- Specials
Subtitle
Default Subtitles
External subtitles can be marked as default using either ".default".
/Movies /Home Alone (1990) Home Alone.mkv Home Alone.srt Home Alone.spa.default.srt
Forced Subtitles
External subtitles can be marked as forced using either ".forced" or ".foreign".
/Movies /Home Alone (1990) Home Alone.mkv Home Alone.srt Home Alone.spa.forced.srt Home Alone.spa.foreign.srt
language:
-
zh-CN
ext for mainland China (simplified) -
zh-SG
ext for Singapore (simplified) -
zh-TW
ext for Taiwan (traditional) -
zh-HK
ext for Hong Kong (traditional)
video to image
How to convert a batch of videos (#mp4) to images (#jpg) at regular time interval throughout each video (with optional resize). Just thought I would share a simple script I made in case anyone else needed to do the same. It is by no means battle-hardened but assuming you have sane names for your videos and trust the content it should work fine. Works great on #Ubuntu on my #GCE instance. Enjoy!
OS: Ubuntu Dependencies: ffmpeg, zip (sudo apt-get install these)
Simply create a new sh file eg script.sh, paste in the below code, and then run:
chmod +x script.sh
To make it executable.
Finally example usage to generate 1 jpg every 1 second in video:
./script.sh 1
Or to resize too use: ./script.sh 1 320:-1
Which would resize to 320px wide whilst maintaining aspect ratio. Here is the script:
#!/bin/sh # A simple script to convert all mp4 videos in current folder to jpg frames with # unique names. Note assumes max frames per video is no more than 999999 # Usage Example 1: Create 5 images every second of video (ie every 200ms) # script.sh 5 # Can also optionally pass scale as 2nd parameter. For example: # script.sh 5 320:-1 # In this case it would resize the width to be 320px and keep aspect ratio for height. #@author Jason Mayes FPS="$1" SCALE="" if [ $2 -eq 0 ] then SCALE="scale="$2"," fi rm *.jpg for i in *.mp4; do echo "$i" # Replace .mp4 with blank to remove FILEPREFIX=$(echo $i | sed 's/.mp4//g') # Generate frames every quarter of a second assuming 25fps ffmpeg -i "$FILEPREFIX".mp4 -y -an -q 0 -vf "$SCALE"fps="$FPS" "$FILEPREFIX"_%06d.jpg done zip -r images.zip *.jpg
视频直播
上传本地视频直播
安装ffmpeg
sudo apt-get install ffmpeg
制作脚本:
#!/bin/bash while true do ffmpeg -re -i "example.mp4" -vcodec copy -acodec aac -b:a 192k -f flv "你的rtmp地址/你的直播码" done
https://www.cnblogs.com/tocy/p/using-ffmpeg-build-hls-live-system.html
https://blog.csdn.net/kingroc/article/details/50839994
https://blog.csdn.net/qq_29099209/article/details/80242476