[FFmpeg-user] cutting mp4 with ffmpeg

Andrew Randrianasulu randrianasulu at gmail.com
Sat Jan 13 20:49:41 EET 2024


On Sat, Jan 13, 2024 at 9:22 PM DEF <shaker.doc at gmail.com> wrote:
>
> On Sat, 13 Jan 2024 at 19:09, Andrew Randrianasulu
> <randrianasulu at gmail.com> wrote:
> >
>
> >
> > also
> >
> > /dev/shm/ffmpeg/ffmpeg -i /dev/shm/6029_cut_2.mp4 -vf showinfo -f null
> > /dev/null
> >
> > last lines were
> >
> > [Parsed_showinfo_0 @ 0xee202580] n:1612 pts:5803200 pts_time:64.48
> > duration:      0 duration_time:0       fmt:yuv420p cl:left sar:0/1
> > s:720x400 i:P iskey:0 type:B checksum:498D7D18
> > plane_checksum:[7C011A9A 72D078F0 1749E97F] mean:[84 158 80]
> > stdev:[10.1 3.4 8.2]
> > [Parsed_showinfo_0 @ 0xee202580] color_range:tv color_space:smpte170m
> > color_primaries:smpte170m color_trc:bt709
> > [Parsed_showinfo_0 @ 0xee202580] n:1613 pts:5806800 pts_time:64.52
> > duration:      0 duration_time:0       fmt:yuv420p cl:left sar:0/1
> > s:720x400 i:P iskey:0 type:B checksum:FB6C528A
> > plane_checksum:[BC0C2674 7A2A71F8 E2E7BA0F] mean:[84 158 80]
> > stdev:[10.1 3.3 8.1]
> > [Parsed_showinfo_0 @ 0xee202580] color_range:tv color_space:smpte170m
> > color_primaries:smpte170m color_trc:bt709
> > [Parsed_showinfo_0 @ 0xee202580] n:1614 pts:5810400 pts_time:64.56
> > duration:      0 duration_time:0       fmt:yuv420p cl:left sar:0/1
> > s:720x400 i:P iskey:0 type:P checksum:32E560F5
> > plane_checksum:[237A0A01 F76B8D20 1D72C9C5] mean:[84 158 80]
> > stdev:[10.1 3.2 8.0]
> > [Parsed_showinfo_0 @ 0xee202580] color_range:tv color_space:smpte170m
> > color_primaries:smpte170m color_trc:bt709
> > [Parsed_showinfo_0 @ 0xee202580] n:1615 pts:5814000 pts_time:64.6
> > duration:      0 duration_time:0       fmt:yuv420p cl:left sar:0/1
> > s:720x400 i:P iskey:1 type:I checksum:C9E56CD5
> > plane_checksum:[1254795B 75287B1F 720B784C] mean:[83 158 80]
> > stdev:[10.1 3.0 7.8]
> > [Parsed_showinfo_0 @ 0xee202580] color_range:tv color_space:smpte170m
> > color_primaries:smpte170m color_trc:bt709
> > [Parsed_showinfo_0 @ 0xee202580] n:1616 pts:5828400 pts_time:64.76
> > duration:      0 duration_time:0       fmt:yuv420p cl:left sar:0/1
> > s:720x400 i:P iskey:0 type:P checksum:07418607
> > plane_checksum:[A672B48D A7D7BD5B 3D4D1410] mean:[83 158 79]
> > stdev:[9.7 2.3 7.0]
> > [Parsed_showinfo_0 @ 0xee202580] color_range:tv color_space:smpte170m
> > color_primaries:smpte170m color_trc:bt709
> > [out#0/null @ 0xbf59800] video:543kB audio:12112kB subtitle:0kB other
> > streams:0kB global headers:0kB muxing overhead: unknown
> > frame= 1617 fps=493 q=-0.0 Lsize=N/A time=00:01:04.61 bitrate=N/A speed=19.7x
> >
> >
> > doesn't this mean ffmpeg cut one frame too much ?
>
> Yes it will and it could.
> As long as you are not encoding the video, ffmpeg will cut at the
> nearest iframes.
> If you are particular then you need to re-encode the video.
>
> /dev/shm/ffmpeg/ffmpeg -i ~/6029.mp4   -c:v libx264 -c:a pcm_s16le
> -t 64.600 /dev/shm/6029_cut_2.mp4
>
> avoid using "-to" in the place of "-t" like i explained.
>
> if you must not reencode and you want to use copyts then you must add
> the option
> "-avoid_negative_ts make_zero"  after your copyts.

bash-5.1$ /dev/shm/ffmpeg/ffmpeg -i ~/6029.mp4  -copyts
-avoid_negative_ts make_zero -c:v copy -c:a pcm_s16le -to 64.600
/dev/shm/6029_cut_2.mp4
ffmpeg version N-112149-ga87a52ed0b Copyright (c) 2000-2024 the FFmpeg
developers
  built with gcc 11.2.0 (GCC)
  configuration:
  libavutil      58. 36.101 / 58. 36.101
  libavcodec     60. 37.100 / 60. 37.100
  libavformat    60. 20.100 / 60. 20.100
  libavdevice    60.  4.100 / 60.  4.100
  libavfilter     9. 17.100 /  9. 17.100
  libswscale      7.  6.100 /  7.  6.100
  libswresample   4. 13.100 /  4. 13.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/guest/6029.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2011-06-24T09:52:37.000000Z
    encoder         : HandBrake 0.9.5 2011043000
  Duration: 01:28:31.60, start: 0.000000, bitrate: 789 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661),
yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 720x400, 657
kb/s, 25 fps, 25 tbr, 90k tbn (default)
      Metadata:
        creation_time   : 2011-06-24T09:52:37.000000Z
        vendor_id       : [0][0][0][0]
        encoder         : JVT/AVC Coding
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000
Hz, stereo, fltp, 127 kb/s (default)
      Metadata:
        creation_time   : 2011-06-24T09:52:37.000000Z
        vendor_id       : [0][0][0][0]
File '/dev/shm/6029_cut_2.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, mp4, to '/dev/shm/6029_cut_2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf60.20.100
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661),
yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 720x400, q=2-31,
657 kb/s, 25 fps, 25 tbr, 90k tbn (default)
      Metadata:
        creation_time   : 2011-06-24T09:52:37.000000Z
        vendor_id       : [0][0][0][0]
        encoder         : JVT/AVC Coding
  Stream #0:1(und): Audio: pcm_s16le (ipcm / 0x6D637069), 48000 Hz,
stereo, s16, 1536 kb/s (default)
      Metadata:
        creation_time   : 2011-06-24T09:52:37.000000Z
        vendor_id       : [0][0][0][0]
        encoder         : Lavc60.37.100 pcm_s16le
[out#0/mp4 @ 0xba48200] video:5803kB audio:12112kB subtitle:0kB other
streams:0kB global headers:0kB muxing overhead: 0.205723%
size=   17952kB time=-00:05:35.50 bitrate=N/A speed=N/A
bash-5.1$ /dev/shm/ffmpeg/ffprobe  /dev/shm/6029_cut_2.mp4
ffprobe version N-112149-ga87a52ed0b Copyright (c) 2007-2024 the
FFmpeg developers
  built with gcc 11.2.0 (GCC)
  configuration:
  libavutil      58. 36.101 / 58. 36.101
  libavcodec     60. 37.100 / 60. 37.100
  libavformat    60. 20.100 / 60. 20.100
  libavdevice    60.  4.100 / 60.  4.100
  libavfilter     9. 17.100 /  9. 17.100
  libswscale      7.  6.100 /  7.  6.100
  libswresample   4. 13.100 /  4. 13.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/dev/shm/6029_cut_2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf60.20.100
  Duration: 00:01:04.68, start: 0.080000, bitrate: 2273 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661),
yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 720x400, 734
kb/s, 25 fps, 25 tbr, 90k tbn (default)
      Metadata:
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
        encoder         : JVT/AVC Coding
  Stream #0:1[0x2](und): Audio: pcm_s16le (ipcm / 0x6D637069), 48000
Hz, stereo, s16, 1536 kb/s (default)
      Metadata:
        handler_name    : SoundHandler
        vendor_id       : [0][0][0][0]

but mpv still ends at

mpv /dev/shm/6029_cut_2.mp4
 (+) Video --vid=1 (*) (h264 720x400 25.000fps)
 (+) Audio --aid=1 (*) ( 2ch 48000Hz)
Failed to initialize a decoder for codec ''.
Audio: no audio
VO: [gpu] 720x400 yuv420p
V: 00:01:04.840 / 00:01:04.880 (100%)


>
> DEF
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-user mailing list