View Single Post
Old 28th July 2007, 17:20   #59  |  Link
microchip8
ffx264/ffhevc author
 
microchip8's Avatar
 
Join Date: May 2007
Location: /dev/video0
Posts: 1,843
Regarding your crop issues. I would do something like this...

1) detect the length of the input source with mplayer and export the output to a file...

Code:
mplayer input_file -identify -vo null -frames 1
2) When running mplayer with the -identify option it prints the video length. Look for the ID_LENGTH= line

3) Now to detect the exact and correct cropping values you run mplayer for ~15 frames with the -sstep option with you give to -sstep ID_LENGTH/15 , eg

Code:
mplayer input_file -vf cropdetect -nosound -vo null -frames 15 -sstep ID_LENGTH/15
this will force mplayer to detect the crop values at various positions in the video. I use this approach for a very long time now inside one of my Linux script and it has never failed to give me incorrect crop values.

Your approach in detecting the crop value for ~6 seconds is flawed as during these 6 second there can be only dark/black frames which will lead to incorrect crop values...

Here's my Linux shell code on how I do it, might help you a bit if you understand Linux shell programming

Code:
mplayer "$sourcetype" $device $vid -identify -vo null -frames 1 2>/dev/null > $CONFIGDIR/cropdetect
VLENGTH=$(grep "^ID_LENGTH" $CONFIGDIR/cropdetect | cut -f '2' -d '=' | cut -f '1' -d '.')
GETCROP=$(mplayer "$sourcetype" $device $vid -vf cropdetect -nosound -vo null -frames 15 -sstep $(($VLENGTH/15)) -nocache 2>/dev/null | tr '\r' '\n' | grep "crop=" | tail -1 | awk '{print $9}' | sed 's/crop=//g; s/).//g')
rm -f $CONFIGDIR/cropdetect
microchip8 is offline   Reply With Quote