FFmpeg转换ts为mp4

冷不防 2023-07-04 04:56 70阅读 0赞

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)内容如下:

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

2、点击保存

第四步:双击 run.bat 运行

其它参考命令

  1. for %%a in ("*.ts") do ffmpeg -i "%%a" -f mp4 -codec copy "%%~na.mp4
  2. 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 去掉片头片尾

  1. ::s1 为片头长度。s2为片尾长度
  2. @echo off & setlocal enabledelayedexpansion
  3. set "s1=00:00:36.00"
  4. set "s2=00:00:36.00"
  5. for /f "tokens=1-4delims=:." %%a in ("%s2%") do (
  6. set /a "t2=(1%%a %% 100 *3600 + 1%%b %% 100 * 60 + 1%%c %% 100) * 1000 + 1%%d %% 1000"
  7. )
  8. md NEW 2>nul
  9. for %%i in (*.mp4) do (
  10. for /f "tokens=2-5delims=:., " %%a in ('ffmpeg -i "%%i" 2^>^&1 ^| find "Duration:"') do (
  11. 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"
  12. set /a h=t/3600,m=t%%3600/60,s=t%%60,h+=100,m+=100,s+=100,ms+=1000
  13. set "t=!h:~1!:!m:~1!:!s:~1!.!ms:~1!"
  14. ffmpeg -i "%%i" -ss !s1! -to !t! -vcodec copy -acodec copy "NEW\%%i" -y
  15. )
  16. )
  17. pause
  18. #python+ffmpeg批量去视频开头
  19. import os
  20. pp=os.getcwd()
  21. path=''#视频所在目录
  22. time=''#格式为hh:mm:ss[.xxx]的形式
  23. for i in os.listdir(path):
  24. 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))
  25. #将这个脚本放到视频的上一层目录,然后指定path为所在目录,time为截去的时间
  26. #视频切割由ffmpeg实现,并且会删除原文件

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

基于FFMpeg的C#录屏全攻略

ffmpeg截取视频

FFmpeg:视频转码、剪切、合并、播放速调整

发表评论

表情:
评论列表 (有 0 条评论,70人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ffmpeg MP4

    FFmpeg 是一个开源的视频和音频转码工具,可以用来转码 MP4 格式的文件。MP4 是一种常用的视频格式,可以支持视频和音频的压缩和存储。使用 FFmpeg 可以将其他格式

    相关 mp4文件如何转换webm格式

    虽说目前我们生活中MP4格式比较常见,使用也比较广泛,但是有时候还是难免会遇到其他格式,那么当我们遇到这种情况时应该怎么办呢?我教大家使用迅捷视频转换器来转换视频格式,推荐的这

    相关 mp4文件如何转换webm格式

    虽说目前我们生活中MP4格式比较常见,使用也比较广泛,但是有时候还是难免会遇到其他格式,那么当我们遇到这种情况时应该怎么办呢?我教大家使用迅捷视频转换器来转换视频格式,推...