VideoHelp Forum
+ Reply to Thread
Results 1 to 8 of 8
Thread
  1. Hi,

    I would like to perform lossless trimming (with "Avidemux") on some .mp4 files downloaded from streaming sites.
    However, it is found that the keyframes of the source files are widely apart.
    The intervals between keyframes are 3-4 seconds on average.

    A friend of mine suggests using YouTube to increase the density of keyframes, i.e. upload the source .mp4 to YT and then download it back to computer.
    It is true that many keyframes have been inserted at desirable positions, and the picture quality is apparently preserved.
    Snapshots taken at different positions of the source and resultant are compared.
    They look the same to my naked eye, although the resultant bitrate is numerically reduced by a half (e.g. 2249kb/s to 1181kb/s).

    My question is: how can the same effect be achieved by using other tools, say "ffmpeg" ?
    I do not want to go YT if alternatives exist.
    Quote Quote  
  2. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Why not just re-encode it in Avidemux, since you're already used to it?
    Quote Quote  
  3. Originally Posted by davexnet View Post
    Why not just re-encode it in Avidemux, since you're already used to it?
    Thank you for the suggestion.

    I use Avidemux mostly for trimming and rarely for re-encoding.
    In fact I find it very difficult to determine the optimal parameters for the process.

    Here is the metadata (generated by "ffmpeg") of a 2 min sample video:
    Code:
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf58.76.100
      Duration: 00:02:00.13, start: 0.000000, bitrate: 2249 kb/s
        Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x544 [SAR 1:1 DAR 40:17], 2034 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 209 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    Would you kindly recommend the parameters for re-encoding ?
    Quote Quote  
  4. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    If you're doing a lot of this kind of frame accurate trimming perhaps consider something like Tmpgenc Smart Renderer. ($$ but with free trial)
    It encodes only the GOP you disturb


    Since you already occurred a quality loss by using Youtube, may as well set up Avidemux to encode the whole file,
    first make all your trims on the frames you want then set it up like this and encode the file
    Image Attached Thumbnails Click image for larger version

Name:	x264-enc.jpg
Views:	26
Size:	105.9 KB
ID:	68108  

    Quote Quote  
  5. Many thanks.

    I shall try it out on the basis of your recommendations.
    Quote Quote  
  6. Originally Posted by anctop View Post
    A friend of mine suggests using YouTube to increase the density of keyframes... My question is: how can the same effect be achieved by using other tools, say "ffmpeg" ?
    I do not want to go YT if alternatives exist.
    Youtube's reencoding is pretty low quality. You can do far better yourself with ffmpeg or any editor. But if you're going to reencode you might as well just use an editor that lets you cut at exactly the frames you want and re-encode there.

    Using ffmpeg:

    Code:
    ffmpeg -i input.mkv -c:v libx264 -preset slow -crf 18 -g 50 -c:a copy output.mkv
    -crf specifies the quality. The lower you set it the higher the quality will be. 12 is give you a video that's nearly the same as the source, even looking at enlarged still frames. 18 is pretty good, very similar to the source at normal playback speed. Youtube is far worse, equivalent to about 25.

    -g is the keyframe interval. Use whatever interval you want. More keyframes means less compression though. x264 will automatically insert keyframes at scene changes.

    If you want just a portion of the source you can use -ss to specify the starting time and -to the specify the ending time:

    Code:
    ffmpeg -i input.mkv -ss 00:00:05.000 -to 00:00:10.000 -c:v libx264 -preset slow -g 50 -crf 18  -c:a copy output.mkv
    That will encode only the segment from 5 seconds to 10 seconds.
    Quote Quote  
  7. Thank you very much for providing the command-line parameters with explanations.

    I have three follow-up questions:
    1. The "-preset slow" is a shorthand for a set of pre-defined values. How does this improve the output quality in comparison with the default "-preset medium" ?
    2. According to the ffmpeg documentation, it seems that the output quality can be controlled alternatively by the "-b" parameter. Which one of "-crf" and "-b" is the preferable approach ?
    3. You mentioned that "x264 will automatically insert keyframes at scene changes", which is exactly the feature I am looking for. As the mechanism is automatic, can I just leave out the "-g" parameter ?
    Quote Quote  
  8. Originally Posted by anctop View Post
    [*] The "-preset slow" is a shorthand for a set of pre-defined values. How does this improve the output quality in comparison with the default "-preset medium" ?
    Slow will give you slightly better quality and usually a slightly smaller file. Some settings aren't blu-ray compatible -- if that's a consideration for you.

    Originally Posted by anctop View Post
    [*] According to the ffmpeg documentation, it seems that the output quality can be controlled alternatively by the "-b" parameter. Which one of "-crf" and "-b" is the preferable approach ?
    The effect of more consecutive b-frames is pretty small once you go beyond 2 or 3 (both medium and slow use 3). crf is the better way to control quality.

    Originally Posted by anctop View Post
    [*] You mentioned that "x264 will automatically insert keyframes at scene changes", which is exactly the feature I am looking for. As the mechanism is automatic, can I just leave out the "-g" parameter ?[/LIST]
    What x264 sees as a scene change may not match your definition. For example, a crossfade will usually not be considered a scene change. So forcing a smaller GOP size will give you a safety fallback (at the cost of a larger file) if you're going to cut later. I believe there's a manual method to force keyframes too.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!