Opened 5 years ago

Last modified 5 years ago

#8189 reopened defect

FFMPEG fails to trim beginning of clip

Reported by: M Morin Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: FFMPEG fails to trim beginning of a clip when given as input option, but works OK as output option. For more information on the solution, see thread at https://stackoverflow.com/questions/57450657/ffmpeg-fails-to-trim-beginning-of-clip/57451310#57451310

How to reproduce:

I downloaded the binary from https://ffmpeg.zeranoe.com/builds/macos64/static/ffmpeg-20190812-faa9cd3-macos64-static.zip

I ran a command to trim the first five seconds of two videos. It succeeded with the first video, which has 16 MB, but not with the second, which has 2.0 GB.

$ ~/Downloads/ffmpeg-20190812-faa9cd3-macos64-static/bin/ffmpeg -ss 0 -to 5 -i 00117.MTS -vcodec copy -acodec copy start_00117.MTS
ffmpeg version N-94528-gfaa9cd312f Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-appkit --enable-avfoundation --enable-coreimage --enable-audiotoolbox
  libavutil      56. 33.100 / 56. 33.100
  libavcodec     58. 55.100 / 58. 55.100
  libavformat    58. 30.100 / 58. 30.100
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 58.100 /  7. 58.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.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.30.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=65.8x    
video:15162kB audio:189kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.143849%
$ ~/Downloads/ffmpeg-20190812-faa9cd3-macos64-static/bin/ffmpeg -ss 0 -to 5 -i 00118.MTS -vcodec copy -acodec copy start_00118.MTS
ffmpeg version N-94528-gfaa9cd312f Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-appkit --enable-avfoundation --enable-coreimage --enable-audiotoolbox
  libavutil      56. 33.100 / 56. 33.100
  libavcodec     58. 55.100 / 58. 55.100
  libavformat    58. 30.100 / 58. 30.100
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 58.100 /  7. 58.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.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.30.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=783 q=-1.0 Lsize= 2130467kB time=00:12:36.54 bitrate=23069.0kbits/s speed=15.7x    
video:1946718kB audio:23627kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.126621%
$ ls -laht start_*
-rw-r--r--@ 1 mmorin  staff   2.0G 15 Sep 11:26 start_00118.MTS
-rw-r--r--@ 1 mmorin  staff    16M 15 Sep 11:25 start_00117.MTS

Change History (18)

comment:1 by Carl Eugen Hoyos, 5 years ago

Keywords: trim input removed
Version: unspecifiedgit-master

Where can I find the input sample?

comment:2 by M Morin, 5 years ago

It is a 2.13 GB MTS file on my hard drive. If you need part or the whole file, I'll ask the people in the video for permission to circulate it. Otherwise, tell me what commands like ffmpeg or ffprobe to run on it.

comment:3 by M Morin, 5 years ago

I tested today with the nightly build and I get the same bug. The input sample that works is at:

https://drive.google.com/open?id=174BkApf3k7rDGkJfdIvjW2PbG8AXOnqL

The sample from the same camera 10 min later that fails is at:

https://drive.google.com/open?id=1LScqnH8vFZ7D0_4-EduSqcqlEFbKdg8f

comment:4 by gdgsdg123, 5 years ago

Let me take a blind guess: the input video must be of non-Intra encoding.

Also check: http://trac.ffmpeg.org/ticket/8464

comment:5 by M Morin, 5 years ago

The output of ffprobe suggests that both samples use the same compression of h264. I include a log below. Both samples use the same coding, intra or non-Intra, so I don't see why it would affect one and not the other.

I read the 8464 bug conversation and don't understand why outpoint and floating point precision would help here.

Results of ffprobe:

$ ffprobe 00122.MTS 
ffprobe version 4.2.2 Copyright (c) 2007-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.16)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include/darwin -fno-stack-check' --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-libvidstab --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-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mpegts, from '00122.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

$ ffprobe 00123.MTS 
ffprobe version 4.2.2 Copyright (c) 2007-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.16)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include/darwin -fno-stack-check' --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-libvidstab --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-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mpegts, from '00123.MTS':
  Duration: 00:12:36.55, start: 756.592000, bitrate: 22479 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
Last edited 5 years ago by M Morin (previous) (diff)

in reply to:  5 ; comment:6 by gdgsdg123, 5 years ago

Replying to mmorin:

...intra or non-Intra, so I don't see why...

You didn't seem to have realized the implications of -c copy.

Another blind guess: removing the

-vcodec copy -acodec copy

part in the command in the description may yield a different result (duration wise).

comment:7 by M Morin, 5 years ago

Indeed, with just

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

the output of both files is now around 5 seconds. No, I haven't realized the implications of -c copy and I have read the manual section. Why does it have a different effect on one input sample and not the other?

in reply to:  7 comment:8 by gdgsdg123, 5 years ago

Replying to mmorin:

-c copy implicates no re-encoding will occur.

Not a direct answer but should help you realize the idea:
https://forum.videohelp.com/threads/395656#post2570892

Keywords: Inter interpolation


Also check the descriptions of inpoint and outpoint directives of concat demuxer.

comment:9 by M Morin, 5 years ago

I think I understand now. Both samples have non-intra encoding, which means that if the data related to a frame exceeds the bitrate, the extra bytes will be saved in a "byte reservoir" and added to later frames . In the first sample, the outpoint of 5 seconds has an empty byte reservoir and the command can exit at that point without having to decode and re-encode. In the second sample, the outpoint of 5 seconds has a non-empty "byte reservoir", so copying without decoding and re-encoding is forced to copy the whole file. Is my understanding correct?

in reply to:  9 comment:10 by gdgsdg123, 5 years ago

Replying to mmorin:

..."byte reservoir"... Is my understanding correct?

Terribly wrong... Nothing to do with "byte reservoir".

Inter interpolation introduces dependency on other frames.

comment:11 by M Morin, 5 years ago

OK, nothing to do with a byte reservoir. Is it then a coincidence that the command works for the first input sample in an hour-long recording and not with the second?

in reply to:  11 comment:12 by gdgsdg123, 5 years ago

Replying to mmorin:

Is it then a coincidence that the command works for the first input sample in an hour-long recording and not with the second?

Somewhat.

3.2 Stream copy

However, it might not work in some cases because of many factors.

Mostly because of the Inter interpolation's nature.

comment:13 by M Morin, 5 years ago

Resolution: invalid
Status: newclosed

OK thanks. Then it's not a bug, just a feature, and I'll close this.

comment:14 by M Morin, 5 years ago

I have now deleted the input samples from the cloud provider.

in reply to:  6 ; comment:15 by Gyan, 5 years ago

Resolution: invalid
Status: closedreopened

Replying to gdgsdg123:

Replying to mmorin:

...intra or non-Intra, so I don't see why...

You didn't seem to have realized the implications of -c copy.

Another blind guess: removing the

-vcodec copy -acodec copy

part in the command in the description may yield a different result (duration wise).

The OP is reporting that the whole file is conveyed when trimming out at 5 seconds. Streamcopying will, at most, add a few frames in the video stream, when trimming the out point. Also, the output is fine when trimming is set via output options. In both cases, the video is being streamcopied.

So, there is a more subtle anomaly being seen here.

To the OP, please re-upload the 2nd file, at least.

in reply to:  15 ; comment:17 by gdgsdg123, 5 years ago

Replying to Gyan:

So, there is a more subtle anomaly being seen here.

I never said there's no problem...

Anyway what causes the problem seems to be the non-Intra nature of the input.


Replying to mmorin:

Here are the input samples...

Off-Topic but... it's quite interesting that the "re-uploads" have identical URL as the original ("deleted") uploads.

in reply to:  17 comment:18 by M Morin, 5 years ago

Replying to gdgsdg123:

Off-Topic but... it's quite interesting that the "re-uploads" have identical URL as the original ("deleted") uploads.

Yes, I was able to undo the deletion of the files, so they have the same links.

Note: See TracTickets for help on using tickets.