Stabilizing, transcoding and melt — what's the best way?

Sorry if I post this in the wrong place, the question is mostly to do with melt.

I am shooting some Full HD videos on Samsung Galaxy Note android phone and using Kdenlive to edit. I shoot around 50 one- or two-minute videos for each project. Since I'm filming it with a phone, it's shaky and I definitely want to use a stabilizer. I've tried vstab and it crashes Kdenlive too often (as far as I can see this currently is a confirmed open bug). I've done one project with videostab2 (aka transcode stabilizer), it's faster on most settings, it's more stable but it doesn't look as good as the first vstab filter.

So, I've decided I'll go on and transcode clips with stabilization using melt while vstab in melt is not stable enough to use in Kdenlive in real time.

Now, this turns out to be not so easy. Maybe someone will suggest a good way to do this, or at least fix the method I've ended up with.

Basically I do stabilizing with this script (sorry, don't know how to do formatting in the posts, any bbcode?):

MLT_FILE=`basename $SOURCE_FILE`.mlt
if [ ! -f $MLT_FILE ] ; then
melt -profile atsc_1080p_30 -verbose $SOURCE_FILE -filter videostab shutterangle=20 -consumer xml:$MLT_FILE all=1 real_time=-2;
if [ ! -f $RENDER_FILE ] ; then
melt -profile atsc_1080p_30 -verbose $MLT_FILE -consumer avformat:$RENDER_FILE vcodec=libx264 acodec=pcm_s16le real_time=-2 threads=3 frame_rate_num=30 frame_rat

This gives me an x264-encoded video with pcm audio in FullHD resolution. Well, sort of. The first problem is the frame rate. Ideally I would like to encode to the same frame rate as the source clip is (the same wish goes to Kdenlive projects, by the way). Galaxy Note creates videos with some weird framerate, sligtly less than 30 fps and even less than 30000/1001 fps (I'll post details below; turns out it varies from clip to clip). Is there are way I can get the framerate intact? The second problem is that mplayer shows me "Movie-Aspect is 1.78:1 - prescaling to correct movie aspect" message — at first I thought that my videos have non-square pixels; but after double-checking it seems that it's not the case — so actually there's no "second problem". The third problem is that I seem to either get audio truncated at the end or it slowly goes out of sync as clip time goes; that is, if I get this clip into Kdenlive I can visually see some one second of silence at the end of the audio track preview.

Why I reencode to x264? Well, I've tried DNxHD, but I couldn't get good results. It's very hard to get encoder's options correct. And the bitrate is very very high.

Now, some details. Here is ffprobe of stabilized clip:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '':
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf54.29.104
Duration: 00:00:53.66, start: 0.000000, bitrate: 21039 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 19543 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc
handler_name :
Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, 2 channels, s16, 1536 kb/s
handler_name :

Here's ffprobe on the original, notice the tbr & fps values:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '../20121212_195422.mp4':
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2012-12-12 16:55:19
Duration: 00:00:53.70, start: 0.000000, bitrate: 17123 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 16992 kb/s, 29.98 fps, 30.08 tbr, 90k tbn, 180k tbc
creation_time : 2012-12-12 16:55:19
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 126 kb/s
creation_time : 2012-12-12 16:55:19
handler_name : SoundHandle

Here's mplayer output on the original, again, note the fps:

Playing ../20121212_195422.mp4.
libavformat version 53.32.100 (external)
libavformat file format detected.
[lavf] stream 0: video (h264), -vid 0
[lavf] stream 1: audio (aac), -aid 0, -alang eng
VIDEO: [H264] 1920x1080 24bpp 30.083 fps 16992.5 kbps (2074.3 kbyte/s)
Clip info:
major_brand: isom
minor_version: 0
compatible_brands: isom3gp4
creation_time: 2012-12-12 16:55:19
Load subtitles in ../

If I view the clip's properties in Kdenlive, I get some other numbers. I've also just found that is varies from clip to clip.

Hi dan

I havn't tried what you want but if you have trouble because of the format you could try to convert the original to DN&HD first. It should actually work well because from Avid it is a recommended format for editing. I have committed some DN&HD profiles for kdenlive in the render section but they are not approved. My own tests however worked quite well.

I think your source is 29.97 (NTSC) progressive video. It uses the X264 codec at a not so high bitrate. Try to uses this profile to convert to DN&HD

Lossless / HQ
File extension:
Avformat parameters:
f=mov mlt_profile=atsc_1080p_2997 vb=145M vcodec=dnxhd acodec=pcm_s16le ar=48000k ac=2

Kind regards,

Thanks, zebulon, I'll give DNxHD one more shot, however bitrate is huge — I don't think I can really afford it on a regular basis.