Memo Can
Memo Can

Reputation: 81

FFmpeg batch script

I have this batch script running perfectly on Windows:

C:\ffmpeg\bin\ffmpeg -i http://ipaddress/stream -deinterlace -c:v libx264 -pix_fmt yuv420p -s 960x540 -preset superfast -vb 1200k -maxrate 1200k -r 30 -g 60 -bufsize 8000k  -c:a aac -b:a 64k -ar 44100 -ac 2 -f flv rtmp://ipaddress/live/

Sometimes ffmpeg crashes, how can I edit the batch script or what can i add to the batch file to restart the stream.

Thanks advance!

Upvotes: 2

Views: 1700

Answers (2)

@echo off
setlocal enabledelayedexpansion

REM Set the folder path containing the videos
set "input_folder=."
set "ffmpeg_path=C:\ffmpeg\bin\ffmpeg.exe"
REM Set the output folder path for the processed videos
set "output_folder=.\output"

REM Set the desired speed and volume adjustment
set "speed=0.2"
set "volume=0.2"

REM Create the output folder if it doesn't exist
if not exist "%output_folder%" mkdir "%output_folder%"

REM Loop through all video files in the input folder
for %%i in ("%input_folder%\*.mp4") do (
    REM Create the output file path with the same filename in the output folder
    set "output_file=%output_folder%\%%~nxi"

    REM Apply the speed and volume adjustments using FFmpeg
    %ffmpeg_path% -i "%%i" -vf "setpts=!speed!*PTS" -af "volume=!volume!" "!output_file!"
)

echo All videos processed successfully.
pause

Upvotes: 0

user6811411
user6811411

Reputation:

I don't know if the ffmpeg command can be restarted this way,
but I would limit the number of retries to avoid endless loops on fails:

@Echo off
Setlocal EnableDelayedExpansion
Set Retry=0
:loop
C:\ffmpeg\bin\ffmpeg.exe -i http://ipaddress/stream ^
  -deinterlace -c:v libx264 -pix_fmt yuv420p -s 960x540 -preset superfast ^
  -vb 1200k -maxrate 1200k -r 30 -g 60 -bufsize 8000k -c:a aac -b:a 64k ^
  -ar 44100 -ac 2 -f flv rtmp://ipaddress/live/ ^
  ||(Set /A "Retry+=1"&if !Retry! leq 3 Goto :loop)

Upvotes: 1

Related Questions