分割成相同的部分,并使用ffmpeg转换许多mp4视频 [英] Split into equal parts and convert many mp4 videos using ffmpeg

查看:241
本文介绍了分割成相同的部分,并使用ffmpeg转换许多mp4视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一吨视频,我需要使用ffmpeg从mp4转换为wmv,并将每个文件分解成10分钟,但我是一个完整的cmd脚本newb(实际上,我是一个脚本newb:)



花了6个小时试图找到答案后,我以为我会把它带给你们。



我的代码正在工作一点,但是我需要能够读取来自命令行的数据并将其发送回脚本进行评估。我不知道ffmpeg在处理视频文件时(当时间戳到底)时会吐出什么代码,但是这个FOR循环只是继续尝试创建新的文件段,即使视频结束了。这是我试图创建一个新文件时看到的,所以我认为可能会搜索这个:



frame = 0 fps = 0.0 q = 0.0 Lsize = 1kB时间= 00:00:00.00比特率= N / A



这是迄今为止已经提出的代码(不要笑:)

  @echo off 
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION

for %% a in * .mp4)do(
set hour = 00

for / L %% i IN(1,1,10)do(
:Beginning
set / a start = %% i-1
set end = %% i
if!start!lss 10 set start =!start!0
if!end!lss 10 set end = !end!0
ffmpeg -ss!hour!:!start!:00 -i%% a-b:v 1500k -vcodec msmpeg4 -acodec wmav2 -t!hour!:!end!:00转换\ %%〜na-!hour! - !start! - !end!.wmv
if end == 60 CALL:Increment



:递增
set / a!hour!+1
set %% i = 1
GOTO:开始
暂停
/ pre>

根据读取此主题正在考虑像这样可能会进入代码,但不知道该怎么做:

 设置dosstring =%*

echo!!dosstring!| findstr / C:frame = 0 fps = 0.0 q = 0.0 Lsize = 1kB time = 00:00:00.00 bitrate = N / A> nul 2>& 1

非常感谢您的帮助!

解决方案

一个更有效的方法是每个文件调用 ffmpeg ,并使用它的细分功能



细分将依次编号,如果你绝对需要在名称中包含时间戳,我们还将生成CSV格式的片段时间戳列表:

  tmp000.wmv, 0.000000,60.281000 
tmp001.wmv,60.281000,120.041000

然后解析它并重命名段。

  
-segment_time 10:00 -segment_list tmp.csv -reset_timestamps 1 ^
-b:v 1500k -vcodec msmpeg4 -acodec wmav2 converted\tmp %% 03d.wmv

setlocal enableDelayedExpansion
for / fdelims =,tokens = 1-3%% b in(tmp.csv)do(
set sec = %% c&设置秒=!秒:。* =!
set / a hour =sec / 3600
set / a mins1 =sec / 60 %% 60&设置mins1 = 0!mins1!
set sec = %% d&设置秒=!秒:。* =!
set / a mins2 =sec / 60 %% 60&设置mins2 = 0!mins2!

renconverted\ %% b%%〜na-!hour! - !mins1:〜-2! - !mins2:〜-2!*

endlocal
del tmp.csv

暂停

这个例子不会重命名名称中的的文件,因为我不想过度复制代码来解决这个问题。


I have a ton of videos I need to convert from mp4 to wmv using ffmpeg and break up each file into 10 minute segments, but I am a total cmd scripting newb (in fact, I am a scripting newb :)

After spending six hours trying to find an answer, I thought I would bring it to you guys.

The code I have is working a little bit, but I need to be able to read data coming from the command line and send it back into the script for evaluation. I am not sure what code ffmpeg will spit out when it is done processing a video file (when the timestamp reaches an end), but this FOR loop just keeps on trying to create new file segments even though the video is over. This is what I saw when it tried to create a new file, so I think it might work to search for this:

frame= 0 fps=0.0 q=0.0 Lsize= 1kB time=00:00:00.00 bitrate=N/A

This is the code I have come up with so far (Don't laugh :)

@echo off
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION

for %%a in ("*.mp4") do (
set hour=00

for /L %%i IN (1,1,10) do (
:Beginning
    set /a start=%%i-1
        set end=%%i
        if !start! lss 10 set start=!start!0
        if !end! lss 10 set end=!end!0
        ffmpeg -ss !hour!:!start!:00 -i "%%a" -b:v 1500k -vcodec msmpeg4 -acodec wmav2 -t !hour!:!end!:00 "Converted\%%~na-!hour!-!start!-!end!.wmv"
        if end==60 CALL :Increment
    )   
)

:Increment
    set /a !hour!+1
    set %%i=1
    GOTO :Beginning
pause

Based on reading this thread was thinking something like this might go in the code, but not sure what to do with it:

set "dosstring=%*"

echo.!dosstring!|findstr /C:"frame=    0 fps=0.0 q=0.0 Lsize=       1kB time=00:00:00.00 bitrate=N/A" >nul 2>&1

Thanks so much for you help!

解决方案

A more efficient method is to invoke ffmpeg just once per file and use its segmenting feature.

The segments will be numbered sequentially so if you absolutely need to include timestamps in the name we'll also generate a list of the segment's timestamps in CSV format:

tmp000.wmv,0.000000,60.281000
tmp001.wmv,60.281000,120.041000

Then parse it and rename the segments.

@echo off

for %%a in (*.mp4) do (

    ffmpeg -i "%%a" ^
        -f segment -segment_time 10:00 -segment_list tmp.csv -reset_timestamps 1 ^
        -b:v 1500k -vcodec msmpeg4 -acodec wmav2 converted\tmp%%03d.wmv

    setlocal enableDelayedExpansion
    for /f "delims=, tokens=1-3" %%b in (tmp.csv) do (
        set sec=%%c & set sec=!sec:.*=!
        set /a hour="sec / 3600"
        set /a mins1="sec / 60 %% 60" & set mins1=0!mins1!
        set sec=%%d & set sec=!sec:.*=!
        set /a mins2="sec / 60 %% 60" & set mins2=0!mins2!

        ren "converted\%%b" "%%~na-!hour!-!mins1:~-2!-!mins2:~-2!.*"
    )
    endlocal
    del tmp.csv
)
pause

This example won't rename files with ! in the name as I didn't want to overcomplicate the code to work around this case.

这篇关于分割成相同的部分,并使用ffmpeg转换许多mp4视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆