6

I have tried to cut video with the following command

ffmpeg -i "Вспомнить все (Total Recall, 1990).avi"  -ss 01:07:29 -to 01:08:05 fight.avi

Output:

Input #0, avi, from '╨Т╤Б╨┐╨╛╨╝╨╜╨╕╤В╤М ╨▓╤Б╨╡ (Total Recall, 1990).avi':
  Metadata:
    encoder         : VirtualDubMod 1.5.10.2 (build 2540/release)
    artist          : Menen
  Duration: 01:53:33.69, start: 0.000000, bitrate: 3660 kb/s
    Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 704x384 [SAR 1:1 DAR 11:6], 2295 kb/s, 23.98 fps, 23.98 tbr, 23.
98 tbn, 23.98 tbc
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:2: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:3: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
File 'fight.avi' already exists. Overwrite ? [y/N] y
Output #0, avi, to 'fight.avi':
  Metadata:
    IART            : Menen
    ISFT            : Lavf55.43.100
    Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 704x384 [SAR 1:1 DAR 11:6], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc
    Metadata:
      encoder         : Lavc55.67.100 mpeg4
    Stream #0:1: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp
    Metadata:
      encoder         : Lavc55.67.100 libmp3lame
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (ac3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
frame=  863 fps= 20 q=31.0 Lsize=    2690kB time=00:00:36.00 bitrate= 612.1kbits/s
video:2061kB audio:563kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.500957%

The resulting video has obviously worse quality, with apparent big MPEG squares visible

Why?

How to avoid?

UPDATE

Even if re-encoding, then why so drastical change? Can we re-encode so that it will be nearly invisible degrading of quality?

UPDATE 2

I guess if I use -codec copy then I will be unable to cut at precise moment. Moment precision is a priority. So I agree with quality loss but it should not be so drastical.

1
  • I don't think ffmpeg supports this, but you can get nearly the best of both options by using the original stream (-codec copy) from the nearest keyframe, and re-encoding only the frames between the cut-point and that keyframe. This only works if you have an encoder that can produce output compatible with the original stream, but you can use a high bitrate for the short segment to avoid quality loss. Commented Apr 16, 2015 at 8:14

2 Answers 2

10

Re-muxing only

Use stream copy mode to just re-mux instead of re-encode:

ffmpeg -ss 01:07:29 -i input -codec copy -map 0 -to 01:08:05 fight.avi
  • Using -ss as an input option can be faster than using it as an output option, but it may not be as accurate.

  • -codec copy will stream copy (no re-encoding). Default behavior, if -codec copy is omitted, is to re-encode, and as you've noticed the default encoding settings for most encoders are not optimal (they used to be a decade ago).

  • Default stream selection is to select only one stream per stream type (video, audio, subtitles, data, etc). -map 0 will ensure all streams are copied in case there are multiples of each type. That being said, your input only has two different streams, so it is actually not needed here.

  • Development of ffmpeg is very active, so it is important to use a recent build if possible. See the FFmpeg Download page for several options.


If you must re-encode

-crf

You can target a "visually lossless" quality level using the encoder libx264 with the -crf option. CRF is just about as close as you can get to a "constant quality" option: 0 is lossless (but usually results in huge files), ~18 is usually considered to be visually lossless or nearly so, 23 is the default, and 51 is worst.

-preset

The encoding speed to compression (quality per file size) ratio. Basically use the slowest preset you have patience for: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow.

ffmpeg -i input -codec:v libx264 -crf 23 -preset medium -ss 01:07:29 -to 01:08:05 output

Also see

3

You are re-encoding the video rather than cutting out a portion of the stream. Any re-encode is going to produce quality loss, particularly when you cut the data rate to less than 1/11th of the original data rate.

If you want to cut out a portion of the video, you need to use a tool like VirtualDUB to actually extract a portion of the actual video stream and put it in a new container without re-encoding. Note that there will be limitations to where you can cut like this since you will need to start at the beginning of a group of pictures.

8
  • 1
    Where am I cutting data rate to 1/11th?
    – Dims
    Commented Jun 19, 2014 at 17:00
  • 1
    Your input stream is 2295 kb/s. Your output stream is 200 kb/s. It is probably a default setting since you aren't specifying a bitrate.
    – AJ Henderson
    Commented Jun 19, 2014 at 17:02
  • Can I just conserve bitrate?
    – Dims
    Commented Jun 19, 2014 at 17:03
  • I mean that copy operation may cut at inprecise moments
    – Dims
    Commented Jun 19, 2014 at 17:04
  • 1
    If you really want to re-encode rather than stream copy (stream copy would likely be accurate to within half a second), then you could probably preserve quality pretty well if you try somewhere around 3,000 or 3,500 kb/s for your encoding. I'd try starting there and play around with some different data rates to find the best trade off between file size and video quality.
    – AJ Henderson
    Commented Jun 19, 2014 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.