PDA

View Full Version : Recompressing Videos with ffmpeg, h264, jerking movements (slow pans)


auroraglacialis
8th August 2008, 08:56
Hi.
I am trying to reduce the amount of disk space used by some archived videos I have here by recompressing them with ffmpeg and h264/x264 on a gentoo linux. However, when I do this, I get strange jerking movements in the resulting video, especially with slow pans and zooms (Like a video of a landscape that is filmed by turning 180° to film the panorama). I noted, that the jerking seems to happen on each keyframe or at least in intervals that are roughly the minimum keyframe interval.

Here is my command line:

ffmpeg -y -threads 2 -i "$FILENAME" -acodec copy $ABITRATE -pass 1 -vcodec h264 -b $VBITRATE -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -flags2 +brdo+dct8x8+wpred+bpyramid+mixed_refs -me full -subq 7B -trellis 2 -refs 6 -bf 8 -directpred 3 -b_strategy 1 -bidir_refine 1 -coder 1 -me_range 16 -g 500 -keyint_min 25 -bt 4000k -r 25 "$FILENAME".$VBITRATE.recompress.avi

ffmpeg -y -threads 2 -i "$FILENAME" -acodec $ACODEC $ABITRATE -pass 2 -vcodec h264 -b $VBITRATE -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -flags2 +brdo+dct8x8+wpred+bpyramid+mixed_refs -me full -subq 7B -trellis 2 -refs 6 -bf 8 -directpred 3 -b_strategy 1 -bidir_refine 1 -coder 1 -me_range 16 -g 500 -keyint_min 25 -bt 4000k -r 25 "$FILENAME".$VBITRATE.recompress.avi

ACODEC is libmp3lame, VCODEC is h264, ABITRATE is 112, VBITRATE is 500k

I tried different settings and read
http://avidemux.org/admWiki/index.php?title=H264
and http://rob.opendot.cl/index.php/useful-stuff/x264-to-ffmpeg-option-mapping/

Can someone tell me how to improve this?
The target are videos of approx. 45-60 min. The result should be about 200M in size and be viewable on a traditional PAL TV.

Thanks
Aurora

DarkZell666
8th August 2008, 09:04
It might be a framerate conversion problem. The fact you spotted a "somewhere near the keyint-min interval" could also mean a "somewhere near the framerate value" since you have both at the same value of 25 ;)

What framerates are the original files ? If they aren't 25, then you have your explanation : framerate conversion always gives jerky movements unless it's motion-compensated, and ffmpeg doesn't do that sort of thing.

You'd need an avisynth script to do that properly. Otherwise, you can simply remove the -r 25 and let ffmpeg use the same framerate as the source file, unless you have a specific reason to use that option of course :)

dat720
8th August 2008, 10:25
Only real reason to retain 25fps would be if he was creating PAL DVD content, highly unlikely tho seens it's h264, i agree with DarkZell666 stick with the orignal framrate.

auroraglacialis
8th August 2008, 23:14
Hi.

I used the framerate, because I read somewhere else, that a wrong framerate can lead to these jerky movements on a PAL video. I am compressing the videos for a PAL TV. Originally I did not specify this and got jerky movements, so I tried this option in the hope to correct this (playing a 29 fps video on a 25fps TV set), but the problem seems to be rather worse than better with that option :-(
I'll try to switch it off again and see if the other options will do any good then.

about that mentioned script for avisynth - is that something I can do in Linux and run from the command line???

Ciao
Aurora

dat720
8th August 2008, 23:57
AVISynth must be run from wine in linux, can be cumbersome and slow.

Gusar
9th August 2008, 12:03
AVISynth must be run from wine in linux, can be cumbersome and slow.Why slow? Well, maybe a little, but not much. But, there are also cases where games run faster via wine than on Windows. And it's not cumbersome at all, if you're not a stranger to the command line.

dat720
9th August 2008, 12:27
I wasn't talking about games.....

And it can be tricky to get AVIsynth working properly in linux...

setarip_old
9th August 2008, 20:13
@auroraglacialis

Hi!...recompressing them with ffmpeg and h264/x264...I am compressing the videos for a PAL TV.May I ask how you are planning on playing H264/X264 video on your TV?

auroraglacialis
12th August 2008, 16:00
I replay Videos via Mplayer or VLC on a Gentoo Linux. The PC is connected to the TV. I use the PC for almost all media purposes (Music, Video, TV, DVD).

dat720
13th August 2008, 07:33
You won't need to do a frame rate conversion if you are playing back from PC.

DarkZell666
13th August 2008, 17:17
Originally I did not specify this and got jerky movements, so I tried this option in the hope to correct this (playing a 29 fps video on a 25fps TV set), but the problem seems to be rather worse than better with that option :-(
If the the original video is jerky, you'll need an avisynth script based on mvtools (http://forum.doom9.org/showthread.php?t=84770&highlight=mvtools) plugin (I think ?) to smooth the pans out. There are two functions named MvFlow and MvFlowFPS that might fix this for you.

RickA
14th August 2008, 03:16
Greets,

You mentioned "playing a 29 fps video on a 25fps TV" sounds like you are trying to convert NTSC to PAL. In such a case you may wish to look into IVTC (Inverse Telecine) and Decimate functions. Good luck with that, can be tricky stuff. I doubt you will be able to get the converted to 25fps to play as smoothly as the 29fps source you have.

I tried unsuccessfully to get my original PAL broadcast TV source material that was converted to NTSC DVD back to it's original 25fps and to play smoothly. Ended up keeping them at 29i. I have no problems converting film back to it's source of 24fps and playing properly. Just can't hit the 25 mark fluidly, yet.

Cheers,
Rick

DarkZell666
14th August 2008, 09:50
I have no problems converting film back to it's source of 24fps and playing properly. Just can't hit the 25 mark fluidly, yet.

Any reason you don't want to convert it to 24fps and then speed it up to 25fps ? You'd need to stretch the audio, but the difference for 1fps isn't as noticeable as for 5fps :p

rkalwaitis
14th August 2008, 12:13
Is there a way that I can type in my command prompts via ffmpeg and findout the command options available to a certain codec?

rkalwaitis
14th August 2008, 19:20
I was hoping someone could explain to me lmin and lmax in regards to mencoder or ffmpeg for video compression. Maybe a little example.

I just need someplace to start.

thanks

auroraglacialis
31st August 2008, 11:53
Ok, I skipped the framerate conversion part. It was of course rather nonsense, since I play back the video on the PC. Wouldn't make sense anyway, since the original video is a different framerate and plays fine. So it must be something else. It seems, that the jerky movements are connected to the keyframes. If I change the keyframe interval, it seems to have an influence on the frequency of the jerky movements.

So cirrently I have the following code:
nice -n 18 ffmpeg -y -threads 2 -i "$FILENAME" -acodec $ACODEC $ABITRATE -pass 1 -vcodec h264 -b $VBITRATE -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -flags2 +brdo+dct8x8+wpred+bpyramid+mixed_refs -me full -subq 7B -trellis 2 -refs 6 -bf 8 -directpred 3 -b_strategy 1 -bidir_refine 1 -coder 1 -me_range 16 -g 500 -keyint_min 12 -bt 4000k "$FILENAME".$VBITRATE.recompress.avi

nice -n 18 ffmpeg -y -threads 2 -i "$FILENAME" -acodec $ACODEC $ABITRATE -pass 2 -vcodec h264 -b $VBITRATE -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -flags2 +brdo+dct8x8+wpred+bpyramid+mixed_refs -me full -subq 7B -trellis 2 -refs 6 -bf 8 -directpred 3 -b_strategy 1 -bidir_refine 1 -coder 1 -me_range 16 -g 500 -keyint_min 12 -bt 4000k "$FILENAME".$VBITRATE.recompress.avi

I know this is a bit stupid, because I don't have to use all the options for the first run and am wasting time with that. Maybe someone can point out to me which options I can skip in the first run, but for now the major problem I have with this configuration is the jerky movement. It seems to happen not only with pans and zooms, but also in other scenes, although it is less noticeable there. It appears to have a rather regular frequency (like 2 times per second for Example).

Can anyone help?

Greetings,
Aurora

DarkZell666
31st August 2008, 15:28
Twice per second is somewhere near your new -keyint_min interval (12) indeed. Why set it so high anyway ? Just set it to 2 or whatever the default is. There's no good reason you wouldn't want keyframes to happen less than 12 frames appart anyway. If pans need more than 2 keyframes in a one second timeframe, then they need those extra keyframes, and x264 will only use them that close if it thinks it's necessary anyway.

It's wierd the video is actually jerky. During a pan or zoom, I would have expected the video to go all blocky, not have it's motion screwed. Could you post some samples please ?

Edit : Also, does -me full really work ? Try -me umh or -me hex, just in case. The original x264 doesn't have "full" search (unless ffmpeg maps it to esa instead ?). Note : ffmpeg says "-me" is deprecated and you should use the "-me_method" parameter instead. Dunno what that implies but I thought that was worthwhile mentionning :)

auroraglacialis
1st September 2008, 21:11
Ok, I'll try to just not set the min_keyframe value at all this time, if that does no good, I'll try to set it to 2.

About the method:
man ffmpeg tells me:
-me method
Set motion estimation method to method. Available methods are (from lowest to best quality):
zero
phods
log
x1
epzs
(default method)
full
exhaustive search (slow and marginally better than epzs)
So while full is a rather bad option (only marginally better), I tried using it in the hope of getting a better quality regarding the strange jerky movements, prior to that I used the default epzs.

Where did you read that -me is deprecated?

Oh and of course I whould like to show you an example, but how can I post a bit of the video to you? The whole thing is about 200 MB large - is there a linux tool to extract part of it without recompressing it again?

Ciao
Aurora

DarkZell666
1st September 2008, 22:22
What version are you using ?
I have r13357 and here's what it says :
-me_method <int> E.V.. set motion estimation method
zero E.V.. zero motion estimation (fastest)
full E.V.. full motion estimation (slowest)
epzs E.V.. EPZS motion estimation (default)
log E.V.. log motion estimation
phods E.V.. phods motion estimation
x1 E.V.. X1 motion estimation
hex E.V.. hex motion estimation
umh E.V.. umh motion estimation
iter E.V.. iter motion estimation
-me <int> E.V.. set motion estimation method (deprecated, use me_method instead)
zero E.V.. zero motion estimation (fastest)
full E.V.. full motion estimation (slowest)
epzs E.V.. EPZS motion estimation (default)
log E.V.. log motion estimation
phods E.V.. phods motion estimation
x1 E.V.. X1 motion estimation
hex E.V.. hex motion estimation
umh E.V.. umh motion estimation
iter E.V.. iter motion estimation

auroraglacialis
1st September 2008, 23:21
EIX says I have the latest stable in gentoos portage, named "0.4.9_p20070616". There is a masked package named "0.4.9_p20080326", that I could try to unlock... If I call ffmpegs help, I also get the information, that there is an option called "-me_method <int> E.V.. set motion estimation method", but there also still is the "-me" option available and I get no list of values for "<int> E.V."... So I guess, after the current test, I'll try to use the masked package of ffmpeg and see what it will give me. Seems that the syntax in the newer version would be "-me_method full" instad of "-me full"...