Lossless video trimming with milliseconds using FFMPEG

AngryCubeDev

I've spent a few weeks going through and testing all the answers on here for lossless cutting using FFMPEG on Android. No matter what I try I always get loss. In the app we're building we need to be millisecond precise.

I've tried so many variations of the command with a lot of them being more than half a second off. This is for both copy and re-encoding. With this i have tried the -ss before and after as well as in both positions but I don't see any difference. These are the two commands that have worked the best be still not close enough:

//copy
"-ss $startTime -t $endTime -i $input -f segment -c copy $output"

//encode
"-i $input -ss $startTime -c:v libx264 -crf 12 -preset ultrafast -t $endTime $output"

Has anyone used a command or even other library that has given more accurate results?

AngryCubeDev

After looking for days the closest I've come to millisecond precise trimming in FFMPEG is with the following command:

"-ss $startCutTime -i $inputFilePath -ss 0 -c copy -to $endCutTime -avoid_negative_ts make_zero $outputFilePath"

This command is precise to about a 20th of a millisecond with a 30fps clip but this will all depend on the frame rate of your video. I hope this helps others out. Here's an explanation of what each component does:

/**
     * FFMPEG Cmd Structure
     * -i: Input file
     * -ss: If this is placed before the input file it seeks to this position in the input file. If it's after the input it will split from that exact position.
     * -to: The position of where the command is going to cut to.
     * -c copy: This copies the video and audio codecs as they are for speed.
     * -avoid_negative_ts make_zero: Sets the first timestamp as 0
     * The times are passed in parsed eg 00:00:10.456
     * The output file is the last part of the command
     */

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Lossless Video Streaming with FFmpeg

From Dev

Producing lossless video from set of .png images using ffmpeg

From Dev

Video file not trimming and copying using FFMpeg in C#

From Dev

Converting RGB images into lossless video with avconv / ffmpeg

From Dev

lossless video using FFmpeg ffv1 on jpeg images is not compressed but expanded

From Dev

trimming audio and video with ffmpeg and filter_complex

From Dev

FFMPEG Lossless

From Dev

Trimming videos using FFMPEG + Python: Invalid Argument

From Dev

FFMPEG: embed current time in milliseconds into video

From Dev

ffmpeg video editing command in milliseconds timestamp

From Dev

FFMpeg - Trimming out the video after removing duplicate frames

From Dev

Using a lossless video codec for archiving (monochrome) scientific video data

From Dev

How to convert videos to AV1 lossless using FFmpeg?

From Dev

Lossless audio conversion from FLAC to ALAC using ffmpeg

From Dev

Visually lossless 1080p to 720p using ffmpeg

From Dev

Lossless VOB conversion with ffmpeg

From Dev

python datetime calculation not trimming to milliseconds

From Dev

Lossless video compression codecs

From Dev

Lossless video editing on Linux?

From Dev

Video padding using ffmpeg

From Dev

How can I change a video frame rate with FFmpeg, lossless and keeping the same total number of frames?

From Dev

Script for trimming with ffmpeg

From Dev

Android video trimming library

From Dev

trimming the start and end of a video

From Dev

Equivalent FFMPEG command with lossless clip

From Dev

Delayed video overlay using FFmpeg

From Dev

storing and securing the video using ffmpeg

From Dev

using ffmpeg to display video on iPhone

From Dev

Invert colors of a video using FFMPEG

Related Related

  1. 1

    Lossless Video Streaming with FFmpeg

  2. 2

    Producing lossless video from set of .png images using ffmpeg

  3. 3

    Video file not trimming and copying using FFMpeg in C#

  4. 4

    Converting RGB images into lossless video with avconv / ffmpeg

  5. 5

    lossless video using FFmpeg ffv1 on jpeg images is not compressed but expanded

  6. 6

    trimming audio and video with ffmpeg and filter_complex

  7. 7

    FFMPEG Lossless

  8. 8

    Trimming videos using FFMPEG + Python: Invalid Argument

  9. 9

    FFMPEG: embed current time in milliseconds into video

  10. 10

    ffmpeg video editing command in milliseconds timestamp

  11. 11

    FFMpeg - Trimming out the video after removing duplicate frames

  12. 12

    Using a lossless video codec for archiving (monochrome) scientific video data

  13. 13

    How to convert videos to AV1 lossless using FFmpeg?

  14. 14

    Lossless audio conversion from FLAC to ALAC using ffmpeg

  15. 15

    Visually lossless 1080p to 720p using ffmpeg

  16. 16

    Lossless VOB conversion with ffmpeg

  17. 17

    python datetime calculation not trimming to milliseconds

  18. 18

    Lossless video compression codecs

  19. 19

    Lossless video editing on Linux?

  20. 20

    Video padding using ffmpeg

  21. 21

    How can I change a video frame rate with FFmpeg, lossless and keeping the same total number of frames?

  22. 22

    Script for trimming with ffmpeg

  23. 23

    Android video trimming library

  24. 24

    trimming the start and end of a video

  25. 25

    Equivalent FFMPEG command with lossless clip

  26. 26

    Delayed video overlay using FFmpeg

  27. 27

    storing and securing the video using ffmpeg

  28. 28

    using ffmpeg to display video on iPhone

  29. 29

    Invert colors of a video using FFMPEG

HotTag

Archive