Using ffmpeg to trim HEVC video: correct duration, but output file size too large
I have a digitized 8mm 16fps HEVC .mp4 that I’m trying to split into clips using ffmpeg
(5.1.2) on MacOS terminal. The output file trims to the correct duration but the filesize is too large.
ffmpeg -ss 05:09 -i input.mp4 -t 02:19 -an -sn -dn -c copy output.mp4
input.mp4
: 11:56 in duration and 8.24 GB in filesize (bitrate 674251 kbits/s).output.mp4
: 02:19 in duration and 5.15 GB in filesize (too large).
5.15 GB is the filesize I’d expect for a clip that is 05:09 + 02:19 in duration at input.mp4
‘s 674251 Kbits/s:
(05:09+02:19) * 674251 kbits/sec = 5.16 GB
I’ve tried various -ss start_pos
and -t duration
values with similar results. The output file is correctly duration
in time and unexpectedly (start_pos
+duration
)*bitrate in filesize.
I’ve consulted this ShotStack.io article on trimming with ffmpeg
and this ffmpeg wiki section on cutting small sections from files. Neither specifically states that the resulting file size will be trimmed to match the duration of the clip, but I’d think that’d be useful.
Addendum:
My input file has only one keyframe at t=0.000s. Likely the root of all my problems.
ffmpeg stdout:
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x14ff04760] Using non-standard frame rate 16384/1024
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
creation_time : 2021-07-24T11:23:44.000000Z
encoder : Lavf58.45.100
Duration: 00:11:56.13, start: 0.000000, bitrate: 92041 kb/s
Stream #0:0[0x1](und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709/bt709/unknown, progressive), 5120x3840 [SAR 1:1 DAR 4:3], 91715 kb/s, 16 fps, 16 tbr, 16384 tbn (default)
Metadata:
creation_time : 2021-07-24T11:23:44.000000Z
handler_name : VideoHandler
vendor_id : [0][0][0][0]
timecode : 17:15:11:05
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 159 kb/s (default)
Metadata:
creation_time : 2021-07-24T11:23:44.000000Z
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 159 kb/s (default)
Metadata:
creation_time : 2021-07-24T11:23:44.000000Z
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:3[0x4](eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 2021-07-24T11:23:44.000000Z
handler_name : TimeCodeHandler
timecode : 17:15:11:05
File 'output.mp4' already exists. Overwrite? [y/N] y
[mp4 @ 0x14ff08660] Using non-standard frame rate 16/1
Last message repeated 1 times
Output #0, mp4, to 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf59.27.100
Stream #0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709/bt709/unknown, progressive), 5120x3840 [SAR 1:1 DAR 4:3], q=2-31, 91715 kb/s, 16 fps, 16 tbr, 16384 tbn (default)
Metadata:
creation_time : 2021-07-24T11:23:44.000000Z
handler_name : VideoHandler
vendor_id : [0][0][0][0]
timecode : 17:15:11:05
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 4290 fps=0.0 q=-1.0 Lsize= 2988507kB time=00:02:18.93 bitrate=176207.6kbits/s speed= 189x
video:2988420kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.002924%
ffprobe output.mp4
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x130804080] Using non-standard frame rate 16384/1024
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf59.27.100
Duration: 00:02:19.31, start: 0.000000, bitrate: 175732 kb/s
Stream #0:0[0x1](und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709/bt709/unknown, progressive), 5120x3840 [SAR 1:1 DAR 4:3], 91304 kb/s, 16 fps, 16 tbr, 16384 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
timecode : 17:15:11:05
Stream #0:1[0x2](eng): Data: none (tmcd / 0x64636D74)
Metadata:
handler_name : VideoHandler
timecode : 17:15:11:05
Unsupported codec with id 0 for input stream 1
Read more here: Source link