FFmpeg转封装(6)

2019-01-23  本文已影响3人  Goning

FFmpeg使用ss与t参数进行切片


1.使用ss指定剪切开头部分

从一个视频文件的第10秒钟开始截取内容

ffmpeg -ss 10 -i 222.mp4 -c copy output.ts

使用ffprobe分别获取222.mp4与output.ts文件的duration并进行对比

aiputekiMacBook-Pro:bin aipu$ ffprobe -v quiet -show_format 222.mp4 |grep duration; ffprobe -v quiet -show_format output.ts |grep duration
duration=30.316000
duration=21.223022

2.使用t指定视频总长度
ffmpeg -i 222.mp4 -c copy -t 10 -copyts output.mp4 

查看222.mp4与output.mp4的起始时间与长度相关信息

aiputekiMacBook-Pro:bin aipu$ ffprobe -v quiet -show_format 222.mp4 |grep start_time; ffprobe -v quiet -show_format output.mp4 |grep start_time
start_time=0.000000
start_time=0.000000
aiputekiMacBook-Pro:bin aipu$ ffprobe -v quiet -show_format 222.mp4 |grep duration; ffprobe -v quiet -show_format output.mp4 |grep duration
duration=30.316000
duration=10.080000

3.使用output_ts_offset指定输出start_time
ffmpeg -i 222.mp4 -c copy -t 10 -output_ts_offset 120 output.mp4
aiputekiMacBook-Pro:bin aipu$ ffprobe -show_format output.mp4 
ffprobe version 4.1 Copyright (c) 2007-2018 the FFmpeg developers
  built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
  configuration: 
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:10.08, start: 119.962993, bitrate: 418 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], 282 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[FORMAT]
filename=output.mp4
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=119.962993
duration=10.080000
size=526813
bit_rate=418105
probe_score=100
TAG:major_brand=isom
TAG:minor_version=512
TAG:compatible_brands=isomiso2avc1mp41
TAG:encoder=Lavf58.20.100
[/FORMAT]

上一篇 下一篇

猜你喜欢

热点阅读