[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] ffmpeg分割如何强制插入关键帧

视频关键帧缺少,如果片段小,切割视频后会一片漆黑只有声音,
用ffmpeg分割,安时间段提取视频,但是会出现不一样的结果,不知道哪里问题
比如下面,想提取每一秒的视频,但是变成开头部分到每一秒的视频
  1. @echo off & setlocal enabledelayedexpansion
  2. title ffmpeg间隔1秒分割视频
  3. for %%i in (*.avi *.mkv *.mp4 *.flv) do (md "%%~ni"
  4.     for /f "tokens=2-5delims=:., " %%a in ('ffmpeg -i "%%i" 2^>^&1 ^| find "Duration:"') do (
  5.     set /a t=%%a*3600+%%b*60+%%c
  6.     echo 视频长度!t!秒,将分割!t!个文件
  7. pause
  8.     for /l %%j in (1 1 !t!) do (set T=%%j&set/a TT=!T!-1
  9.         set /a hh=!TT!/3600
  10.         set /a mm=!TT!%%3600/60
  11.         set /a ss=!TT!%%60
  12.         set hh=00!h!
  13.         set mm=00!m!
  14.         set ss=00!s!
  15.         set /a h=!T!/3600
  16.         set /a m=!T!%%3600/60
  17.         set /a s=!T!%%60
  18.         set h=00!h!
  19.         set m=00!m!
  20.         set s=00!s!
  21.     ffmpeg -ss !hh:~-2!:!mm:~-2!:!ss:~-2!.000 -t !h:~-2!:!m:~-2!:!s:~-2!.000 -accurate_seek -i "%%i"  -codec copy  -avoid_negative_ts 1 "%~dp0%%~ni\!t!%%~xi"
  22.         )
  23.     )
  24. )
  25. pause
复制代码
链接:https://pan.xunlei.com/s/VMXoikqkVYJldEFdNZ-GSk52A1
提取码:bf3e

有没有办法直接在视频上设置关键帧?比如每个片段大于120帧就平均分割,在1秒处强制设置一个关键帧,或外部导入一张透明的PNG作为关键帧

  1. ffmpeg -ss 00:00:00.000 -t 00:00:01.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\1.mp4"
  2. ffmpeg -ss 00:00:01.000 -t 00:00:02.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\2.mp4"
  3. ffmpeg -ss 00:00:02.000 -t 00:00:03.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\3.mp4"
  4. ffmpeg -ss 00:00:03.000 -t 00:00:04.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\4.mp4"
  5. ffmpeg -ss 00:00:04.000 -t 00:00:05.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\5.mp4"
  6. ffmpeg -ss 00:00:05.000 -t 00:00:06.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\6.mp4"
  7. ffmpeg -ss 00:00:06.000 -t 00:00:07.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\7.mp4"
  8. ffmpeg -ss 00:00:07.000 -t 00:00:08.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\8.mp4"
  9. ffmpeg -ss 00:00:08.000 -t 00:00:09.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\9.mp4"
  10. ffmpeg -ss 00:00:09.000 -t 00:00:10.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\10.mp4"
  11. ffmpeg -ss 00:00:10.000 -t 00:00:11.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\11.mp4"
  12. ffmpeg -ss 00:00:11.000 -t 00:00:12.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\12.mp4"
  13. ffmpeg -ss 00:00:12.000 -t 00:00:13.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\13.mp4"
  14. ffmpeg -ss 00:00:13.000 -t 00:00:14.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\14.mp4"
  15. ffmpeg -ss 00:00:14.000 -t 00:00:15.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\15.mp4"
  16. ffmpeg -ss 00:00:15.000 -t 00:00:16.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\16.mp4"
  17. ffmpeg -ss 00:00:16.000 -t 00:00:17.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\17.mp4"
  18. ffmpeg -ss 00:00:17.000 -t 00:00:18.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\18.mp4"
  19. ffmpeg -ss 00:00:18.000 -t 00:00:19.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\19.mp4"
  20. ffmpeg -ss 00:00:19.000 -t 00:00:20.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\20.mp4"
  21. ffmpeg -ss 00:00:20.000 -t 00:00:21.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\21.mp4"
  22. ffmpeg -ss 00:00:21.000 -t 00:00:22.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\22.mp4"
  23. ffmpeg -ss 00:00:22.000 -t 00:00:23.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\23.mp4"
  24. ffmpeg -ss 00:00:23.000 -t 00:00:24.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\24.mp4"
  25. ffmpeg -ss 00:00:24.000 -t 00:00:25.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\25.mp4"
  26. ffmpeg -ss 00:00:25.000 -t 00:00:26.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\26.mp4"
  27. ffmpeg -ss 00:00:26.000 -t 00:00:27.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\27.mp4"
  28. ffmpeg -ss 00:00:27.000 -t 00:00:28.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\28.mp4"
  29. ffmpeg -ss 00:00:28.000 -t 00:00:29.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\29.mp4"
  30. ffmpeg -ss 00:00:29.000 -t 00:00:30.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\30.mp4"
  31. ffmpeg -ss 00:00:30.000 -t 00:00:31.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\31.mp4"
  32. ffmpeg -ss 00:00:31.000 -t 00:00:32.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\32.mp4"
  33. ffmpeg -ss 00:00:32.000 -t 00:00:33.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\33.mp4"
  34. ffmpeg -ss 00:00:33.000 -t 00:00:34.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\34.mp4"
  35. ffmpeg -ss 00:00:34.000 -t 00:00:35.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\35.mp4"
  36. ffmpeg -ss 00:00:35.000 -t 00:00:36.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\36.mp4"
  37. ffmpeg -ss 00:00:36.000 -t 00:00:37.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\37.mp4"
  38. ffmpeg -ss 00:00:37.000 -t 00:00:38.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\38.mp4"
  39. ffmpeg -ss 00:00:38.000 -t 00:00:39.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\39.mp4"
  40. ffmpeg -ss 00:00:39.000 -t 00:00:40.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\40.mp4"
  41. ffmpeg -ss 00:00:40.000 -t 00:00:41.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\41.mp4"
  42. ffmpeg -ss 00:00:41.000 -t 00:00:42.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\42.mp4"
  43. ffmpeg -ss 00:00:42.000 -t 00:00:43.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\43.mp4"
  44. ffmpeg -ss 00:00:43.000 -t 00:00:44.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\44.mp4"
  45. ffmpeg -ss 00:00:44.000 -t 00:00:45.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\45.mp4"
  46. ffmpeg -ss 00:00:45.000 -t 00:00:46.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\46.mp4"
  47. ffmpeg -ss 00:00:46.000 -t 00:00:47.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\47.mp4"
  48. ffmpeg -ss 00:00:47.000 -t 00:00:48.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\48.mp4"
  49. ffmpeg -ss 00:00:48.000 -t 00:00:49.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\49.mp4"
  50. ffmpeg -ss 00:00:49.000 -t 00:00:50.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\50.mp4"
  51. ffmpeg -ss 00:00:50.000 -t 00:00:51.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\51.mp4"
  52. ffmpeg -ss 00:00:51.000 -t 00:00:52.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\52.mp4"
  53. ffmpeg -ss 00:00:52.000 -t 00:00:53.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\53.mp4"
  54. ffmpeg -ss 00:00:53.000 -t 00:00:54.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\54.mp4"
  55. ffmpeg -ss 00:00:54.000 -t 00:00:55.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\55.mp4"
  56. ffmpeg -ss 00:00:55.000 -t 00:00:56.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\56.mp4"
  57. ffmpeg -ss 00:00:56.000 -t 00:00:57.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\57.mp4"
  58. ffmpeg -ss 00:00:57.000 -t 00:00:58.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\58.mp4"
  59. ffmpeg -ss 00:00:58.000 -t 00:00:59.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\59.mp4"
  60. ffmpeg -ss 00:00:59.000 -t 00:01:00.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\60.mp4"
  61. ffmpeg -ss 00:01:00.000 -t 00:01:01.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\61.mp4"
  62. ffmpeg -ss 00:01:01.000 -t 00:01:02.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\62.mp4"
  63. ffmpeg -ss 00:01:02.000 -t 00:01:03.000 -accurate_seek -i "南极之恋.mp4" -codec copy -avoid_negative_ts 1 "D:\搞笑视频\南极之恋\63.mp4"
复制代码
全部内容是这样的,比如最后一行提取00:01:02.000 到 00:01:03.000之间的视频,也是1秒,但是变成一分多钟,其他也一样

TOP

本帖最后由 nwm310 于 2021-4-10 09:20 编辑

-t  長度
-to 終點

獲得每個關鍵幀的時間
  1. ffprobe.exe  -v error  -select_streams v -show_entries "frame=key_frame,pkt_pts_time" -of  csv   -sexagesimal  a.mp4   | find "frame,1,"
复制代码
獲得 1:23 (1分23秒) 附近的關鍵幀時間
cmd窗口  1:23%+#1
bat    1:23%%+#1
  1. ffprobe.exe  -v error  -select_streams v -show_entries "frame=pkt_pts_time" -of  csv   -sexagesimal  -read_intervals   1:23%+#1   a.mp4
复制代码
1

评分人数

TOP

原来这样,没关键帧还是不能分割,插入关键帧又重新编码,大了不少

TOP

返回列表