Search code examples
ffmpegvideo-processing

Change mp4 video duration using FFMPEG


I'm trying to alter the video duration using FFMPEG. I do not believe this is associated with metadata but rather is encoded at the start of the video somehow. Would anyone know if it is possible to alter this value..?

 Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : “test_title"
    encoder         : Lavf55.19.104
 Duration: 00:57:51.81, start: 0.000000, bitrate: 1289 kb/s
 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 1157 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
 Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)

thanks


Solution

  • There is actually a post on their wiki: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video

    Quoting:

    Speeding up/slowing down video

    You can change the speed of your video using setpts video filter. [...]

    To speed up your video, you can type:

    ffmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv
    

    Note that this method will drop frames to achieve your desired speed. You can avoid dropping frames by specifying a higher "output frame rate" than the input, for example, to go from an input of 4 to one that is sped up to 4x that (16 fps):

    ffmpeg -i input.mkv -r 16 -filter:v "setpts=0.25*PTS" -an output.mkv
    

    To slow down your video, you have to use a multiplier greater than 1:

    ffmpeg -i input.mkv -filter:v "setpts=2.0*PTS" output.mkv