Board logo

标题: [文件操作] 如何写ffmpeg批处理将一批每集1小时左右的aac文件分割为每集20分钟的文件 [打印本页]

作者: tmp05    时间: 2022-5-22 15:08     标题: 如何写ffmpeg批处理将一批每集1小时左右的aac文件分割为每集20分钟的文件

本帖最后由 tmp05 于 2022-5-22 15:15 编辑

有一批每集时长为1小时的aac音频文件,请问如何写ffmpeg批处理将它们分割为每集20分钟的mp3文件,用格式工厂似乎做不到。谢谢了!
找到了这篇,https://blog.csdn.net/iteye_19045/article/details/94879577,但这是去头去尾的,而不是等量分割
作者: Batcher    时间: 2022-5-22 15:58

回复 1# tmp05


先找一个文件试试:
test.bat
ffmpeg.exe
in.aac
放在同一个目录下
  1. @echo off
  2. cd /d "%~dp0"
  3. ffmpeg -i "in.aac" -f segment -segment_time 1200 -c copy "out_%%03d.mp3"
复制代码

作者: tmp05    时间: 2022-5-22 20:04

运行后是这样的:


作者: Batcher    时间: 2022-5-23 12:05

回复 3# tmp05
  1. @echo off
  2. cd /d "%~dp0"
  3. ffmpeg -i "in.aac" -acodec libmp3lame "temp.mp3"
  4. ffmpeg -i "temp.mp3" -f segment -segment_time 60 -c copy "out_%%03d.mp3"
复制代码

作者: tmp05    时间: 2022-5-23 14:07

回复  tmp05
Batcher 发表于 2022-5-23 12:05

单个文件这样可以了,但如何批量?
作者: Batcher    时间: 2022-5-23 14:11

回复 5# tmp05
  1. @echo off
  2. cd /d "%~dp0"
  3. for /f "delims=" %%i in ('dir /b /a-d *.aac') do (
  4.     ffmpeg -i "%%i" -acodec libmp3lame "temp.mp3"
  5.     ffmpeg -i "temp.mp3" -f segment -segment_time 60 -c copy "%%~ni_%%03d.mp3"
  6. )
复制代码

作者: tmp05    时间: 2022-5-23 16:20

回复  tmp05
Batcher 发表于 2022-5-23 14:11

每次还要确认下?能否再帮完善下,谢谢

作者: Batcher    时间: 2022-5-23 17:39

回复 7# tmp05
  1. @echo off
  2. cd /d "%~dp0"
  3. for /f "delims=" %%i in ('dir /b /a-d *.aac') do (
  4.     ffmpeg -i "%%i" -acodec libmp3lame "temp.mp3" -y
  5.     ffmpeg -i "temp.mp3" -f segment -segment_time 60 -c copy "%%~ni_%%03d.mp3"
  6. )
复制代码

作者: tmp05    时间: 2022-5-24 13:51

本帖最后由 tmp05 于 2022-5-24 16:38 编辑

回复 8# Batcher


    可以了,谢谢版主!另外,请问如何将每个文件三等分,而不是分成20分钟一个文件?要求有点多
作者: tmp05    时间: 2022-5-27 10:01

请问如何将每个文件三等分?
作者: tmp05    时间: 2022-5-29 07:28

有劳版主方便时帮改下语句,谢谢
作者: flashercs    时间: 2022-5-29 19:52

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. cd /d "%~dp0"
  4. set splitCount=3
  5. for /f "delims=" %%i in ('dir /b /a-d *.aac') do (
  6.     ffmpeg -y -i "%%i" -acodec libmp3lame "temp.mp3"
  7.     for /f "delims=" %%B in ('ffprobe -show_format -i "temp.mp3" 2^>nul^|findstr /lbic:"duration="') do (
  8.     set %%B
  9.   )
  10.   set /a d=duration/splitCount+1
  11.   ffmpeg -i "temp.mp3" -f segment -segment_time !d! -c copy "%%~ni_%%03d.mp3"
  12. )
  13. endlocal
复制代码

作者: tmp05    时间: 2022-5-30 14:58

回复 12# flashercs
执行了下,是这样的:

作者: flashercs    时间: 2022-5-30 15:16

回复 13# tmp05


    下载ffprobe http://bcn.bathome.net/tool/ffmpeg,4.3/ffprobe.exe
作者: Batcher    时间: 2022-5-30 15:51

回复 9# tmp05
  1. @echo off
  2. cd /d "%~dp0"
  3. setlocal enabledelayedexpansion
  4. set "SplitCount=3"
  5. for /f "delims=" %%i in ('dir /b /a-d *.aac') do (
  6.     ffmpeg -i "%%i" -acodec libmp3lame "temp.mp3" -y
  7.     for /f "tokens=2-4 delims=:. " %%a in ('ffmpeg -i "temp.mp3" 2^>^&1 ^| find "Duration:"') do (
  8.         call :Time2SS %%a %%b %%c
  9.     )
  10.     set /a SegTime=SS/SplitCount+1
  11.     ffmpeg -i "temp.mp3" -f segment -segment_time !SegTime! -c copy "%%~ni_%%03d.mp3"
  12. )
  13. goto :eof
  14. :Time2SS
  15. set /a HH=1%1-100
  16. set /a MM=1%2-100
  17. set /a SS=1%3-100
  18. set /a HH2MM=HH*60
  19. set /a MM+=HH2MM
  20. set /a MM2SS=MM*60
  21. set /a SS+=MM2SS
  22. goto :eof
复制代码

作者: tmp05    时间: 2022-5-31 10:58

回复 15# Batcher
是否将SplitCount=3改为SplitCount=4就是四等分?谢谢!
作者: Batcher    时间: 2022-5-31 11:16

回复 16# tmp05


    请亲自尝试一下吧,如果有问题的话咱们再继续研究。
作者: tmp05    时间: 2022-6-2 09:10

回复 17# Batcher
谢谢回复!




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2