1

The following command trims a video from 5s to 10s:

ffmpeg -y -i input.mp4 -vf trim=5:10,setpts=PTS-STARTPTS output.mp4

But if I try to specify start and end time using HH:MM:SS format, FFmpeg returns an error:

Output file is empty, nothing was encoded(check -ss / -t / -frames parameters if used)

ffmpeg -y -i input.mp4 -vf trim='00:00:05':'00:00:15',setpts=PTS-STARTPTS output.mp4
ffmpeg -y -i input.mp4 -vf trim=00\:00\:05:00\:00\:15,setpts=PTS-STARTPTS output.mp4

Why is that?


ffmpeg -y -i input.mp4 -vf trim='00\:00\:05':'00\:00\:15',setpts=PTS-STARTPTS output.mp4 -report:

ffmpeg started on 2024-06-20 at 12:13:45
Report written to "ffmpeg-20240620-121345.log"
Log level: 48
Command line:
ffmpeg -y -i input.mp4 -vf "trim=00\\:00\\:05:00\\:00\\:15,setpts=PTS-STARTPTS" output.mp4 -report
ffmpeg version 7.0.1 Copyright (c) 2000-2024 the FFmpeg developers
  built with Apple clang version 15.0.0 (clang-1500.3.9.4)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/7.0.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  libavutil      59.  8.100 / 59.  8.100
  libavcodec     61.  3.100 / 61.  3.100
  libavformat    61.  1.100 / 61.  1.100
  libavdevice    61.  1.100 / 61.  1.100
  libavfilter    10.  1.100 / 10.  1.100
  libswscale      8.  1.100 /  8.  1.100
  libswresample   5.  1.100 /  5.  1.100
  libpostproc    58.  1.100 / 58.  1.100
Splitting the commandline.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-i' ... matched as input url with argument 'input.mp4'.
Reading option '-vf' ... matched as option 'vf' (alias for -filter:v (apply filters to video streams)) with argument 'trim=00\:00\:05:00\:00\:15,setpts=PTS-STARTPTS'.
Reading option 'output.mp4' ... matched as output url.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url input.mp4.
Successfully parsed a group of options.
Opening an input file: input.mp4.
[AVFormatContext @ 0x1597050c0] Opening 'input.mp4' for reading
[file @ 0x6000021202a0] Setting default whitelist 'file,crypto,data'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] Processing st: 0, edit list 0 - media time: 1024, duration: 637440
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] Offset DTS by 1024 to make first pts zero.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] Setting codecpar->delay to 2 for stream st: 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] Before avformat_find_stream_info() pos: 326866 bytes read:48062 seeks:1 nb_streams:1
[h264 @ 0x159705a00] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x159705a00] Decoding VUI
[h264 @ 0x159705a00] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x159705a00] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x159705a00] Decoding VUI
[h264 @ 0x159705a00] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x159705a00] nal_unit_type: 6(SEI), nal_ref_idc: 0
[h264 @ 0x159705a00] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x159705a00] Format yuv420p chosen by get_format().
[h264 @ 0x159705a00] Reinit context to 192x112, pix_fmt: yuv420p
[h264 @ 0x159705a00] no picture 
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1597050c0] After avformat_find_stream_info() pos: 2448 bytes read:80830 seeks:2 frames:1
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf61.1.100
  Duration: 00:00:49.80, start: 0.000000, bitrate: 52 kb/s
  Stream #0:0[0x1](und), 1, 1/12800: Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 192x108 [SAR 1:1 DAR 16:9], 50 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
      Metadata:
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.3.100 libx264
Successfully opened the file.
Parsing a group of options: output url output.mp4.
Applying option vf (alias for -filter:v (apply filters to video streams)) with argument trim=00\:00\:05:00\:00\:15,setpts=PTS-STARTPTS.
Successfully parsed a group of options.
Opening an output file: output.mp4.
[out#0/mp4 @ 0x600003f243c0] No explicit maps, mapping streams automatically...
[vost#0:0/libx264 @ 0x159605c30] Created video stream from input stream 0:0
[AVFilterGraph @ 0x600002120310] Setting 'start' to value '00'
[AVFilterGraph @ 0x600002120310] Setting 'end' to value '00'
[AVFilterGraph @ 0x600002120310] Setting 'start_pts' to value '05'
[AVFilterGraph @ 0x600002120310] Setting 'end_pts' to value '00'
[AVFilterGraph @ 0x600002120310] Setting 'duration' to value '00'
[AVFilterGraph @ 0x600002120310] Setting 'start_frame' to value '15'
[AVFilterGraph @ 0x600002120310] Setting 'expr' to value 'PTS-STARTPTS'
detected 10 logical cores
[h264 @ 0x159706f10] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x159706f10] Decoding VUI
[h264 @ 0x159706f10] nal_unit_type: 8(PPS), nal_ref_idc: 3
[file @ 0x600002121030] Setting default whitelist 'file,crypto,data'
Successfully opened the file.
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
[vost#0:0/libx264 @ 0x159605c30] Starting thread...
[vf#0:0 @ 0x600003825a70] Starting thread...
[vist#0:0/h264 @ 0x1596053c0] [dec:h264 @ 0x159705bc0] Starting thread...
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x600003620100] Starting thread...
Press [q] to stop, [?] for help
[h264 @ 0x159706f10] nal_unit_type: 6(SEI), nal_ref_idc: 0
[h264 @ 0x159706f10] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x159706f10] Format yuv420p chosen by get_format().
[h264 @ 0x159706f10] Reinit context to 192x112, pix_fmt: yuv420p
[h264 @ 0x159706f10] no picture 
[h264 @ 0x15970f930] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x15970f930] no picture 
[h264 @ 0x159718350] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x159720d70] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[h264 @ 0x159729790] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[h264 @ 0x1597321b0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x15973abd0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x1597435f0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[h264 @ 0x15974c010] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[h264 @ 0x159754a30] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x15975d450] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x159706f10] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[h264 @ 0x15970f930] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[AVFilterGraph @ 0x600002126e60] Setting 'start' to value '00'
[AVFilterGraph @ 0x600002126e60] Setting 'end' to value '00'
[AVFilterGraph @ 0x600002126e60] Setting 'start_pts' to value '05'
[AVFilterGraph @ 0x600002126e60] Setting 'end_pts' to value '00'
[AVFilterGraph @ 0x600002126e60] Setting 'duration' to value '00'
[h264 @ 0x159718350] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[AVFilterGraph @ 0x600002126e60] Setting 'start_frame' to value '15'
[AVFilterGraph @ 0x600002126e60] Setting 'expr' to value 'PTS-STARTPTS'
[h264 @ 0x159720d70] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x159729790] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[h264 @ 0x1597321b0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x15973abd0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x1597435f0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[h264 @ 0x15974c010] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[h264 @ 0x159754a30] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 0x15975d450] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[graph 0 input from stream 0:0 @ 0x600003d24a50] Setting 'video_size' to value '192x108'
[graph 0 input from stream 0:0 @ 0x600003d24a50] Setting 'pix_fmt' to value '0'
[graph 0 input from stream 0:0 @ 0x600003d24a50] Setting 'time_base' to value '1/12800'
[graph 0 input from stream 0:0 @ 0x600003d24a50] Setting 'pixel_aspect' to value '1/1'
[graph 0 input from stream 0:0 @ 0x600003d24a50] Setting 'colorspace' to value '2'
[graph 0 input from stream 0:0 @ 0x600003d24a50] Setting 'range' to value '0'
[graph 0 input from stream 0:0 @ 0x600003d24a50] Setting 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0x600003d24a50] w:192 h:108 pixfmt:yuv420p tb:1/12800 fr:25/1 sar:1/1 csp:unknown range:unknown
[format @ 0x600003d211e0] Setting 'pix_fmts' to value 'yuv420p|yuvj420p|yuv422p|yuvj422p|yuv444p|yuvj444p|nv12|nv16|nv21|yuv420p10le|yuv422p10le|yuv444p10le|nv20le|gray|gray10le'
[AVFilterGraph @ 0x600002126e60] query_formats: 5 queried, 12 merged, 0 already done, 0 delayed
[Parsed_trim_0 @ 0x600003d24bb0] TB:0.000078 FRAME_RATE:25.000000 SAMPLE_RATE:nan
[graph 0 input from stream 0:0 @ 0x600003d24a50] video frame properties congruent with link at pts_time: 0
[out_0_0 @ 0x600003d21130] EOF on sink link out_0_0:default.
[vf#0:0 @ 0x600003825a70] Filtergraph returned EOF, finishing
[vf#0:0 @ 0x600003825a70] All consumers returned EOF
[vost#0:0/libx264 @ 0x159605c30] No filtered frames for output stream, trying to initialize anyway.
[libx264 @ 0x159605f30] using mv_range_thread = 24
[libx264 @ 0x159605f30] using SAR=1/1
[libx264 @ 0x159605f30] using cpu capabilities: ARMv8 NEON
[libx264 @ 0x159605f30] profile High, level 5.2, 4:2:0, 8-bit
[libx264 @ 0x159605f30] 264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.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_me=1 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 decimate=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 keyint=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_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf61.1.100
  Stream #0:0(und), 0, 1/12800: Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 192x108 [SAR 1:1 DAR 16:9], q=2-31, 12800 tbn (default)
      Metadata:
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.3.100 libx264
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[out#0/mp4 @ 0x600003f243c0] Starting thread...
[vost#0:0/libx264 @ 0x159605c30] Encoder thread received EOF
[vost#0:0/libx264 @ 0x159605c30] Terminating thread with return code 0 (success)
[out#0/mp4 @ 0x600003f243c0] All streams finished
[out#0/mp4 @ 0x600003f243c0] Terminating thread with return code 0 (success)
[vf#0:0 @ 0x600003825a70] Terminating thread with return code 0 (success)
[vist#0:0/h264 @ 0x1596053c0] [dec:h264 @ 0x159705bc0] Decoder returned EOF, finishing
[vist#0:0/h264 @ 0x1596053c0] [dec:h264 @ 0x159705bc0] Terminating thread with return code 0 (success)
[vist#0:0/h264 @ 0x1596053c0] All consumers of this stream are done
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x600003620100] All consumers are done
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x600003620100] Terminating thread with return code 0 (success)
[AVIOContext @ 0x159766030] Statistics: 265 bytes written, 2 seeks, 3 writeouts
[out#0/mp4 @ 0x600003f243c0] Output file #0 (output.mp4):
[out#0/mp4 @ 0x600003f243c0]   Output stream #0:0 (video): 0 frames encoded; 0 packets muxed (0 bytes); 
[out#0/mp4 @ 0x600003f243c0]   Total: 0 packets (0 bytes) muxed
[out#0/mp4 @ 0x600003f243c0] video:0KiB audio:0KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown
[out#0/mp4 @ 0x600003f243c0] Output file is empty, nothing was encoded(check -ss / -t / -frames parameters if used)
frame=    0 fps=0.0 q=0.0 Lsize=       0KiB time=N/A bitrate=N/A speed=N/A    
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x600003620100] Input file #0 (input.mp4):
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x600003620100]   Input stream #0:0 (video): 31 packets read (9791 bytes); 10 frames decoded; 0 decode errors; 
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x600003620100]   Total: 31 packets (9791 bytes) demuxed
[AVIOContext @ 0x159705320] Statistics: 80830 bytes read, 2 seeks
1
  • If you want to trim using time you would have to use -ss and -to ...ffmpeg -ss 00:00:05 -to 00:00:15 -i input.mp4 Commented Jun 19 at 0:40

1 Answer 1

1

You'll have to quote and escape both.

trim='00\:00\:05':'00\:00\:15'

or double escape,

trim=00\\:00\\:05:00\\:00\\:15

4
  • Thanks, but neither of these two solution works for me (e.g., ffmpeg -y -i input.mp4 -vf trim='00\:00\:05':'00\:00\:15',setpts=PTS-STARTPTS output.mp4). I receive the same error message. What might be a reason? ffmpeg version 7.0.1
    – jsx97
    Commented Jun 19 at 6:18
  • 1
    Add -report and rerun. Share report.
    – Gyan
    Commented Jun 20 at 4:23
  • I added it to the question.
    – jsx97
    Commented Jun 20 at 9:15
  • The video itself was created using ffmpeg -y -f lavfi -r 10 -i testsrc=size=192x108:rate=1:duration=500 -vf setpts=N/10/TB -c:v libx264 -pix_fmt yuv420p input.mp4
    – jsx97
    Commented Jun 20 at 9:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .