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.
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 8 of 8
Thread
-
-
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
-
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 -
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
-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
-
Thank you very much for providing the command-line parameters with explanations.
I have three follow-up questions:- 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" ?
- 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 ?
- 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 ?
-
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.
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.
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.
Similar Threads
-
Video Editor That Allows Both Cutting on Keyframes and Viewing Waveform
By Spiralagnus in forum Newbie / General discussionsReplies: 0Last Post: 11th Jun 2022, 11:15 -
Cutting untranslated A/V movies scenes without keyframes
By ilrobbi in forum EditingReplies: 2Last Post: 21st Nov 2021, 15:45 -
Clipping Video Using FFMPEG and KeyFrames - Need More KeyFrames?
By Alan2106 in forum EditingReplies: 1Last Post: 3rd Jun 2021, 07:31 -
FFmpeg, and keyframes in vide files
By 2di in forum Video ConversionReplies: 2Last Post: 31st Jul 2020, 01:36 -
Anyone reccomend an app to show keyframes intervals?
By Djard in forum Newbie / General discussionsReplies: 12Last Post: 18th Jan 2018, 21:43