简体   繁体   English

FFMPEG 无法修剪剪辑的开头

[英]FFMPEG fails to trim beginning of clip

I have two .MTS files taken in sequence and I want to trim them to the first five seconds.我有两个按顺序拍摄的.MTS文件,我想将它们修剪到前五秒。 This command works for the first file:此命令适用于第一个文件:

ffmpeg -ss 0 -to 5 -i 00117.MTS -vcodec copy -acodec copy start_00117.MTS

The result is 5 seconds and 17 MB, as opposed to the 12 minutes and 2 GB from the original.结果是 5 秒和 17 MB,而不是原始的 12 分钟和 2 GB。

The same command on the second file fails:第二个文件上的相同命令失败:

ffmpeg -ss 0 -to 5 -i 00118.MTS -vcodec copy -acodec copy start_00118.MTS

The result is 12 minutes and 2 GB, like its original file.结果是 12 分钟和 2 GB,就像它的原始文件一样。

What is the problem?问题是什么?

Full log :完整日志

$ rm start_00117.MTS; ffmpeg -ss 0 -to 5 -i 00117.MTS -vcodec copy -acodec copy start_00117.MTS
ffmpeg version 4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.4_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, mpegts, from '00117.MTS':
  Duration: 00:12:36.02, start: 1.040000, bitrate: 22490 kb/s
  Program 1 
    Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
    Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
Output #0, mpegts, to 'start_00117.MTS':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(top first), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 50 tbr, 90k tbn, 90k tbc
    Stream #0:1: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  304 fps=0.0 q=-1.0 Lsize=   16601kB time=00:00:06.02 bitrate=22590.4kbits/s speed=25.8x    
video:15162kB audio:189kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.143849%
$ rm start_00118.MTS; ffmpeg -ss 0 -to 5 -i 00118.MTS -vcodec copy -acodec copy start_00118.MTS
rm: start_00118.MTS: No such file or directory
ffmpeg version 4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.4_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, mpegts, from '00118.MTS':
  Duration: 00:12:36.59, start: 756.592000, bitrate: 22471 kb/s
  Program 1 
    Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
    Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
Output #0, mpegts, to 'start_00118.MTS':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(top first), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 50 tbr, 90k tbn, 90k tbc
    Stream #0:1: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=37804 fps=923 q=-1.0 Lsize= 2130467kB time=00:12:36.54 bitrate=23069.0kbits/s speed=18.5x    
video:1946718kB audio:23627kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.126621%

This looks to be a bug with input -to .这看起来是 input -to的错误。 For now, use -ss and -to as output options.现在,使用-ss-to作为输出选项。

ffmpeg -i 00118.MTS -ss 0 -to 5 -c copy start_00118.MTS

Using -c copy may fail in several situations and this is one of them.在多种情况下使用-c copy可能会失败,这就是其中之一。 From the documentation :文档

Stream copy is a mode selected by supplying the copy parameter to the -codec option.流复制是通过将copy参数提供给-codec选项来选择的模式。 It makes ffmpeg omit the decoding and encoding step for the specified stream, so it does only demuxing and muxing.它使 ffmpeg 省略了指定流的解码和编码步骤,因此它只进行解复用和复用。 It is useful for changing the container format or modifying container-level metadata.它对于更改容器格式或修改容器级元数据很有用。 The diagram above will, in this case, simplify to this:在这种情况下,上图将简化为:

 _______ ______________ ________ | | | | | | | input | demuxer | encoded data | muxer | output | | file | ---------> | packets | -------> | file | |_______| |______________| |________|

Since there is no decoding or encoding, it is very fast and there is no quality loss.由于没有解码或编码,因此速度非常快且没有质量损失。 However, it might not work in some cases because of many factors.但是,由于许多因素,它在某些情况下可能不起作用。

This is one such factor.这是一个这样的因素。 See the closed bug report for a longer explanation and the coincidence of why the command works with the first section of a long record and not the second section.请参阅已关闭的错误报告以获得更长的解释以及为什么该命令适用于长记录的第一部分而不是第二部分的巧合。

Removing -c copy (or -vcodec copy -acodec copy ) fixes the corner case, ie:删除-c copy (或-vcodec copy -acodec copy )修复了-vcodec copy -acodec copy情况,即:

ffmpeg -ss 0 -to 5 -i 00122.MTS start_00122.MTS

See also Gyan's solution of using -ss and -to as output options, which also fixes the corner case.另请参阅 Gyan 使用-ss-to作为输出选项的解决方案,这也解决了极端情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM