批处理之家's Archiver

tmp05 发表于 2022-5-22 15:08

如何写ffmpeg批处理将一批每集1小时左右的aac文件分割为每集20分钟的文件

[i=s] 本帖最后由 tmp05 于 2022-5-22 15:15 编辑 [/i]

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

Batcher 发表于 2022-5-22 15:58

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=255944&ptid=62809]1#[/url] [i]tmp05[/i] [/b]


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

tmp05 发表于 2022-5-22 20:04

运行后是这样的:

[img]https://s1.ax1x.com/2022/05/22/OzKN4J.jpg[/img]

Batcher 发表于 2022-5-23 12:05

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=255955&ptid=62809]3#[/url] [i]tmp05[/i] [/b][code]@echo off
cd /d "%~dp0"
ffmpeg -i "in.aac" -acodec libmp3lame "temp.mp3"
ffmpeg -i "temp.mp3" -f segment -segment_time 60 -c copy "out_%%03d.mp3"[/code]

tmp05 发表于 2022-5-23 14:07

[quote]回复  tmp05
[size=2][color=#999999]Batcher 发表于 2022-5-23 12:05[/color] [url=http://www.bathome.net/redirect.php?goto=findpost&pid=255968&ptid=62809][img]http://www.bathome.net/images/common/back.gif[/img][/url][/size][/quote]
单个文件这样可以了,但如何批量?

Batcher 发表于 2022-5-23 14:11

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=255975&ptid=62809]5#[/url] [i]tmp05[/i] [/b][code]@echo off
cd /d "%~dp0"
for /f "delims=" %%i in ('dir /b /a-d *.aac') do (
    ffmpeg -i "%%i" -acodec libmp3lame "temp.mp3"
    ffmpeg -i "temp.mp3" -f segment -segment_time 60 -c copy "%%~ni_%%03d.mp3"
)[/code]

tmp05 发表于 2022-5-23 16:20

[quote]回复  tmp05
[size=2][color=#999999]Batcher 发表于 2022-5-23 14:11[/color] [url=http://www.bathome.net/redirect.php?goto=findpost&pid=255978&ptid=62809][img]http://www.bathome.net/images/common/back.gif[/img][/url][/size][/quote]
每次还要确认下?能否再帮完善下,谢谢
[img]https://s1.ax1x.com/2022/05/23/Xpwya4.jpg[/img]

Batcher 发表于 2022-5-23 17:39

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=255987&ptid=62809]7#[/url] [i]tmp05[/i] [/b][code]@echo off
cd /d "%~dp0"
for /f "delims=" %%i in ('dir /b /a-d *.aac') do (
    ffmpeg -i "%%i" -acodec libmp3lame "temp.mp3" -y
    ffmpeg -i "temp.mp3" -f segment -segment_time 60 -c copy "%%~ni_%%03d.mp3"
)[/code]

tmp05 发表于 2022-5-24 13:51

[i=s] 本帖最后由 tmp05 于 2022-5-24 16:38 编辑 [/i]

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=255990&ptid=62809]8#[/url] [i]Batcher[/i] [/b]


    可以了,谢谢版主!另外,请问如何将每个文件三等分,而不是分成20分钟一个文件?要求有点多:loveliness:

tmp05 发表于 2022-5-27 10:01

请问如何将每个文件三等分?

tmp05 发表于 2022-5-29 07:28

有劳版主方便时帮改下语句,谢谢

flashercs 发表于 2022-5-29 19:52

[code]@echo off
setlocal enabledelayedexpansion
cd /d "%~dp0"
set splitCount=3
for /f "delims=" %%i in ('dir /b /a-d *.aac') do (
    ffmpeg -y -i "%%i" -acodec libmp3lame "temp.mp3"
    for /f "delims=" %%B in ('ffprobe -show_format -i "temp.mp3" 2^>nul^|findstr /lbic:"duration="') do (
    set %%B
  )
  set /a d=duration/splitCount+1
  ffmpeg -i "temp.mp3" -f segment -segment_time !d! -c copy "%%~ni_%%03d.mp3"
)
endlocal
[/code]

tmp05 发表于 2022-5-30 14:58

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256196&ptid=62809]12#[/url] [i]flashercs[/i] [/b]
执行了下,是这样的:
[img]https://s1.ax1x.com/2022/05/30/XljzZ9.jpg[/img]

flashercs 发表于 2022-5-30 15:16

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256232&ptid=62809]13#[/url] [i]tmp05[/i] [/b]


    下载ffprobe [url=http://bcn.bathome.net/tool/ffmpeg,4.3/ffprobe.exe]http://bcn.bathome.net/tool/ffmpeg,4.3/ffprobe.exe[/url]

Batcher 发表于 2022-5-30 15:51

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=256024&ptid=62809]9#[/url] [i]tmp05[/i] [/b][code]@echo off
cd /d "%~dp0"
setlocal enabledelayedexpansion

set "SplitCount=3"
for /f "delims=" %%i in ('dir /b /a-d *.aac') do (
    ffmpeg -i "%%i" -acodec libmp3lame "temp.mp3" -y
    for /f "tokens=2-4 delims=:. " %%a in ('ffmpeg -i "temp.mp3" 2^>^&1 ^| find "Duration:"') do (
        call :Time2SS %%a %%b %%c
    )
    set /a SegTime=SS/SplitCount+1
    ffmpeg -i "temp.mp3" -f segment -segment_time !SegTime! -c copy "%%~ni_%%03d.mp3"
)
goto :eof

:Time2SS
set /a HH=1%1-100
set /a MM=1%2-100
set /a SS=1%3-100
set /a HH2MM=HH*60
set /a MM+=HH2MM
set /a MM2SS=MM*60
set /a SS+=MM2SS
goto :eof[/code]

tmp05 发表于 2022-5-31 10:58

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256240&ptid=62809]15#[/url] [i]Batcher[/i] [/b]
是否将SplitCount=3改为SplitCount=4就是四等分?谢谢!

Batcher 发表于 2022-5-31 11:16

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=256281&ptid=62809]16#[/url] [i]tmp05[/i] [/b]


    请亲自尝试一下吧,如果有问题的话咱们再继续研究。

tmp05 发表于 2022-6-2 09:10

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=256283&ptid=62809]17#[/url] [i]Batcher[/i] [/b]
谢谢回复!

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.