南棱笑笑生头像
20261120使用ffmpeg截取mp4视频的开头部分封面图

20261120使用ffmpeg截取mp4视频的开头部分

ffmpeg -i E:\20261120的OPPO_Find_X6_Pro\videoplayback.360p.mp4  -t 00:59:55 -c copy -avoid_negative_ts 1 output.mp4


✅ 方法一:改用 -t 指定保留时长(最推荐)
你已经知道视频总时长(01:26:54.62),要保留到 01:12:13,则保留时长为 01:12:13(从开头算起)。
使用 -t 而非 -to,可以避免一些时间戳解析问题:

bash
ffmpeg -i "Screenrecorder-2026-07-18-16-11-33-355解锁太阳观测与摄影_KV-凯文【最后拿掉】.mp4" -t 01:12:13 -c copy -avoid_negative_ts 1 output.mp4
-t 01:12:13:表示从输入开头起截取 1小时12分13秒 的内容。

-avoid_negative_ts 1:强制将负时间戳归零,避免 muxer 报错。


20261120使用ffmpeg截取mp4视频的开头部分
2026/11/20 17:15


DeepSeek:ffmpeg拿掉最后的部分?命令?


Microsoft Windows [版本 10.0.19045.6466]
(c) Microsoft Corporation。保留所有权利。

C:\Users\QQQ>cd E:\20261120的OPPO_Find_X6_Pro

C:\Users\QQQ>e:

E:\20261120的OPPO_Find_X6_Pro>dir
 驱动器 E 中的卷是 4TB
 卷的序列号是 12FC-B918

 E:\20261120的OPPO_Find_X6_Pro 的目录

2026/11/20  17:11    <DIR>          .
2026/11/20  17:11    <DIR>          ..
2026/01/03  00:02         3,973,448 IMG20260103000205.jpg
2026/01/03  00:02         3,667,361 IMG20260103000219.jpg
2026/11/20  15:15    <DIR>          Screenshots
2026/11/17  16:48       531,803,255 VID20261117_164737在深圳湾公园看鸭子.mp4
2026/11/20  13:14       185,629,496 videoplayback.360p.mp4
2026/11/20  13:20     7,493,730,700 videoplayback.webm
               5 个文件  8,218,804,260 字节
               3 个目录 149,860,704,256 可用字节

E:\20261120的OPPO_Find_X6_Pro>ffmpeg -i E:\20261120的OPPO_Find_X6_Pro\videoplayback.360p.mp4  -t 00:59:55 -c copy -avoid_negative_ts 1 output.mp4
ffmpeg version 2025-01-22-git-e20ee9f9ae-essentials_build-www.gyan.dev Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 14.2.0 (Rev1, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      59. 55.100 / 59. 55.100
  libavcodec     61. 31.101 / 61. 31.101
  libavformat    61.  9.106 / 61.  9.106
  libavdevice    61.  4.100 / 61.  4.100
  libavfilter    10.  6.101 / 10.  6.101
  libswscale      8. 13.100 /  8. 13.100
  libswresample   5.  4.100 /  5.  4.100
  libpostproc    58.  4.100 / 58.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'E:\20261120的OPPO_Find_X6_Pro\videoplayback.360p.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2026-11-20T04:13:08.000000Z
    encoder         : Google
  Duration: 01:00:43.30, start: 0.000000, bitrate: 407 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 640x360 [SAR 1:1 DAR 16:9], 356 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      creation_time   : 2026-11-20T04:13:08.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 11/19/2026.
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](eng): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 48 kb/s (default)
    Metadata:
      creation_time   : 2026-11-20T04:13:08.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 11/19/2026.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf61.9.106
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 356 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      creation_time   : 2026-11-20T04:13:08.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 11/19/2026.
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 48 kb/s (default)
    Metadata:
      creation_time   : 2026-11-20T04:13:08.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 11/19/2026.
      vendor_id       : [0][0][0][0]
Press [q] to stop, [?] for help
[out#0/mp4 @ 000001a49b4c8780] video:156436KiB audio:21065KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 1.390565%
frame=107851 fps=61946 q=-1.0 Lsize=  179969KiB time=00:59:55.06 bitrate= 410.1kbits/s speed=2.06e+03x

E:\20261120的OPPO_Find_X6_Pro>


ffmpeg拿掉最后的部分?命令?
用户想知道如何使用ffmpeg移除视频文件的后半部分。我需要提供相应的命令。为了全面获取信息,我将同时进行多项搜索,涵盖不同关键词和可能的命令选项。

搜索到 29 个网页
搜索结果显示了一些相关页面。为了全面获取信息,我需要同时打开这些页面。

浏览 4 个页面
How to Trim and Cut Video with FFmpeg: Timestamps, Duration, Split (2026 Guide) - WaveSpeed Blog
如何使用FFmpeg剪切和裁剪视频:时间戳、时长与分割(2026年指南) - WaveSpeed Blog
How to Trim Videos using FFmpeg
How to Trim Video Using FFmpeg and Its Best Alternative
这些资料提供了多种方法。我的回答将涵盖几种方法:使用 -t 参数、使用 -sseof 参数,以及使用 -to 参数。我还会提到 -c copy 选项。我的回答将用中文呈现,并会注明引用来源。

你可以使用 ffmpeg 的 -t 或 -sseof 参数来移除视频的末尾部分,两者的用法有所不同。

方法一:使用 -t 参数 (需要知道视频总时长)
这是最常用的方法,你需要先知道视频的总时长,然后用 -t 指定你想保留的前面部分的时长。

命令格式:ffmpeg -i input.mp4 -t [保留时长] -c copy output.mp4

命令示例:例如,要删除一个5分钟视频的最后30秒,只需保留前4分30秒:

bash
ffmpeg -i input.mp4 -t 00:04:30 -c copy output.mp4
这条命令的意思是:从视频开头开始,截取时长为 00:04:30(4分30秒)的内容作为输出。-c copy 参数可以实现快速剪切且不损失画质。

方法二:使用 -sseof 参数 (无需知道总时长)
这个方法更直接,可以让你从视频末尾开始计算并移除,无需事先知道视频总时长。

命令格式:ffmpeg -sseof -[移除时长] -i input.mp4 -c copy output.mp4

命令示例:例如,要删除视频末尾的30秒:

bash
ffmpeg -sseof -30 -i input.mp4 -c copy output.mp4
这条命令的意思是:从文件末尾(-sseof)往回倒推30秒(-30)的位置开始,截取到文件末尾。注意,-sseof 的值必须是负数。

方法三:使用 -to 参数 (需要知道结束时间点)
这个方法和方法一类似,但用的是 -to 来指定输出的结束时间点。

命令格式:ffmpeg -i input.mp4 -to [结束时间点] -c copy output.mp4

命令示例:例如,要保留一个视频从开头到4分30秒的部分:

bash
ffmpeg -i input.mp4 -to 00:04:30 -c copy output.mp4
这条命令的意思是:从视频开头开始,截取到 00:04:30 这个时间点为止。

补充说明
-c copy:这个参数能实现快速剪切且不损失画质,但剪切点可能不是100%精确,它会停在离指定时间最近的关键帧上。如果需要精确到帧的剪切,可以移除 -c copy 让FFmpeg重新编码,但这会耗费更多时间并可能轻微影响画质。

时间格式:时间可以用 HH:MM:SS(时:分:秒)或直接用秒数(如 -t 270 表示270秒)来表示。

使用方法3,异常了、

Microsoft Windows [版本 10.0.19045.6466]
(c) Microsoft Corporation。保留所有权利。

C:\Users\QQQ>cd E:\20260722红米Note12Pro

C:\Users\QQQ>e:

E:\20260722红米Note12Pro>dir
 驱动器 E 中的卷是 14TB581
 卷的序列号是 7C51-A42F

 E:\20260722红米Note12Pro 的目录

2026/07/25  11:36    <DIR>          .
2026/07/25  11:36    <DIR>          ..
2026/07/23  00:50    <DIR>          Camera
2026/07/23  00:49    <DIR>          ScreenRecorder
2026/07/07  11:43         4,551,582 Screenrecorder-2026-07-07-11-43-23-297鄂尔多斯.mp4
2026/07/08  11:19        80,126,306 Screenrecorder-2026-07-08-11-18-58-26.mp4
2026/07/08  20:42            36,186 Screenrecorder-2026-07-08-20-42-00-384.mp4
2026/07/08  20:42        10,688,455 Screenrecorder-2026-07-08-20-42-10-105.mp4
2026/07/08  22:50    13,619,587,504 Screenrecorder-2026-07-08-20-42-24-656深空摄影.mp4
2026/07/18  16:11        87,092,176 Screenrecorder-2026-07-18-16-10-38-935.mp4
2026/07/18  17:38     9,578,685,811 Screenrecorder-2026-07-18-16-11-33-355解锁太阳观测与摄影_KV-凯文【最后拿掉】.mp4
2026/07/18  20:53     2,783,872,833 Screenrecorder-2026-07-18-19-51-54-941人文讲坛:经典艺术永流传-AI时代华君武漫画传承 与创新-人文讲坛第304期-深圳图书馆【片段】.mp4
2026/07/18  21:03       592,223,055 Screenrecorder-2026-07-18-20-58-31-572生活中的化学-了解食用油-中国科普博览【片段】.mp4
2026/07/23  00:51    <DIR>          Screenshots
               9 个文件 26,756,863,908 字节
               5 个目录 88,033,964,032 可用字节

E:\20260722红米Note12Pro>ffmpeg -i E:\20260722红米Note12Pro\Screenrecorder-2026-07-18-16-11-33-355解锁太阳观测与摄影_KV-凯文【最后拿掉】.mp4   -to 01:12:13 -c copy output.mp4
ffmpeg version 2025-01-22-git-e20ee9f9ae-essentials_build-www.gyan.dev Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 14.2.0 (Rev1, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      59. 55.100 / 59. 55.100
  libavcodec     61. 31.101 / 61. 31.101
  libavformat    61.  9.106 / 61.  9.106
  libavdevice    61.  4.100 / 61.  4.100
  libavfilter    10.  6.101 / 10.  6.101
  libswscale      8. 13.100 /  8. 13.100
  libswresample   5.  4.100 /  5.  4.100
  libpostproc    58.  4.100 / 58.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'E:\20260722红米Note12Pro\Screenrecorder-2026-07-18-16-11-33-355解锁太阳观测与摄影_KV-凯文【最后拿掉】.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2026-07-18T09:38:28.000000Z
    com.android.version: 13
  Duration: 01:26:54.62, start: 0.000000, bitrate: 14695 kb/s
  Stream #0:0[0x1](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 287 kb/s (default)
    Metadata:
      creation_time   : 2026-07-18T09:38:28.000000Z
      handler_name    : SoundHandle
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 2400x1080, 14404 kb/s, 24.25 fps, 24.17 tbr, 90k tbn (default)
    Metadata:
      creation_time   : 2026-07-18T09:38:28.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    com.android.version: 13
    encoder         : Lavf61.9.106
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 2400x1080, q=2-31, 14404 kb/s, 24.25 fps, 24.17 tbr, 90k tbn (default)
    Metadata:
      creation_time   : 2026-07-18T09:38:28.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 287 kb/s (default)
    Metadata:
      creation_time   : 2026-07-18T09:38:28.000000Z
      handler_name    : SoundHandle
      vendor_id       : [0][0][0][0]
Press [q] to stop, [?] for help
[aost#0:1/copy @ 000001bba2ae00c0] Error submitting a packet to the muxer: Invalid argument 23x
    Last message repeated 1 times
[out#0/mp4 @ 000001bba0ce0800] Error muxing a packet
[out#0/mp4 @ 000001bba0ce0800] Task finished with error code: -22 (Invalid argument)
[out#0/mp4 @ 000001bba0ce0800] Terminating thread with return code -22 (Invalid argument)
[out#0/mp4 @ 000001bba0ce0800] Error writing trailer: Invalid argument
[out#0/mp4 @ 000001bba0ce0800] Error closing file: Invalid argument
[out#0/mp4 @ 000001bba0ce0800] video:7168056KiB audio:127691KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown
frame=88096 fps=556 q=-1.0 Lsize= 7295488KiB time=01:00:32.20 bitrate=16454.1kbits/s speed=22.9x
Conversion failed!

E:\20260722红米Note12Pro>
我们看到了用户提供的命令和错误信息。用户执行了:
ffmpeg -i E:\20260722红米Note12Pro\Screenrecorder-2026-07-18-16-11-33-355解锁太阳观测与摄影_KV-凯文【最后拿掉】.mp4 -to 01:12:13 -c copy output.mp4

这个命令本意是截取从开头到01:12:13的部分,即拿掉后面部分。但出现了错误:Error submitting a packet to the muxer: Invalid argument,并且最终失败。

可能的原因:使用-to配合-c copy时,如果指定的时间点不是关键帧,FFmpeg可能需要重新编码才能精确截断,但-c copy会尝试在关键帧处截断,可能会导致问题。另外,可能输出文件已存在或有权限问题,或者文件本身有损坏。但错误信息是“Invalid argument”,可能是时间格式或参数问题。

用户使用的-to 01:12:13,而视频总时长是01:26:54.62,所以截取到01:12:13是合理的。但错误出现在muxer提交包时,可能因为音频或视频流的不一致。

或许需要加上-avoid_negative_ts make_zero或使用-ss和-t组合。或者更可靠的方法是使用-ss指定开始时间(0)和-t指定时长(计算总时长减去要移除的长度)。

由于用户想拿掉最后部分,我们可以推荐更可靠的方法:使用-t指定保留时长,或者使用-sseof方法(从末尾开始)。之前用户已知总时长01:26:54.62,要保留到01:12:13,则保留时长是01:12:13,但可能因为关键帧问题,建议加上-vsync drop或使用-copyts等。

但错误信息显示Error submitting a packet to the muxer: Invalid argument,这可能是由于时间戳问题。有些建议是在-to前加上-copyts或使用-ss作为输入选项。

我们可以提供以下解决方案:

尝试使用-ss 0 -t 01:12:13(指定从0开始截取时长01:12:13)。

尝试加上-avoid_negative_ts 1。

尝试使用-sseof方法,如ffmpeg -sseof -14:41.49 -i input.mp4 -c copy output.mp4(因为总时长减去要保留的时间就是移除的时长,但这里要移除的是14分41.49秒)。

用户要拿掉最后部分,即保留从开头到01:12:13,移除的时间为总时长01:26:54.62减去01:12:13 = 14分41.62秒(约14:41.62)。可以使用-sseof -00:14:41.62。

由于用户遇到错误,我们应指导用户尝试更稳健的命令,并解释可能的原因。

另外,注意Windows路径中的空格和特殊字符,用户已经用引号括起来了?但命令中没有引号,可能没问题,因为路径没有空格。但是有【】等,不过FFmpeg应该能处理。

建议用户尝试:

先用ffmpeg -i input.mp4 -t 01:12:13 -c copy -avoid_negative_ts 1 output.mp4

或者使用-ss 0 -to 01:12:13 -c copy并添加-copyts。

或者用-sseof方法:计算移除时长,-sseof -00:14:41.62 -i input.mp4 -c copy output.mp4。

同时提示用户如果还是失败,可能需要重新编码(去掉-c copy)。

我们需要给出清晰、详细的回答,解释错误可能的原因,并提供多种解决方案。

从你贴出的错误信息看,FFmpeg 在封装(mux)时遇到了 Invalid argument 错误,这通常是由于使用 -to 配合 -c copy 时,截断点不在关键帧(I帧)上,导致输出的时间戳出现异常,尤其是音频和视频流长度不匹配时更容易触发。

针对你的需求(保留视频开头到 01:12:13,即删除末尾部分),这里给出几种更稳健的解决办法,按推荐程度排序:

✅ 方法一:改用 -t 指定保留时长(最推荐)
你已经知道视频总时长(01:26:54.62),要保留到 01:12:13,则保留时长为 01:12:13(从开头算起)。
使用 -t 而非 -to,可以避免一些时间戳解析问题:

bash
ffmpeg -i "Screenrecorder-2026-07-18-16-11-33-355解锁太阳观测与摄影_KV-凯文【最后拿掉】.mp4" -t 01:12:13 -c copy -avoid_negative_ts 1 output.mp4
-t 01:12:13:表示从输入开头起截取 1小时12分13秒 的内容。

-avoid_negative_ts 1:强制将负时间戳归零,避免 muxer 报错。

✅ 方法二:使用 -sseof 从末尾倒推(无需计算总时长)
直接告诉 FFmpeg “我要删掉末尾 XX 秒”,不用自己算总时长。
你的视频总时长约 01:26:54.62,要保留到 01:12:13,则删除的时长为:
01:26:54.62 - 01:12:13 = 14分41.62秒(约 00:14:41.62)。

命令如下(注意 -sseof 的值必须是负数):

bash
ffmpeg -sseof -00:14:41.62 -i "Screenrecorder-2026-07-18-16-11-33-355解锁太阳观测与摄影_KV-凯文【最后拿掉】.mp4" -c copy output.mp4
这个命令从文件末尾往回跳 14分41.62秒,然后复制从该位置到文件末尾的内容(注意:这实际上保留的是后半段,并不是你要的)。
请改成正向理解:-sseof 其实是跳到距离末尾多少秒的位置开始输出,如果你想要保留开头到某个点,应该改用 -ss + -t,所以方法二不太适合你的需求,这里只是作为补充说明。

✅ 方法三:用 -ss 作为输出选项(强制精确切割)
如果你想精确到非关键帧,可以牺牲一点速度让 FFmpeg 重新编码,但你的文件很大(9.5GB),重新编码会非常耗时。
如果非要使用 -to,可以尝试加上 -copyts 和 -avoid_negative_ts:

bash
ffmpeg -i "input.mp4" -to 01:12:13 -c copy -copyts -avoid_negative_ts 1 output.mp4
-copyts 保留原始时间戳,有时能避免 mux 错误。

🔍 错误原因分析
你原命令中 -to 01:12:13 可能恰好落在非关键帧上,而 -c copy 要求切割点必须在关键帧,否则 FFmpeg 会尝试调整时间戳,导致音频/视频数据包的 PTS/DTS 出现负数或异常,最终 muxer 拒绝写入。

你的视频帧率是 24.25 fps,时间戳计算可能有微小的舍入误差,也容易触发此问题。

⚠️ 如果上述方法仍然失败
可以放弃 -c copy,让 FFmpeg 重新编码(虽然慢但最精确):

bash
ffmpeg -i "input.mp4" -to 01:12:13 -c:v libx264 -c:a aac output.mp4
这会重新编码视频和音频,耗时较长(你的视频约 9.5GB,可能在几十分钟到数小时),但几乎能保证成功。

📝 注意事项
在 Windows 命令提示符中,建议用双引号将文件名括起来,因为文件名包含中文和特殊符号(【】),虽然你之前没加也执行了,但为了安全还是加上。

确保输出文件名不与已有文件冲突,否则会询问是否覆盖,可以用 -y 自动覆盖。

你可以先尝试方法一,它最稳定且能快速完成。如果成功,就不需要重新编码了。

转载自 CSDN-专业IT技术社区

原文链接:https://blog.csdn.net/wb4916/article/details/171108696

文章来源转载

评论

评论列表

微信小程序
QQ小程序

关于作者

点赞数:0
关注数:0
粉丝:0
文章:0
关注标签:0
加入于:--