Search code examples
videoffmpeg

Accurately cut an .mp4 with ffmpeg without losing audio fidelity?


I'm trying to find a way of accurately cutting an .mp4 with ffmpeg. As I understand, it will need to be re-encoded to get around the issue of keyframes. I know the video quality can be set to lossless with '-crf 0', but is there a means of doing this with the audio as well? The best attempt I have pieced together is this:

ffmpeg -ss 0 -i input.mp4 -t 23 -c:v libx264 -c:a aac -b:a 320k -strict experimental -preset ultrafast -crf 0 output.mp4

I'm not too bothered about file size either. Thanks for any help.

UPDATE using ffmpeg 3.2.5

This produces a 13 second output video:

ffmpeg -ss 00:00:03 -i input.mp4 -t 10 -c:v libx264 -c:a copy -crf 0 -preset ultrafast output.mp4

This produces a 10 second output (what I'm looking for) but without re-encoded audio:

ffmpeg -ss 00:00:03 -i input.mp4 -t 10 -c:v libx264 -crf 0 -preset ultrafast output.mp4

ANOTHER UPDATE

I don't think this is possible, so as Brad suggested, I will look into using .mkv with VP9 encoding and PCM audio.


Solution

  • As I understand, it will need to be re-encoded to get around the issue of keyframes.

    That's correct, and AAC audio has a framing problem as well.

    If you want lossless audio, you need to use a codec that supports lossless audio. I'd recommend FLAC.