FFmpeg转换ts为mp4

1.转换ts为mp4

第一步:官网下载 FFmpeg

打开 https://ffmpeg.zeranoe.com/builds/

点 download 按钮,找到自己的系统对应格式(如Windows7 64位下载压缩包ffmpeg-20200108-5bd0010-win64-static)

第二步:解压

解压后,有个bin目录,里面是3个exe文件

第三步:编写批处理bat脚本,放在此路径下

1、新建一个txt文本,将txt后缀修改为可执行的bat文件(如:run.bat)内容如下:

for %%a in ("D:\源视频目录\*.mp4") do ffmpeg -i "%%a"   -vcodec copy -acodec copy -f mpegts "D:\转换后目录\%%~na.ts"
pause

2、点击保存

第四步:双击 run.bat 运行

其它参考命令

for %%a in ("*.ts") do ffmpeg -i "%%a" -f mp4 -codec copy "%%~na.mp4
pause

2.使用ffmpeg拆分大的mp4文件为小段的mp4文件

With ffmpeg you can split file using the following command:

ffmpeg -acodec copy -vcodec copy -ss START -t LENGTH -i ORIGINALFILE.mp4 OUTFILE.mp4

where START is starting positing in seconds or in format hh:mm:ss LENGTH is the chunk length in seconds or in format hh:mm:ss

So you will need to run this command few times depending on how long your video. If let's say your video is 31 minutes long and you want so split into 15 min chunks here is how you run it:

ffmpeg -acodec copy -vcodec copy -ss 0 -t 00:15:00 -i ORIGINALFILE.mp4 OUTFILE-1.mp4

ffmpeg -acodec copy -vcodec copy -ss 00:15:00 -t 00:15:00 -i ORIGINALFILE.mp4 OUTFILE-2.mp4

ffmpeg -acodec copy -vcodec copy -ss 00:30:00 -t 00:15:00 -i ORIGINALFILE.mp4 OUTFILE-3.mp4

There is a python script that you can use that does this automatically(i.e. takes video file, chunk size in seconds and generates individual playable video files): http://icephoenix.us/notes-for-myself/auto-splitting-video-file-in-equal-chunks-with-ffmpeg-and-python/

3 使用ffmpeg命令分割视频方法

4 FFMPEG 视频分割和合并

5 FFMPEG无损快速剪辑入门

6 ffmpeg 去掉片头片尾

::s1 为片头长度。s2为片尾长度
@echo off & setlocal enabledelayedexpansion
set "s1=00:00:36.00"
set "s2=00:00:36.00"
for /f "tokens=1-4delims=:." %%a in ("%s2%") do (
    set /a "t2=(1%%a %% 100 *3600 + 1%%b %% 100 * 60 + 1%%c %% 100) * 1000 + 1%%d %% 1000"
)

md NEW 2>nul
for %%i in (*.mp4) do (
    for /f "tokens=2-5delims=:., " %%a in ('ffmpeg -i "%%i" 2^>^&1 ^| find "Duration:"') do (
        set /a "t=(1%%a%%100*3600+1%%b%%100*60+1%%c%%100)*1000+1%%d0%%1000,t-=t2,ms=t%%1000,t/=1000"
        set /a h=t/3600,m=t%%3600/60,s=t%%60,h+=100,m+=100,s+=100,ms+=1000
        set "t=!h:~1!:!m:~1!:!s:~1!.!ms:~1!"
        ffmpeg -i "%%i" -ss !s1! -to !t! -vcodec copy -acodec copy "NEW\%%i" -y
    )
)
pause
#python+ffmpeg批量去视频开头
import os
pp=os.getcwd()
path=''#视频所在目录
time=''#格式为hh:mm:ss[.xxx]的形式
for i in os.listdir(path):
    os.system("""ffmpeg -i '%s/%s/%s' -ss %s -vcodec copy -acodec copy '%s/%s/%s'&&rm '%s/%s/%s'"""%(pp,path,i,time,pp,path,i[:-4]+'@.mp4',pp,path,i))
#将这个脚本放到视频的上一层目录,然后指定path为所在目录,time为截去的时间
#视频切割由ffmpeg实现,并且会删除原文件

使用FFmpeg进行屏幕录像和录音

基于FFMpeg的C#录屏全攻略

ffmpeg截取视频

发布了254 篇原创文章 · 获赞 31 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/yueliang2100/article/details/104223715