ffmpeg:在精确的时间剪切视频

ffmpeg:在精确的时间剪切视频

我正在尝试在精确的时间剪辑视频。

我尝试了以下命令:

-i file.mkv -ss 0:00 -to 6.120000 -c:v libx264 -c:a aac -f mpegts test.ts

-i file.mkv -ss 0:00 -t 6.120000 -c:v libx264 -c:a aac -f mpegts test.ts

-ss 0:00 -i file.mkv -to 6.120000 -c:v libx264 -c:a aac -f mpegts test.ts

以及所有其他与 -ss 和 -to / -t 的组合

还删除了声音:

-i file.mkv -ss 0:00 -to 6.120000 -c:v libx264 -an -f mpegts test.ts

对输出视频进行 ffprobe 后,我收到了以下时长:

duration=6.131122

我怎样才能将持续时间缩短至 6.120000?

稍后编辑:

输入流:

Input #0, matroska,webm, from 'file.mkv':
  Metadata:
    encoder         : libx264 + libebml + libmatroska + libfastrar
    creation_time   : 2017-07-17T02:02:11.000000Z
  Duration: 00:58:33.18, start: 0.000000, bitrate: 697 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709/unknown/unknown, progressive), 720x404 [SAR 1:1 DAR 180:101], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp (default)
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1001/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=720
height=404
coded_width=720
coded_height=416
has_b_frames=2
sample_aspect_ratio=1:1
display_aspect_ratio=180:101
pix_fmt=yuv420p
level=31
color_range=tv
color_space=bt709
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=progressive
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=24000/1001
avg_frame_rate=24000/1001
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]
[STREAM]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=LC
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=2
channel_layout=stereo
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]

输出

Input #0, mpegts, from 'test0.ts':
  Duration: 00:00:06.13, start: 1.483422, bitrate: 1782 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 720x404 [SAR 1:1 DAR 180:101], 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1001/48000
codec_tag_string=[27][0][0][0]
codec_tag=0x001b
width=720
height=404
coded_width=720
coded_height=416
has_b_frames=2
sample_aspect_ratio=1:1
display_aspect_ratio=180:101
pix_fmt=yuv420p
level=30
color_range=unknown
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=progressive
timecode=N/A
refs=1
is_avc=false
nal_length_size=0
id=0x100
r_frame_rate=24000/1001
avg_frame_rate=24000/1001
time_base=1/90000
start_pts=133508
start_time=1.483422
duration_ts=551801
duration=6.131122
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]

答案1

6.12 秒和 6.131 秒之间的差异不到一帧。您的视频长度必须始终为整数帧数。在帧之间剪辑视频以结束是没有意义的。

如果需要,您可以指定特定数量的帧,而不是基于时间的持续时间,-frames:v例如-frames:v 500

相关内容