Страница 1 из 1
Список ключевых кадров
Добавлено: 22 мар 2025, 20:19
ya
cmd
Код: Выделить всё
@echo off
set /p id="Enter Input file: "
echo %id%
echo " "
ffprobe -i %id%
echo " "
ffprobe -i %id% -select_streams v -skip_frame nokey -show_frames -show_entries frame=pkt_pts_time -sexagesimal -print_format flat > %id%_keyframes.txt
Параметр -print_format (или псевдоним -of) используется для изменения формата вывода. Доступные форматы: default, compact, csv, flat, ini, json, xml.
Формат вывода: flat
Код: Выделить всё
frames.frame.0.pkt_pts_time="0:00:00.000000"
frames.frame.1.pkt_pts_time="0:00:08.333333"
frames.frame.2.pkt_pts_time="0:00:16.666667"
Формат вывода: csv
Код: Выделить всё
frame,0:00:00.000000
frame,0:00:08.333333
frame,0:00:16.666667
Re: Список ключевых кадров
Добавлено: 22 мар 2025, 20:40
ya
cmd
Код: Выделить всё
@echo off
set /p id="Enter Input file: "
echo %id%
ffprobe -i %id% -select_streams v -skip_frame nokey -show_frames -show_entries frame=pkt_pts_time -sexagesimal -print_format csv > %id%_keyframes.txt
rem Создание файла с временными метками
(
for /f "tokens=1,2 delims=," %%a in (%id%_keyframes.txt) do (
echo %%b
)
) > %id%_formatted_keyframes.txt
rem Удаление оригинального файла с ключевыми кадрами
del %id%_keyframes.txt
rem Переименование отформатированного файла
ren %id%_formatted_keyframes.txt %id%_keyframes.txt
Результат:
Код: Выделить всё
0:00:00.000000
0:00:08.333333
0:00:16.666667
for /f "tokens=1,2 delims=," %%a in (%id%_keyframes.txt) — читает файл строка за строкой. tokens=1,2 указывает, что мы хотим разделить строки на два токена, разделенные запятой. %%a будет содержать часть строки до запятой (в данном случае "frame"), а %%b будет содержать временную метку.
Re: Список ключевых кадров
Добавлено: 22 мар 2025, 21:01
ya
добавим функцию, которая запрашивает у пользователя время в формате 0:00:00, а затем находит наибольшее значение, которое меньше введённого из ранее созданного текстового файла
cmd
Код: Выделить всё
@echo off
setlocal enabledelayedexpansion
set /p id="Enter Input file: "
echo %id%
echo " "
ffprobe -i %id%
echo " "
ffprobe -i %id% -select_streams v -skip_frame nokey -show_frames -show_entries frame=pkt_pts_time -sexagesimal -print_format csv > %id%_keyframes.txt
rem Создание файла с временными метками
(
for /f "tokens=1,2 delims=," %%a in (%id%_keyframes.txt) do (
echo %%b
)
) > %id%_formatted_keyframes.txt
echo "Formatted keyframes output saved to %id%_formatted_keyframes.txt"
rem Удаление оригинального файла с ключевыми кадрами
del %id%_keyframes.txt
rem Переименование отформатированного файла
ren %id%_formatted_keyframes.txt %id%_keyframes.txt
echo "Original keyframes file deleted and formatted file renamed to %id%_keyframes.txt"
rem Запрос пользовательского ввода
set /p search_time="Enter the desired time in format 0:00:00: "
rem Инициализация переменной для хранения наибольшего значения
set max_time=0:00:00.000000
rem Поиск наибольшего значения, которое меньше введенного
for /f "delims=" %%t in (%id%_keyframes.txt) do (
set "current_time=%%t"
rem Сравнение временных значений
if "%%t" lss "%search_time%" (
rem Сравнение с максимальным значением
if "!current_time!" gtr "!max_time!" (
set "max_time=!current_time!"
)
)
)
rem Вывод результата
if "!max_time!" neq "0:00:00.000000" (
echo The largest time less than %search_time% is !max_time!
) else (
echo No time found less than %search_time%.
)
endlocal
Re: Список ключевых кадров
Добавлено: 22 мар 2025, 21:42
ya
разрешим пользователю вводить в формате 0:0:0
cmd
Код: Выделить всё
@echo off
setlocal enabledelayedexpansion
set /p id="Enter Input file: "
ffprobe -i %id% -select_streams v -skip_frame nokey -show_frames -show_entries frame=pkt_pts_time -sexagesimal -print_format csv > %id%_keyframes.txt
rem Создание файла с временными метками
(
for /f "tokens=1,2 delims=," %%a in (%id%_keyframes.txt) do (
echo %%b
)
) > %id%_formatted_keyframes.txt
rem Удаление оригинального файла с ключевыми кадрами
del %id%_keyframes.txt
rem Переименование отформатированного файла
ren %id%_formatted_keyframes.txt %id%_keyframes.txt
rem Запрос пользовательского ввода
set /p search_time="Enter the desired time in format 0:0:0: "
rem Преобразование времени в формат 0:00:00
for /f "tokens=1,2,3 delims=:" %%h in ("%search_time%") do (
set "hours=%%h"
set "minutes=0%%i"
set "seconds=0%%j"
)
set "formatted_search_time=!hours:~-2!:!minutes:~-2!:!seconds:~-2!"
rem Инициализация переменной для хранения наибольшего значения
set max_time=0:00:00.000000
rem Поиск наибольшего значения, которое меньше введенного
for /f "delims=" %%t in (%id%_keyframes.txt) do (
set "current_time=%%t"
rem Сравнение временных значений
if "%%t" lss "!formatted_search_time!" (
rem Сравнение с максимальным значением
if "!current_time!" gtr "!max_time!" (
set "max_time=!current_time!"
)
)
)
rem Вывод результата
if "!max_time!" neq "0:00:00.000000" (
echo The largest time less than !formatted_search_time! is !max_time!
) else (
echo No time found less than !formatted_search_time!.
)
endlocal