Quantcast
Channel: Bash – 2Axels-Company
Viewing all articles
Browse latest Browse all 12

Videos unter Linux drehen

$
0
0

Videos unter Linux zu drehen ist eigentlich ganz einfach, wenn man weiß wie es geht…

Folgender Blog gab mir den entscheidenden Hinweis: rotate-a-video-avi-with-linux

seit ich auf Ubuntu 14.04 upgedatet habe, funktioniert das hier nicht mehr so:

1
2
mencoder -vf rotate=1 Source.video -ovc x264 -oac pcm -o output_video -ni -lavdopts threads=2 -x264encopts qp=26
mencoder -vf rotate=1 VIDEO0120.mp4 -ovc x264 -oac pcm -o VIDEO0120_rot.mp4  -lavdopts threads=4 -x264encopts qp=26

Aber mit avconv funktioniert es jetzt. Keine Ahnung wo da der Unterschied ist, oder warum es nun nur noch so klappt.

1
2
avconv -i VIDEO0126.mp4 -vcodec mjpeg -vb 8000k -acodec libmp3lame -ab 128k -ar 44100 VIDEO0126.avi
avconv  -i VIDEO0120.mp4 -strict experimental -vf "transpose=1"  VIDEO0120_rot.mp4

Achtung: Die Videos erst zu *.avi konvertieren funktioniert zwar, aber dann klappt das mit dem rotieren nicht mehr…

Hier nun noch die 2 Scripts die ich mir dazu geschrieben habe:

convert_video_to_avi.bash:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
videos="$@"
if [ "$videos" = "" -o "${videos}x" = "x" ]
then
  echo "bitte videos als Parameter angeben! - Exit"
  exit 1
else
 
 for video in $videos
 do
    echo "Now working for video: $video"
    echo -e "\nConverting Video $video to avi:"
    avconv -i $video -vcodec mjpeg -vb 8000k -acodec libmp3lame -ab 128k -ar 44100 ${video}.avi
 done
fi

rotate_handy_video_90degrees.bash

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# check the Parameters and Inputvariables:
# if an option has a colon sign after it, a parameter is needed
# a  (Option without an argument)
# c: (Option with an argument is needed!)
# :  (if the first char is a colon, the verbose mode for getopts is enabled)
usage="
USAGE: Dieses Script benoetigt folgende Optionen:
 
-r rotate (how to rotate the videos: 90, -90, 180, vflip)
 
-v videos to convert (put the videos, that should be converted into a list) 
 
h | help anzeigen dieser Hilfe
 
Example: 
 
$0 -r 90 -v VIDEO0120.mp4
 
"
 
while getopts h:r:v: option
do
        case "${option}"
        in
             r) ROTATE=${OPTARG}
                echo -e "Found option -$option <$OPTARG>\n" 
                ;;
             v) videos=${OPTARG}
                echo -e "Found option -$option <$OPTARG>\n" 
                ;;
             h|help) echo "$usage"
                exit 1
                ;;
            \?) echo -e "$usage\n"
                echo -e "Invalid option: -$OPTARG\n" >&2
                exit 1
                ;;
             :) echo -e "$usage\n"
                echo -e "Option $OPTARG requires an argument.\n" >&2
                exit 1
                ;;
        esac
done
DIRNAME="$( dirname $0 )"
BASENAME="$( basename $0 )"
 
################################################
#videos="$@"
if [ "$videos" = "" -o "${videos}x" = "x" ]
then
  echo "$usage"
  exit 1
else
 
 for video in $videos
 do
    echo "Now working for video: $video"
    if [ "$ROTATE" = "90" ]
    then
       echo -e "\nRotating Video $video for 90degrees clockwise:"
       echo    avconv  -i ${video} -strict experimental -threads auto -vf "transpose=1"  ${video%%.*}_rot90.${video##*.}
    elif [ "$ROTATE" = "-90" ]
    then
       echo -e "\nRotating Video $video for 90degrees counterclockwise:"
       echo    avconv  -i ${video} -strict experimental -threads auto -vf "transpose=0"  ${video%%.*}_rot-90.${video##*.}
    elif [ "$ROTATE" = "180" ]
    then
       echo -e "\nRotating Video $video for 180degrees clockwise:"
       echo    avconv  -i ${video} -strict experimental -threads auto -vf "hflip"  ${video%%.*}_rot180.${video##*.}
    elif [ "$ROTATE" = "vflip" ]
    then
       echo   avconv  -i ${video} -strict experimental -threads auto -vf "vflip"  ${video%%.*}_vflip.${video##*.}
    else
       echo "$usage"
       exit 1
    fi
 done
 
fi
 
exit 0
 
#
# http://www.kocram.com/wp/2013/11/rotate-video-using-ffmpeg-avconv/
# 
# http://askubuntu.com/questions/269429/how-can-i-rotate-video-by-180-degrees-with-avconv
# It is possible using the transpose video filter. You cannot rotate by 180 degrees, but you can rotate by 90 degrees and chain the filter.
#
# avconv -i video.mp4 -vf transpose=1,transpose=1 out.mkv
# 
# See transpose in the avconv manpage: http://manpages.ubuntu.com/manpages/quantal/en/man1/avconv.1.html
#
# avconv -filters to show all options belonging the filters

Viewing all articles
Browse latest Browse all 12