[FFmpeg-user] FFMPEG Changes TimeBase in Trim Operation?

Larry Camilli larry.camilli at gmail.com
Sat Jan 6 04:51:16 EET 2018


I'm having trouble using FFMPEG to manipulate mp4 videos that are the output
of a Wolverine film2video converter.
The converter has no provision for editing and produces videos with a 30fps
frame rate, but with the film frames
copied one-to-one to the video, so the playback speed is wrong.  [8mm =
16fps; Super8 = 18fps]

So, what I am trying to do is:

1. use FFMPEG to trim each video segment (just removing a few seconds from
the beginning and end to remove leader film
   and damaged frames) (with the {-ss <time> + -filter:v
"setpts=PTS-STARTPTS"} and {-t <time>} options).
2. concatenate segments from the same filming session into a longer video
(with the {-f concat} option and a separate text file
   with the segments to concatenate).
3. fix the speed, so that the video runs at the correct speed (with the
{-filter:v "setpts=1.875*PTS"}(8mm) or
   {-filter:v "setpts=1.667*PTS"}(Super8) option.

I have had individual steps work, but, when I combine them, I get screwed-up
videos.

I reduced one of the failures (trimming and assembling 9 segments) to
processing only two segments, to make it easier to figure
out what's going wrong.  (There might be other problems, but this is a
start.)


I now have two videos, each an mp4, the output of the "film2video" converter
- having converted a single Super8 film segment.
VLC says that each is 30fps [Tools -> Codec Information -> Codec (tab)].  If
I concatenate the two with FFMPEG, I get a video
that appears to be the concatenation of the two segments, and it seems to be
30fps (with the one-to-one mapping from the 18fps
film).  [VLC says 30fps, and it runs fast, just like the segments.]

However, if I trim the first video segment at either or both ends and then
concatenate the two, the resultant video actually
runs at a slow speed (and VLC says that the frame rate is 15.359113).

It APPEARS that, when trimming a video, FFMPEG changes the time-scale /
time-base number (is that what tbn stands for?) from 30K to 15360.
Why?  I would think that trimming a video would involve doing nothing to the
video but throwing away some frame records and
renumbering the remaining ones (the setpts option).  What's the logic behind
FFMPEG changing the whole video so dramatically?

More important (to me):  Is there an option to keep FFMPEG from tampering
with TBN in the trimming operation?  [I'd prefer an option that
says "leave it alone", but, I suppose, I could live with an option that
requires me, for each video, to see what the TBN on the original is
and put that number on the command line.


By the way, VLC says that the truncated video is still 30fps and it seems to
play the video at 30/18 (ratio of video FPS and film FPS) speed.
(Does it calculate that from some of the timestamps and from the time
scale?)
 
FFMPEG (the concatenate operation) seems to be saying that the
timescale/timebase/whatever was cut in half by the trim operation.  When
FFMPEG
changed the timebase, did it also change the timestamps on the frames to
match?  Does the FFPROBE tool show such things?



Log of FFMPEG Concatenating two video segments, as scanned:
----------------------------------------------------------
E:\Camilli\Personal\Video\TEMP\TEST>ffmpeg -f concat -i
ConcatenateTwoAsScanned.txt -c copy Italy1971Reel1Segment1Segment2-0030S8FPS
mp4
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib
--enable-fontconfig --enable-gnutls --enable-iconv --en
e-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame
--enable-libopenjpeg --enable-libopus --enable-libshine --enabl
ibsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx2
--enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma
--enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis -
able-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2
--enable-avisynth --enable-libmfx
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000007b6e56b900] Auto-inserting h264_mp4toannexb
bitstream filter
Input #0, concat, from 'ConcatenateTwoAsScanned.txt':
  Duration: N/A, start: 0.000000, bitrate: 8190 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p,
960x720, 8190 kb/s, 30 fps, 30 tbr, 30k tbn, 60k tbc
    Metadata:
      creation_time   : 2014-01-02T14:04:04.000000Z
      handler_name    : DataHandler
      encoder         : h264
Output #0, mp4, to 'Italy1971Reel1Segment1Segment2-0030S8FPS30.mp4':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p,
960x720, q=2-31, 8190 kb/s, 30 fps, 30 tbr, 30k tbn, 30k tbc
    Metadata:
      creation_time   : 2014-01-02T14:04:04.000000Z
      handler_name    : DataHandler
      encoder         : h264
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000007b6e89f940] Auto-inserting h264_mp4toannexb
bitstream filter
frame=18136 fps=563 q=-1.0 Lsize=  604591kB time=00:10:04.50
bitrate=8193.2kbits/s speed=18.8x
video:604511kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.013351%

E:\Camilli\Personal\Video\TEMP\TEST>
==========================================================




Log of FFMPEG Trimming Segment 1 (1.5 Seconds off the start):
------------------------------------------------------------
E:\Camilli\Personal\Video\TEMP\TEST>ffmpeg -ss 00:00:01.5 -i
Italy1971Reel1Segment1-0030S8FPS30ASSCANNED.mp4 -filter:v "setpts=PTS-S
TPTS" Italy1971Reel1Segment1-0030S8FPS30TrimmedAtStart.mp4
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib
--enable-fontconfig --enable-gnutls --enable-iconv --en
e-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame
--enable-libopenjpeg --enable-libopus --enable-libshine --enabl
ibsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx2
--enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma
--enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis -
able-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2
--enable-avisynth --enable-libmfx
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'Italy1971Reel1Segment1-0030S8FPS30ASSCANNED.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isomavc1mp42
    creation_time   : 2014-01-02T14:04:04.000000Z
    original_format : NVT-IM
    original_format-eng: NVT-IM
    comment         : CarDV-TURNKEY
    comment-eng     : CarDV-TURNKEY
  Duration: 00:02:01.83, start: 0.000000, bitrate: 8350 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p,
960x720, 8190 kb/s, 30 fps, 30 tbr, 30k tbn, 60k tbc (default
    Metadata:
      creation_time   : 2014-01-02T14:04:04.000000Z
      handler_name    : DataHandler
      encoder         : h264
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0000000d447d8ce0] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2
[libx264 @ 0000000d447d8ce0] profile High, level 3.1
[libx264 @ 0000000d447d8ce0] 264 - core 152 r2851 ba24899 - H.264/MPEG-4 AVC
codec - Copyleft 2003-2017 - http://www.videolan.org/x2
html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7
psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_m
 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2
threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decima
1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2
b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2
int=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf
mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_r
o=1.40 aq=1:1.00
Output #0, mp4, to 'Italy1971Reel1Segment1-0030S8FPS30TrimmedAtStart.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isomavc1mp42
    comment-eng     : CarDV-TURNKEY
    original_format : NVT-IM
    original_format-eng: NVT-IM
    comment         : CarDV-TURNKEY
    encoder         : Lavf57.83.100
    Stream #0:0(eng): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p,
960x720, q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2014-01-02T14:04:04.000000Z
      handler_name    : DataHandler
      encoder         : Lavc57.107.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 3610 fps= 11 q=-1.0 Lsize=   93753kB time=00:02:00.23
bitrate=6387.8kbits/s speed=0.359x
video:93722kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.033489%
[libx264 @ 0000000d447d8ce0] frame I:134   Avg QP:23.45  size: 40030
[libx264 @ 0000000d447d8ce0] frame P:2130  Avg QP:26.39  size: 27591
[libx264 @ 0000000d447d8ce0] frame B:1346  Avg QP:26.97  size: 23654
[libx264 @ 0000000d447d8ce0] consecutive B-frames: 49.2%  2.2%  2.9% 45.7%
[libx264 @ 0000000d447d8ce0] mb I  I16..4: 10.6% 67.3% 22.1%
[libx264 @ 0000000d447d8ce0] mb P  I16..4:  7.7% 39.3%  8.7%  P16..4: 28.9%
10.5%  2.6%  0.0%  0.0%    skip: 2.2%
[libx264 @ 0000000d447d8ce0] mb B  I16..4:  3.5% 12.7%  3.1%  B16..8: 37.3%
15.7%  3.5%  direct:14.8%  skip: 9.3%  L0:52.7% L1:38.6%
: 8.6%
[libx264 @ 0000000d447d8ce0] 8x8 transform intra:69.5% inter:59.1%
[libx264 @ 0000000d447d8ce0] coded y,uvDC,uvAC intra: 80.9% 29.9% 1.3%
inter: 58.6% 32.2% 0.1%
[libx264 @ 0000000d447d8ce0] i16 v,h,dc,p: 13% 23% 37% 26%
[libx264 @ 0000000d447d8ce0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 18% 26%  6%
7%  6%  8%  6% 10%
[libx264 @ 0000000d447d8ce0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 22% 23%  7%
7%  5%  6%  5%  7%
[libx264 @ 0000000d447d8ce0] i8c dc,h,v,p: 63% 25% 11%  1%
[libx264 @ 0000000d447d8ce0] Weighted P-Frames: Y:16.3% UV:9.2%
[libx264 @ 0000000d447d8ce0] ref P L0: 56.5% 16.9% 16.2%  9.1%  1.4%
[libx264 @ 0000000d447d8ce0] ref B L0: 86.2%  9.5%  4.2%
[libx264 @ 0000000d447d8ce0] ref B L1: 94.7%  5.3%
[libx264 @ 0000000d447d8ce0] kb/s:6380.29

E:\Camilli\Personal\Video\TEMP\TEST>
============================================================



Log of FFMPEG Concatenating the Trimmed 1st Segment and the (as Scanned) 2nd
Segment:
----------------------------------------------------------------------------
--------
E:\Camilli\Personal\Video\TEMP\TEST>ffmpeg -f concat -i
ConcatenateOneTrimmedAtStartOneAsScanned.txt -c copy Italy1971Reel1Segment1S
ent2-0030S8FPS30SCREWEDUP.mp4
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib
--enable-fontconfig --enable-gnutls --enable-iconv --en
e-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame
--enable-libopenjpeg --enable-libopus --enable-libshine --enabl
ibsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx2
--enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma
--enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis -
able-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2
--enable-avisynth --enable-libmfx
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000006102ad78a0] Auto-inserting h264_mp4toannexb
bitstream filter
Input #0, concat, from 'ConcatenateOneTrimmedAtStartOneAsScanned.txt':
  Duration: N/A, start: 0.000000, bitrate: 6380 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
960x720, 6380 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc
    Metadata:
      handler_name    : VideoHandler
Output #0, mp4, to
'Italy1971Reel1Segment1Segment2-0030S8FPS30SCREWEDUP.mp4':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
960x720, q=2-31, 6380 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360

    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 00000061029d3180] Auto-inserting h264_mp4toannexb
bitstream filter
frame=18091 fps=531 q=-1.0 Lsize=  576509kB time=00:19:37.73
bitrate=4010.0kbits/s speed=34.5x
video:576414kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.016557%

E:\Camilli\Personal\Video\TEMP\TEST>
============================================================================
========
 
 


More information about the ffmpeg-user mailing list