透過Copilot 產生 FFMPEG影片分段的BAT[Generate BAT of FFMPEG video segments through Copilot]
透過Copilot 產生 FFMPEG影片分段的BAT[Generate BAT of FFMPEG video segments through Copilot]
問題內容:
假設有一影片檔案名稱為 videoplayback.mp4 該影片長度預設為60分鐘
我想要透過FFMPEG 將當以每2分鐘 且檔案主檔名長度為4
請產生對應的BAT命令檔案給我
影片來源: https://www.youtube.com/watch?v=gCUjHOw1-KA [印度偷電有多瘋狂,連警察都攔不住,電力公司虧的底朝天|免費紀錄片|短紀錄片]
影片下載: https://www.ssyoutube.com/watch?v=gCUjHOw1-KA
BAT
@echo off setlocal enabledelayedexpansion REM 設定輸出檔案名稱的格式 set "filename=0001" set "extension=mp4" REM 設定每個分割檔案的長度(以秒為單位) set /a "segment_length=2*60" REM 設定起始時間為0 set /a "start_time=0" REM 設定總影片長度(以秒為單位) set /a "total_length=8*60+8" REM 使用迴圈來分割影片 :loop if !start_time! geq !total_length! ( echo 完成影片分割。 goto :eof ) REM 計算下一個檔案的起始時間 set /a "next_start_time=!start_time!+!segment_length!" REM 執行FFMPEG命令來分割影片 ffmpeg -i videoplayback.mp4 -ss !start_time! -t !segment_length! -c copy !filename!.!extension! REM 更新檔案名稱為下一個序號 set /a "filename_num=1%filename% + 1" set "filename=!filename_num:~1!" REM 更新起始時間為下一個分段的起始時間 set /a "start_time=!next_start_time!" goto loop
HTML影片撥放語法
<HTML> <BODY> <p> <video id="player" width="400" height="300" controls="" style="background:black;" src="https://github.com/jash-git/Generate-BAT-of-FFMPEG-video-segments-through-Copilot/raw/main/0001.mp4?raw=true"> </video> <br> <script> var player = document.getElementById('player') var string1="https://github.com/jash-git/Generate-BAT-of-FFMPEG-video-segments-through-Copilot/raw/main/" var string2="?raw=true" var playlist = [ "0001.mp4", "0002.mp4", "0003.mp4", "0004.mp4", "0005.mp4", ] var activeVideo = 0 var fileurl = string1 + playlist[activeVideo]+ string2 player.src = fileurl player.addEventListener('ended', function(e) { // update the new active video index activeVideo = (++activeVideo) % playlist.length var string1="https://github.com/jash-git/Generate-BAT-of-FFMPEG-video-segments-through-Copilot/raw/main/" var string2="?raw=true" var fileurl = string1 + playlist[activeVideo]+ string2 player.src = fileurl player.play() }) </script> <br> </p> </BODY> </HTML>
心得:
印度偷電駭客(黑客) 證明古人說的家財萬貫不如一技在身
黑客賺錢又一經典案例
6 thoughts on “透過Copilot 產生 FFMPEG影片分段的BAT[Generate BAT of FFMPEG video segments through Copilot]”
對應 GITHUB:
https://github.com/jash-git/Generate-BAT-of-FFMPEG-video-segments-through-Copilot
BAT/CMD
Do While 迴圈
GOTO
變數宣告
變數與字串組合
假設有一影片檔案名稱為 videoplayback.mp4 該影片長度預設為60分鐘
我想要透過FFMPEG 將當以每2分鐘 且檔案主檔名長度為4
請產生對應的LINUX SHELL命令檔案給我
#!/bin/bash
# Set input video file name
input_file="videoplayback.mp4"
# Set segment duration in seconds
segment_duration=120
# Set output file name pattern
output_file_pattern="part%04d.mp4"
# Calculate total number of segments
total_segments=$(($((60 * 60) / segment_duration)))
# Split the video into segments
for i in $(seq 0 $((total_segments - 1))); do
start_time=$((i * segment_duration))
output_file=$(printf "$output_file_pattern" $i)
ffmpeg -i "$input_file" -ss $start_time -t $segment_duration -c copy "$output_file"
done
強的怕狠的 狠的怕無天良的 無天良的怕神經不正常
強怕狠 狠怕沒天良 沒天良的怕神經不正常
假設有一影片檔案名稱為 videoplayback.mp4 該影片長度預設為60分鐘
我想要透過FFMPEG 將當以每2分鐘 且檔案主檔名長度為4
請產生對應的python命令檔案給我
import subprocess
# Set input video file name
input_file = "videoplayback.mp4"
# Set segment duration in seconds
segment_duration = 120
# Set output file name pattern
output_file_pattern = "part%04d.mp4"
# Calculate total number of segments
total_segments = int(60 * 60 / segment_duration)
# Split the video into segments
for i in range(total_segments):
start_time = i * segment_duration
output_file = output_file_pattern % (i + 1)
command = ["ffmpeg", "-i", input_file, "-ss", f"{start_time}", "-t", f"{segment_duration}", "-c", "copy", output_file]
subprocess.call(command)
假設有一影片檔案名稱為 videoplayback.mp4 該影片長度預設為60分鐘
我想要透過FFMPEG 將當以每2分鐘 且檔案主檔名長度為4
請產生對應的php命令檔案給我
<?php
// Set input video file name
$inputFile = 'videoplayback.mp4';
// Set segment duration in seconds
$segmentDuration = 120;
// Set output file name pattern
$outputFilePattern = 'part%04d.mp4';
// Calculate total number of segments
$totalSegments = intdiv(60 * 60, $segmentDuration);
// Split the video into segments
for ($i = 0; $i