Statistics
| Branch: | Revision:

psnr-tools / psnr.sh @ fb38685e

History | View | Annotate | Download (2.56 KB)

1
#!/bin/bash
2

    
3
TMPPREFIX=./
4

    
5
ORIG_YUV=${TMPPREFIX}orig.yuv
6
ORIG_MP4=${TMPPREFIX}orig_compressed.m4v
7
RECEIVED_MP4=${TMPPREFIX}received.m4v
8
REFILLED_YUV=${TMPPREFIX}refilled.yuv
9

    
10
FFMPEG="/home/cskiraly/local/napa-wine/src/ffmpeg/build/ffmpeg -y"
11
ANALYSER=Analyser/analyser
12
CUTTER=Cutter/cutter
13
CUTTER_GOP=Cutter/cutter.gop
14
LOGPARSER=LogParser/logparser
15
REFILLER=ReFiller/refiller
16
EVALPSNR=EvalVid/psnr
17

    
18
XSIZE=352
19
YSIZE=288
20

    
21
function usage {
22
   echo "Usage: $0 init <orig video>";
23
   echo "       $0 calc <chunksize> <file with losses>";
24
   exit $1 
25
}
26

    
27
function init {
28
  [[ $# -eq 1 ]] || usage 1
29

    
30
  ORIG=$1
31

    
32
  #the command line to use for converting the original YUV file
33
  #to a compressed stream.
34
  #the frame size is 320x240; the "-mbd 2" option is just to
35
  #increase the compressed video quality (it asks for a more
36
  #complex motion estimation), and "-b 400k" is the video
37
  #bitrate.
38
  #This is one of the simplest encoding (no B frames, no
39
  #advanced features, etc...). B framed can be added with "-bf 1".
40

    
41
  #initialize
42
  $FFMPEG -i $ORIG $ORIG_YUV >${TMPPREFIX}ffmpeg.log
43
  $FFMPEG -s ${XSIZE}x${YSIZE} -r 25 -i $ORIG_YUV -f m4v -mbd 2 -b 400k $ORIG_MP4 >>${TMPPREFIX}ffmpeg.log
44
  $ANALYSER $ORIG_MP4 > ${TMPPREFIX}orig_log.txt
45
}
46

    
47
function calc {
48
  [[ $# -eq 2 ]] || usage 1
49

    
50
  CHUNK_SIZE=$1
51
  LOST_FILE=$2
52

    
53
  #cut lost chunks
54
  if [[ $CHUNK_SIZE == 0 ]]; then
55
    $CUTTER_GOP $ORIG_MP4 $RECEIVED_MP4 $LOST_FILE $CHUNK_SIZE 2> ${TMPPREFIX}cutter_log.txt
56
  else 
57
    $CUTTER $ORIG_MP4 $RECEIVED_MP4 $LOST_FILE $CHUNK_SIZE 2> ${TMPPREFIX}cutter_log.txt
58
  fi
59

    
60
  #get chunk count and avgsize
61
  BYTES=`awk '/^bytes:/ {print $2}' ${TMPPREFIX}cutter_log.txt`
62
  CHUNKS=`awk '/^chunks:/ {print $2}' ${TMPPREFIX}cutter_log.txt`
63
  CHUNKSLOST=`awk '/^chunkslost:/ {print $2}' ${TMPPREFIX}cutter_log.txt`
64
  #CHUNK_SIZE_AVG=`(echo - | awk '{ print $BYTES/$CHUNKS}')`
65

    
66
  #analyse losses
67
  $ANALYSER $RECEIVED_MP4 > ${TMPPREFIX}received_log.txt
68

    
69
  #reconstruct sequence by duplicating 
70
  $LOGPARSER ${TMPPREFIX}orig_log.txt ${TMPPREFIX}received_log.txt > ${TMPPREFIX}received_dup.txt
71
  $REFILLER $RECEIVED_MP4 $REFILLED_YUV ${TMPPREFIX}received_dup.txt > ${TMPPREFIX}refiller_log.txt
72
  $EVALPSNR $XSIZE $YSIZE 420 $ORIG_YUV $REFILLED_YUV >${TMPPREFIX}psnr_log.txt 2>&1
73

    
74
  PSNR=`awk '/^psnr:/ {print $8}' ${TMPPREFIX}psnr_log.txt`
75

    
76
  echo "bytes: $BYTES"
77
  echo "chunks: $CHUNKS"
78
  echo "chunkslost: $CHUNKSLOST"
79
  echo "frames: $FRAMES"
80
  echo "frameslost: $FRAMESLOST"
81
  echo "psnr: $PSNR"
82
}
83

    
84
[[ $# -ge 1 ]] || usage 1
85
CMD=$1;
86
shift
87

    
88
case $CMD in
89
  init)
90
    init $@
91
    ;;
92
  calc)
93
    calc $@
94
    ;;
95
  *)
96
    usage 1
97
    ;;
98
esac