Does --stop-at have a 1 second minimum trim?

Discussion of the HandBrake command line interface (CLI)
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
Chris Canfield
Posts: 4
Joined: Fri Jan 12, 2018 5:34 pm

Does --stop-at have a 1 second minimum trim?

Post by Chris Canfield »

Description of problem or question:
Hello! I'm trying to use HandBrakeCLI to trim a *few* frames off of a video while re-encoding from ProRes to h.264, but this doesn't seem to work. In both the command line and the GUI, I seem to need to trim off a full second or more. Otherwise the --stop-at seems to be ignored.

This is the full command:

Code: Select all

HandBrakeCLI -v0 -i ${VIDNAME}.mov -o ${VIDNAME}_${BITRATENAME}.mp4 -e x264 --start-at frame:0 --stop-at frame:3062 --encoder-preset ${ENCODESPEED} --encoder-tune ${ENCODERTUNING} --encoder-profile main --encoder-level 3.0 --vb ${BITRATEVB} --aencoder ${AUDIOTYPE} --ab ${AUDIOBITRATE}  --arate ${AUDIOSAMPLERATE} --mixdown stereo --width ${WIDTH} --height ${HEIGHT} --crop 0:0:0:0 --encopts keyint=${KEYINTERVAL}:min-keyint=${KEYINTERVAL}:scenecut=0:vbv-maxrate=${VBVMAXRATE}:vbv-bufsize=${VBVBUFSIZE}:
These are the parts that seem applicable:

Code: Select all

HandBrakeCLI -v0 -i ${VIDNAME}.mov -o ${VIDNAME}_${BITRATENAME}.mp4 -e x264 --start-at frame:0 --stop-at frame:3062
This video is 3062 frames long, at 29.97 fps. If I set the --stop-at frame to 3050, the resultant video has 3062 frames. If I set the --stop-at frame to 3040, the resultant video has 3062 frames. This is consistent down to 3033. However, If I set the --stop-at frame to 3032 (1 second off), the final output has 3032 frames. Below that, it seems to match the asked-for number of frames precisely.

Is this a known thing, where more than a second must be trimmed off? Is there a workaround?


HandBrake version (e.g., 1.0.0):
HandBrakeCLI version 1.1.1

Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.13 High Sierra, Windows 10 Creators Update):
macOS 10.13.5 High Sierra,

HandBrake Activity Log ***required*** (see How-to get an activity log)

Code: Select all

[17:32:50] hb_init: starting libhb thread
[17:32:50] thread 70000364b000 started ("libhb")
HandBrake 1.1.1 (2018061800) - Darwin x86_64 - https://handbrake.fr
8 CPUs detected
Opening TestFile.mov...
[17:32:50] CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
[17:32:50]  - Intel microarchitecture Haswell
[17:32:50]  - logical processor count: 8
[17:32:50] hb_scan: path=TestFile.mov, title_index=1
udfread ERROR: ECMA 167 Volume Recognition failed
disc.c:323: failed opening UDF image TestFile.mov
disc.c:424: error opening file BDMV/index.bdmv
disc.c:424: error opening file BDMV/BACKUP/index.bdmv
[17:32:50] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 5.0.3
libdvdread: Encrypted DVD support unavailable.
libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[17:32:50] dvd: not a dvd - trying as a stream/file instead
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'TestFile.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2018-05-30 10:47:47
  Duration: 00:01:42.16, start: 0.000000, bitrate: 150665 kb/s
    Stream #0:0(eng): Video: prores [apch / 0x68637061]
      yuv422p10le, bt709/bt709/bt709
      2048x912, 148922 kb/s, PAR 2048:2048 DAR 128:57
      29.97 fps, 30k tbn (default)
    Metadata:
      creation_time   : 2018-05-30 10:47:47
      handler_name    : Apple Alias Data Handler
      encoder         : Apple ProRes 422 (HQ)
    Stream #0:1(eng): Audio: pcm_s16le [sowt / 0x74776F73]
      48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2018-05-30 10:47:47
      handler_name    : Apple Alias Data Handler
    Stream #0:2(eng): Data: tmcd / 0x64636D74 (default)
    Metadata:
      creation_time   : 2018-05-30 10:47:47
      handler_name    : Apple Alias Data Handler
[17:32:50] scan: decoding previews for title 1
[17:32:50] scan: audio 0x1: pcm_s16le, rate=48000Hz, bitrate=1536000 English (pcm_s16le) (2.0 ch)

Scanning title 1 of 1, preview 4, 40.00 %
Scanning title 1 of 1, preview 10, 100.00 %[17:32:50] scan: 10 previews, 2048x912, 29.970 fps, autocrop = 0/0/0/0, aspect 2.25:1, PAR 2048:2048
[17:32:50] libhb: scan thread found 1 valid title(s)
+ Using preset: CLI Default
+ title 1:
  + stream: TestFile.mov
  + duration: 00:01:42
  + size: 2048x912, pixel aspect: 2048/2048, display aspect: 2.25, 29.970 fps
  + autocrop: 0/0/0/0
  + chapters:
    + 1: cells 0->0, 0 blocks, duration 00:01:42
  + audio tracks:
    + 1, English (pcm_s16le) (2.0 ch) (iso639-2: eng)
  + subtitle tracks:
[17:32:51] 1 job(s) to process
[17:32:51] starting job
[17:32:51] job configuration:
[17:32:51]  * source
[17:32:51]    + TestFile.mov
[17:32:51]    + title 1, frames 0 to 3032
[17:32:51]    + container: mov,mp4,m4a,3gp,3g2,mj2
[17:32:51]    + data rate: 150665 kbps
[17:32:51]  * destination
[17:32:51]    + TestFile_130.mp4
[17:32:51]    + container: MPEG-4 (libavformat)
[17:32:51]  * video track
[17:32:51]    + decoder: prores
[17:32:51]      + bitrate 148922 kbps
[17:32:51]    + filters
[17:32:51]      + Framerate Shaper (mode=0)
[17:32:51]        + frame rate: same as source (around 29.970 fps)
[17:32:51]      + Crop and Scale (width=512:height=228:crop-top=0:crop-bottom=0:crop-left=0:crop-right=0)
[17:32:51]        + source: 2048 * 912, crop (0/0/0/0): 2048 * 912, scale: 512 * 228
[17:32:51]    + Output geometry
[17:32:51]      + storage dimensions: 512 x 228
[17:32:51]      + pixel aspect ratio: 1 : 1
[17:32:51]      + display dimensions: 512 x 228
[17:32:51]    + encoder: H.264 (libx264)
[17:32:51]      + preset:  ultrafast
[17:32:51]      + tune:    animation
[17:32:51]      + options: keyint=180:min-keyint=180:scenecut=0:vbv-maxrate=40:vbv-bufsize=60:
[17:32:51]      + profile: main
[17:32:51]      + level:   3.0
[17:32:51]      + bitrate: 20 kbps, pass: 0
[17:32:51]  * audio track 1
[17:32:51]    + decoder: English (pcm_s16le) (2.0 ch) (track 1, id 0x1)
[17:32:51]      + bitrate: 1536 kbps, samplerate: 48000 Hz
[17:32:51]    + mixdown: Stereo
[17:32:51]    + encoder: HE-AAC (Apple AudioToolbox)
[17:32:51]      + bitrate: 80 kbps, samplerate: 48000 Hz
[17:32:51] sync: expecting 3033 video frames
[17:32:51] encx264: min-keyint: 180, keyint: 180
[17:32:51] encx264: encoding at average bitrate 20
[17:32:51] encx264: unparsed options: keyint=180:keyint-min=180:scenecut=0:vbv-maxrate=40:vbv-bufsize=60:level=3.0:ref=1:bframes=2:b-adapt=0:weightb=0:no-deblock=1:cabac=0:analyse=none:8x8dct=0:weightp=0:me=dia:subme=0:mixed-refs=0:psy-rd=0.4,0:aq-mode=0:mbtree=0:rc-lookahead=0
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x264 [info]: profile Main, level 3.0
[17:32:51] sync: first pts video is 0
[17:32:51] sync: Chapter 1 at frame 1 time 0
[17:32:51] sync: first pts audio 0x1 is 0
[17:33:23] reader: done. 1 scr changes
[17:33:23] work: average encoding speed for job is 95.421181 fps
[17:33:23] vfr: lost time: 0 (0 frames)
[17:33:23] vfr: gained time: 0 (0 frames) (0 not accounted for)
[17:33:23] pcm_s16le-decoder done: 4798 frames, 0 decoder errors
[17:33:23] prores-decoder done: 3062 frames, 0 decoder errors
[17:33:23] sync: got 3062 frames, 3033 expected
[17:33:23] sync: framerate min 29.970 fps, max 29.970 fps, avg 29.970 fps
x264 [info]: frame I:18    Avg QP:42.30  size:  2674
x264 [info]: frame P:1021  Avg QP:40.74  size:   144
x264 [info]: frame B:2023  Avg QP:42.22  size:    23
x264 [info]: consecutive B-frames:  0.6%  1.1% 98.3%
x264 [info]: mb I  I16..4: 100.0%  0.0%  0.0%
x264 [info]: mb P  I16..4:  3.2%  0.0%  0.0%  P16..4:  2.9%  0.0%  0.0%  0.0%  0.0%    skip:93.8%
x264 [info]: mb B  I16..4:  0.1%  0.0%  0.0%  B16..8:  0.4%  0.0%  0.0%  direct: 0.1%  skip:99.4%  L0:59.7% L1:38.5% BI: 1.8%
x264 [info]: final ratefactor: 49.84
x264 [info]: coded y,uvDC,uvAC intra: 15.0% 28.9% 13.7% inter: 0.3% 0.7% 0.1%
x264 [info]: i16 v,h,dc,p: 62% 24% 11%  4%
x264 [info]: i8c dc,h,v,p: 78% 11% 10%  1%
x264 [info]: kb/s:18.95
[17:33:23] mux: track 0, 3062 frames, 241243 bytes, 18.87 kbps, fifo 4096
[17:33:23] mux: track 1, 2398 frames, 972578 bytes, 76.08 kbps, fifo 4096
[17:33:23] libhb: work result = 0

Encode done!
HandBrake has exited.

User avatar
s55
HandBrake Team
Posts: 10350
Joined: Sun Dec 24, 2006 1:05 pm

Re: Does --stop-at have a 1 second minimum trim?

Post by s55 »

Depending on source, frame ranges are not guaranteed to be frame accurate.
Chris Canfield
Posts: 4
Joined: Fri Jan 12, 2018 5:34 pm

Re: Does --stop-at have a 1 second minimum trim?

Post by Chris Canfield »

Darn. I was worried it might be something like that.

Thank you for the info, though! That info definitely helps me debug this system.
User avatar
BradleyS
Moderator
Posts: 1860
Joined: Thu Aug 09, 2007 12:16 pm

Re: Does --stop-at have a 1 second minimum trim?

Post by BradleyS »

Try --stop-at="pts:274500000" which is the base clock 90,000 Hz times the frame rate.
Post Reply