
Recherche avancée
Médias (1)
-
Rennes Emotion Map 2010-11
19 octobre 2011, par
Mis à jour : Juillet 2013
Langue : français
Type : Texte
Autres articles (32)
-
Mise à jour de la version 0.1 vers 0.2
24 juin 2013, parExplications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...) -
Des sites réalisés avec MediaSPIP
2 mai 2011, parCette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page. -
Soumettre améliorations et plugins supplémentaires
10 avril 2011Si vous avez développé une nouvelle extension permettant d’ajouter une ou plusieurs fonctionnalités utiles à MediaSPIP, faites le nous savoir et son intégration dans la distribution officielle sera envisagée.
Vous pouvez utiliser la liste de discussion de développement afin de le faire savoir ou demander de l’aide quant à la réalisation de ce plugin. MediaSPIP étant basé sur SPIP, il est également possible d’utiliser le liste de discussion SPIP-zone de SPIP pour (...)
Sur d’autres sites (6276)
-
Resize the video
8 juin 2016, par Android devI have a requirement for video size before upload on the server and would like to resize the video to make sure it will not go the threshold.
So far I ended up with this command :
ffmpeg -y -i E:\test3.mp4 -s 640*480 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 E:\debug_video.mp4
The issues with this command :
- is it changes aspect ratio of the video
- it works too slow (30 seconds for 12 seconds 24mb video on Nexus 5)The best solution so far for the first issue is to check the video resolution first and only than run the ffmpeg.
Do you know how to do that with help of ffmpeg as two separate commands or as a single one ? Do you know how to make it faster ? Thank you in advance
UPDATE
The console output is below. Please let me know if you would like to get console output foronProgress
callbackadb -s 07f0f4ac01897da5 logcat "ffmpeg:*" "*:S"
06-08 17:43:29.589 20835 20835 D ffmpeg : FFmpeg:onProgress: ffmpeg version n3.
0.1 Copyright (c) 2000-2016 the FFmpeg developers
06-08 17:43:29.589 20835 20835 D ffmpeg : FFmpeg:onProgress: built with gcc 4
.8 (GCC)
06-08 17:43:29.592 20835 20835 D ffmpeg : FFmpeg:onProgress: configuration: -
-target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchai
n-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime
-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/s
ysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enab
le-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disabl
e-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable
-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-sha
red --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-
pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --
extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/includ
e -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-a
ll' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android
/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxf
lags=
06-08 17:43:29.600 20835 20835 D ffmpeg : FFmpeg:onProgress: libavutil 5
5. 17.103 / 55. 17.103
06-08 17:43:29.600 20835 20835 D ffmpeg : FFmpeg:onProgress: libavcodec 5
7. 24.102 / 57. 24.102
06-08 17:43:29.600 20835 20835 D ffmpeg : FFmpeg:onProgress: libavformat 5
7. 25.100 / 57. 25.100
06-08 17:43:29.600 20835 20835 D ffmpeg : FFmpeg:onProgress: libavdevice 5
7. 0.101 / 57. 0.101
06-08 17:43:29.600 20835 20835 D ffmpeg : FFmpeg:onProgress: libavfilter
6. 31.100 / 6. 31.100
06-08 17:43:29.600 20835 20835 D ffmpeg : FFmpeg:onProgress: libswscale
4. 0.100 / 4. 0.100
06-08 17:43:29.600 20835 20835 D ffmpeg : FFmpeg:onProgress: libswresample
2. 0.101 / 2. 0.101
06-08 17:43:29.600 20835 20835 D ffmpeg : FFmpeg:onProgress: libpostproc 5
4. 0.100 / 54. 0.100
06-08 17:43:29.885 20835 20835 D ffmpeg : FFmpeg:onProgress: Input #0, mov,mp4,
m4a,3gp,3g2,mj2, from '/storage/emulated/0/Pictures/test2.mp4':
06-08 17:43:29.885 20835 20835 D ffmpeg : FFmpeg:onProgress: Metadata:
06-08 17:43:29.885 20835 20835 D ffmpeg : FFmpeg:onProgress: major_brand
: mp42
06-08 17:43:29.885 20835 20835 D ffmpeg : FFmpeg:onProgress: minor_version
: 0
06-08 17:43:29.885 20835 20835 D ffmpeg : FFmpeg:onProgress: compatible_bra
nds: isommp42
06-08 17:43:29.886 20835 20835 D ffmpeg : FFmpeg:onProgress: creation_time
: 2016-06-02 09:20:58
06-08 17:43:29.886 20835 20835 D ffmpeg : FFmpeg:onProgress: com.android.ve
rsion: 6.0.1
06-08 17:43:29.886 20835 20835 D ffmpeg : FFmpeg:onProgress: Duration: 00:00:
12.03, start: 0.000000, bitrate: 17234 kb/s
06-08 17:43:29.886 20835 20835 D ffmpeg : FFmpeg:onProgress: Stream #0:0(en
g): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 16902 kb/s,
SAR 1:1 DAR 16:9, 29.81 fps, 29.85 tbr, 90k tbn, 180k tbc (default)
06-08 17:43:29.886 20835 20835 D ffmpeg : FFmpeg:onProgress: Metadata:
06-08 17:43:29.890 20835 20835 D ffmpeg : FFmpeg:onProgress: rotate
: 90
06-08 17:43:29.890 20835 20835 D ffmpeg : FFmpeg:onProgress: creation_tim
e : 2016-06-02 09:20:58
06-08 17:43:29.891 20835 20835 D ffmpeg : FFmpeg:onProgress: handler_name
: VideoHandle
06-08 17:43:29.891 20835 20835 D ffmpeg : FFmpeg:onProgress: Side data:
06-08 17:43:29.891 20835 20835 D ffmpeg : FFmpeg:onProgress: displaymatri
x: rotation of -90.00 degrees
06-08 17:43:29.892 20835 20835 D ffmpeg : FFmpeg:onProgress: Stream #0:1(en
g): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 96 kb/s (default)
06-08 17:43:29.892 20835 20835 D ffmpeg : FFmpeg:onProgress: Metadata:
06-08 17:43:29.893 20835 20835 D ffmpeg : FFmpeg:onProgress: creation_tim
e : 2016-06-02 09:20:58
06-08 17:43:29.893 20835 20835 D ffmpeg : FFmpeg:onProgress: handler_name
: SoundHandle
06-08 17:43:29.893 20835 20835 D ffmpeg : FFmpeg:onProgress: Please use -b:a or
-b:v, -b is ambiguous
06-08 17:43:29.894 20835 20835 D ffmpeg : FFmpeg:onProgress: Codec AVOption pre
set (Set the encoding preset (cf. x264 --fullhelp)) specified for output file #0
(/storage/emulated/0/Pictures/scaled_video.mp4) has not been used for any strea
m. The most likely reason is either wrong type (e.g. a video option with no vide
o streams) or that it is a private option of some encoder which was not actually
used for any stream.
06-08 17:43:29.939 20835 20835 D ffmpeg : FFmpeg:onProgress: [mpeg4 @ 0xb5c4440
0] Invalid pixel aspect ratio 5121/5120, limit is 255/255 reducing
06-08 17:43:29.996 20835 20835 D ffmpeg : FFmpeg:onProgress: Output #0, mp4, to
'/storage/emulated/0/Pictures/scaled_video.mp4':
06-08 17:43:29.998 20835 20835 D ffmpeg : FFmpeg:onProgress: Metadata:
06-08 17:43:29.999 20835 20835 D ffmpeg : FFmpeg:onProgress: major_brand
: mp42
06-08 17:43:30.000 20835 20835 D ffmpeg : FFmpeg:onProgress: minor_version
: 0
06-08 17:43:30.000 20835 20835 D ffmpeg : FFmpeg:onProgress: compatible_bra
nds: isommp42
06-08 17:43:30.001 20835 20835 D ffmpeg : FFmpeg:onProgress: com.android.ve
rsion: 6.0.1
06-08 17:43:30.002 20835 20835 D ffmpeg : FFmpeg:onProgress: encoder
: Lavf57.25.100
06-08 17:43:30.003 20835 20835 D ffmpeg : FFmpeg:onProgress: Stream #0:0(en
g): Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 640x1138 [SAR 1:1 DAR 320:569],
q=2-31, 2097 kb/s, SAR 5121:5120 DAR 9:16, 15 fps, 15360 tbn, 15 tbc (default)
06-08 17:43:30.004 20835 20835 D ffmpeg : FFmpeg:onProgress: Metadata:
06-08 17:43:30.005 20835 20835 D ffmpeg : FFmpeg:onProgress: handler_name
: VideoHandle
06-08 17:43:30.006 20835 20835 D ffmpeg : FFmpeg:onProgress: creation_tim
e : 2016-06-02 09:20:58
06-08 17:43:30.007 20835 20835 D ffmpeg : FFmpeg:onProgress: encoder
: Lavc57.24.102 mpeg4
06-08 17:43:30.008 20835 20835 D ffmpeg : FFmpeg:onProgress: Side data:
06-08 17:43:30.008 20835 20835 D ffmpeg : FFmpeg:onProgress: unknown side
data type 10 (24 bytes)
06-08 17:43:30.008 20835 20835 D ffmpeg : FFmpeg:onProgress: Stream #0:1(en
g): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, mono, fltp, 12 kb/s (def
ault)
06-08 17:43:30.008 20835 20835 D ffmpeg : FFmpeg:onProgress: Metadata:
06-08 17:43:30.008 20835 20835 D ffmpeg : FFmpeg:onProgress: creation_tim
e : 2016-06-02 09:20:58
06-08 17:43:30.008 20835 20835 D ffmpeg : FFmpeg:onProgress: handler_name
: SoundHandle
06-08 17:43:30.009 20835 20835 D ffmpeg : FFmpeg:onProgress: encoder
: Lavc57.24.102 aac
06-08 17:43:30.009 20835 20835 D ffmpeg : FFmpeg:onProgress: Stream mapping:
06-08 17:43:30.009 20835 20835 D ffmpeg : FFmpeg:onProgress: Stream #0:0 -> #
0:0 (h264 (native) -> mpeg4 (native))
06-08 17:43:30.009 20835 20835 D ffmpeg : FFmpeg:onProgress: Stream #0:1 -> #
0:1 (aac (native) -> aac (native))
06-08 17:43:30.010 20835 20835 D ffmpeg : FFmpeg:onProgress: Press [q] to stop,
[?] for help
06-08 17:43:30.730 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 2 fps=0.
0 q=2.0 size= 129kB time=00:00:01.00 bitrate=1056.4kbits/s speed=1.66x
06-08 17:43:31.350 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 5 fps=4.
0 q=2.0 size= 314kB time=00:00:01.00 bitrate=2566.0kbits/s dup=0 drop=1 spee
d=0.809x
06-08 17:43:31.842 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 8 fps=4.
6 q=7.5 size= 404kB time=00:00:01.00 bitrate=3302.5kbits/s dup=0 drop=4 spee
d=0.573x
06-08 17:43:32.367 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 10 fps=4.
4 q=8.7 size= 431kB time=00:00:01.00 bitrate=3523.1kbits/s dup=0 drop=6 spee
d=0.441x
06-08 17:43:32.873 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 13 fps=4.
7 q=9.0 size= 518kB time=00:00:01.00 bitrate=4230.9kbits/s dup=0 drop=9 spee
d=0.361x
06-08 17:43:33.392 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 15 fps=4.
5 q=11.6 size= 536kB time=00:00:01.00 bitrate=4381.7kbits/s dup=0 drop=11 sp
eed=0.303x
06-08 17:43:34.011 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 17 fps=4.
3 q=11.7 size= 558kB time=00:00:02.00 bitrate=2279.7kbits/s dup=0 drop=13 sp
eed=0.512x
06-08 17:43:34.621 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 20 fps=4.
4 q=12.5 size= 598kB time=00:00:02.00 bitrate=2444.5kbits/s dup=0 drop=16 sp
eed=0.443x
06-08 17:43:35.207 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 23 fps=4.
5 q=11.3 size= 630kB time=00:00:02.00 bitrate=2574.3kbits/s dup=0 drop=19 sp
eed=0.394x
06-08 17:43:35.726 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 26 fps=4.
6 q=10.1 size= 689kB time=00:00:02.00 bitrate=2815.3kbits/s dup=0 drop=22 sp
eed=0.357x
06-08 17:43:36.252 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 28 fps=4.
6 q=9.6 size= 707kB time=00:00:02.00 bitrate=2888.7kbits/s dup=0 drop=24 spe
ed=0.327x
06-08 17:43:36.749 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 31 fps=4.
7 q=9.5 size= 726kB time=00:00:02.06 bitrate=2879.6kbits/s dup=0 drop=27 spe
ed=0.311x
06-08 17:43:37.341 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 33 fps=4.
6 q=9.3 size= 767kB time=00:00:03.00 bitrate=2089.4kbits/s dup=0 drop=29 spe
ed=0.417x
06-08 17:43:37.872 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 35 fps=4.
5 q=9.4 size= 791kB time=00:00:03.00 bitrate=2154.3kbits/s dup=0 drop=31 spe
ed=0.386x
06-08 17:43:38.447 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 38 fps=4.
6 q=9.2 size= 854kB time=00:00:03.00 bitrate=2324.7kbits/s dup=0 drop=34 spe
ed=0.361x
06-08 17:43:39.005 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 41 fps=4.
6 q=8.2 size= 883kB time=00:00:03.00 bitrate=2404.7kbits/s dup=0 drop=36 spe
ed=0.338x
06-08 17:43:39.507 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 43 fps=4.
6 q=9.0 size= 918kB time=00:00:03.00 bitrate=2499.3kbits/s dup=0 drop=38 spe
ed=0.32x
06-08 17:43:40.065 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 46 fps=4.
6 q=9.6 size= 948kB time=00:00:03.06 bitrate=2531.5kbits/s dup=0 drop=41 spe
ed=0.307x
06-08 17:43:40.602 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 48 fps=4.
6 q=9.3 size= 990kB time=00:00:04.01 bitrate=2021.2kbits/s dup=0 drop=43 spe
ed=0.381x
06-08 17:43:41.189 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 51 fps=4.
6 q=7.3 size= 1025kB time=00:00:04.01 bitrate=2094.5kbits/s dup=0 drop=46 spe
ed=0.361x
06-08 17:43:41.744 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 54 fps=4.
6 q=6.9 size= 1064kB time=00:00:04.01 bitrate=2173.0kbits/s dup=0 drop=49 spe
ed=0.345x
06-08 17:43:42.288 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 56 fps=4.
6 q=6.1 size= 1082kB time=00:00:04.01 bitrate=2209.5kbits/s dup=0 drop=51 spe
ed=0.329x
06-08 17:43:42.872 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 59 fps=4.
6 q=4.5 size= 1107kB time=00:00:04.01 bitrate=2260.3kbits/s dup=0 drop=54 spe
ed=0.314x
06-08 17:43:43.292 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 61 fps=4.
6 q=3.2 size= 1152kB time=00:00:04.26 bitrate=2212.2kbits/s dup=0 drop=56 spe
ed=0.321x
06-08 17:43:43.986 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 64 fps=4.
6 q=3.9 size= 1178kB time=00:00:05.01 bitrate=1924.7kbits/s dup=0 drop=59 spe
ed=0.361x
06-08 17:43:44.518 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 66 fps=4.
6 q=3.6 size= 1196kB time=00:00:05.01 bitrate=1953.9kbits/s dup=0 drop=61 spe
ed=0.347x
06-08 17:43:45.104 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 69 fps=4.
6 q=3.4 size= 1232kB time=00:00:05.01 bitrate=2013.0kbits/s dup=0 drop=64 spe
ed=0.334x
06-08 17:43:45.687 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 72 fps=4.
6 q=4.9 size= 1263kB time=00:00:05.01 bitrate=2063.4kbits/s dup=0 drop=67 spe
ed=0.321x
06-08 17:43:46.262 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 75 fps=4.
6 q=3.5 size= 1307kB time=00:00:05.01 bitrate=2135.1kbits/s dup=0 drop=70 spe
ed=0.31x
06-08 17:43:46.840 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 77 fps=4.
6 q=3.1 size= 1334kB time=00:00:06.01 bitrate=1816.5kbits/s dup=0 drop=72 spe
ed=0.359x
06-08 17:43:47.354 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 80 fps=4.
6 q=3.5 size= 1380kB time=00:00:06.01 bitrate=1878.6kbits/s dup=0 drop=75 spe
ed=0.349x
06-08 17:43:47.826 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 82 fps=4.
6 q=3.6 size= 1412kB time=00:00:06.01 bitrate=1923.2kbits/s dup=0 drop=77 spe
ed=0.339x
06-08 17:43:48.346 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 85 fps=4.
7 q=3.5 size= 1476kB time=00:00:06.01 bitrate=2009.8kbits/s dup=0 drop=80 spe
ed=0.33x
06-08 17:43:48.911 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 88 fps=4.
7 q=3.5 size= 1524kB time=00:00:06.01 bitrate=2074.7kbits/s dup=0 drop=83 spe
ed=0.32x
06-08 17:43:49.496 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 91 fps=4.
7 q=3.8 size= 1556kB time=00:00:06.06 bitrate=2101.5kbits/s dup=0 drop=86 spe
ed=0.313x
06-08 17:43:50.100 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 93 fps=4.
7 q=4.1 size= 1616kB time=00:00:07.01 bitrate=1886.0kbits/s dup=0 drop=88 spe
ed=0.352x
06-08 17:43:50.598 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 95 fps=4.
6 q=4.3 size= 1652kB time=00:00:07.01 bitrate=1928.4kbits/s dup=0 drop=90 spe
ed=0.342x
06-08 17:43:51.182 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 98 fps=4.
7 q=4.7 size= 1728kB time=00:00:07.01 bitrate=2017.1kbits/s dup=0 drop=93 spe
ed=0.333x
06-08 17:43:51.693 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 100 fps=4.
6 q=4.6 size= 1763kB time=00:00:07.01 bitrate=2057.5kbits/s dup=0 drop=95 spe
ed=0.325x
06-08 17:43:52.272 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 103 fps=4.
6 q=4.6 size= 1812kB time=00:00:07.01 bitrate=2115.1kbits/s dup=0 drop=98 spe
ed=0.317x
06-08 17:43:52.839 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 106 fps=4.
7 q=4.2 size= 1845kB time=00:00:07.06 bitrate=2138.7kbits/s dup=0 drop=101 sp
eed=0.311x
06-08 17:43:53.383 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 108 fps=4.
6 q=4.1 size= 1886kB time=00:00:08.02 bitrate=1925.7kbits/s dup=0 drop=103 sp
eed=0.344x
06-08 17:43:53.966 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 111 fps=4.
7 q=3.5 size= 1940kB time=00:00:08.02 bitrate=1981.0kbits/s dup=0 drop=106 sp
eed=0.336x
06-08 17:43:54.472 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 113 fps=4.
6 q=3.1 size= 1968kB time=00:00:08.02 bitrate=2010.1kbits/s dup=0 drop=108 sp
eed=0.329x
06-08 17:43:55.129 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 116 fps=4.
6 q=3.3 size= 2016kB time=00:00:08.02 bitrate=2058.5kbits/s dup=0 drop=111 sp
eed=0.321x
06-08 17:43:55.624 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 119 fps=4.
7 q=3.2 size= 2052kB time=00:00:08.02 bitrate=2096.0kbits/s dup=0 drop=114 sp
eed=0.314x
06-08 17:43:56.082 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 121 fps=4.
6 q=2.7 size= 2119kB time=00:00:08.06 bitrate=2152.0kbits/s dup=0 drop=116 sp
eed=0.309x
06-08 17:43:56.729 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 124 fps=4.
7 q=4.0 size= 2172kB time=00:00:09.02 bitrate=1971.5kbits/s dup=0 drop=119 sp
eed=0.339x
06-08 17:43:57.292 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 127 fps=4.
7 q=3.5 size= 2210kB time=00:00:09.02 bitrate=2006.0kbits/s dup=0 drop=122 sp
eed=0.332x
06-08 17:43:57.793 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 129 fps=4.
7 q=3.3 size= 2234kB time=00:00:09.02 bitrate=2028.1kbits/s dup=0 drop=124 sp
eed=0.326x
06-08 17:43:58.431 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 132 fps=4.
7 q=3.3 size= 2275kB time=00:00:09.02 bitrate=2065.6kbits/s dup=0 drop=127 sp
eed=0.319x
06-08 17:43:58.986 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 135 fps=4.
7 q=3.4 size= 2344kB time=00:00:09.02 bitrate=2127.5kbits/s dup=0 drop=130 sp
eed=0.313x
06-08 17:43:59.374 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 136 fps=4.
6 q=3.2 size= 2356kB time=00:00:09.10 bitrate=2119.0kbits/s dup=0 drop=131 sp
eed=0.31x
06-08 17:43:59.986 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 139 fps=4.
6 q=2.9 size= 2392kB time=00:00:10.02 bitrate=1954.2kbits/s dup=0 drop=133 sp
eed=0.335x
06-08 17:44:00.582 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 142 fps=4.
7 q=2.8 size= 2428kB time=00:00:10.02 bitrate=1983.5kbits/s dup=0 drop=136 sp
eed=0.329x
06-08 17:44:01.158 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 145 fps=4.
7 q=3.0 size= 2516kB time=00:00:10.02 bitrate=2055.4kbits/s dup=0 drop=139 sp
eed=0.323x
06-08 17:44:01.691 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 148 fps=4.
7 q=4.6 size= 2583kB time=00:00:10.02 bitrate=2110.7kbits/s dup=0 drop=142 sp
eed=0.317x
06-08 17:44:02.168 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 150 fps=4.
7 q=4.8 size= 2626kB time=00:00:10.02 bitrate=2145.1kbits/s dup=0 drop=144 sp
eed=0.312x
06-08 17:44:02.587 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 152 fps=4.
7 q=5.0 size= 2668kB time=00:00:10.32 bitrate=2117.0kbits/s dup=0 drop=146 sp
eed=0.317x
06-08 17:44:03.209 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 154 fps=4.
6 q=5.0 size= 2709kB time=00:00:11.02 bitrate=2012.4kbits/s dup=0 drop=148 sp
eed=0.333x
06-08 17:44:03.815 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 157 fps=4.
7 q=3.7 size= 2770kB time=00:00:11.02 bitrate=2057.2kbits/s dup=0 drop=151 sp
eed=0.327x
06-08 17:44:04.402 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 160 fps=4.
7 q=3.3 size= 2800kB time=00:00:11.02 bitrate=2079.7kbits/s dup=0 drop=154 sp
eed=0.321x
06-08 17:44:04.965 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 163 fps=4.
7 q=3.0 size= 2835kB time=00:00:11.02 bitrate=2105.7kbits/s dup=0 drop=157 sp
eed=0.316x
06-08 17:44:05.505 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 166 fps=4.
7 q=3.1 size= 2880kB time=00:00:11.06 bitrate=2131.8kbits/s dup=0 drop=160 sp
eed=0.313x
06-08 17:44:06.094 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 169 fps=4.
7 q=3.3 size= 2880kB time=00:00:11.26 bitrate=2093.9kbits/s dup=0 drop=163 sp
eed=0.313x
06-08 17:44:06.603 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 171 fps=4.
7 q=3.8 size= 2880kB time=00:00:11.40 bitrate=2069.5kbits/s dup=0 drop=165 sp
eed=0.312x
06-08 17:44:07.192 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 174 fps=4.
7 q=3.6 size= 2880kB time=00:00:11.60 bitrate=2033.8kbits/s dup=0 drop=168 sp
eed=0.313x
06-08 17:44:07.772 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 177 fps=4.
7 q=3.3 size= 2880kB time=00:00:11.80 bitrate=1999.3kbits/s dup=0 drop=171 sp
eed=0.313x
06-08 17:44:08.287 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 180 fps=4.
7 q=3.2 size= 2880kB time=00:00:12.00 bitrate=1966.0kbits/s dup=0 drop=174 sp
eed=0.314x
06-08 17:44:08.900 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 182 fps=4.
7 q=3.5 size= 3118kB time=00:00:12.13 bitrate=2105.2kbits/s dup=0 drop=176 sp
eed=0.313x
06-08 17:44:08.915 20835 20835 D ffmpeg : FFmpeg:onProgress: frame= 182 fps=4.
7 q=3.5 Lsize= 3205kB time=00:00:12.13 bitrate=2163.7kbits/s dup=0 drop=176 s
peed=0.312x
06-08 17:44:08.915 20835 20835 D ffmpeg : FFmpeg:onProgress: video:3177kB audio
:21kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.19565
3%
06-08 17:44:08.946 20835 20835 D ffmpeg : FFmpeg:onProgress: [aac @ 0xb5c44c00]
Qavg: 137.182
06-08 17:44:08.963 20835 20835 D ffmpeg : FFmpeg:onSuccess: ffmpeg version n3.0
.1 Copyright (c) 2000-2016 the FFmpeg developers
06-08 17:44:08.963 20835 20835 D ffmpeg : built with gcc 4.8 (GCC)
06-08 17:44:08.963 20835 20835 D ffmpeg : configuration: --target-os=linux --
cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-l
inux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroo
t=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic
--enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --ena
ble-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-f
fserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-f
fprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static
--pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix
=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/ho
me/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE
-D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags
='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -
Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
06-08 17:44:08.963 20835 20835 D ffmpeg : libavutil 55. 17.103 / 55. 17.
103
06-08 17:44:08.963 20835 20835 D ffmpeg : libavcodec 57. 24.102 / 57. 24.
102
06-08 17:44:08.963 20835 20835 D ffmpeg : libavformat 57. 25.100 / 57. 25.
100
06-08 17:44:08.963 20835 20835 D ffmpeg : libavdevice 57. 0.101 / 57. 0.
101
06-08 17:44:08.963 20835 20835 D ffmpeg : libavfilter 6. 31.100 / 6. 31.
100
06-08 17:44:08.963 20835 20835 D ffmpeg : libswscale 4. 0.100 / 4. 0.
100
06-08 17:44:08.963 20835 20835 D ffmpeg : libswresample 2. 0.101 / 2. 0.
101
06-08 17:44:08.963 20835 20835 D ffmpeg : libpostproc 54. 0.100 / 54. 0.
100
06-08 17:44:08.963 20835 20835 D ffmpeg : Input #0, mov,mp4,m4a,3gp,3g2,mj2, fr
om '/storage/emulated/0/Pictures/test2.mp4':
06-08 17:44:08.963 20835 20835 D ffmpeg : Metadata:
06-08 17:44:08.963 20835 20835 D ffmpeg : major_brand : mp42
06-08 17:44:08.963 20835 20835 D ffmpeg : minor_version : 0
06-08 17:44:08.963 20835 20835 D ffmpeg : compatible_brands: isommp42
06-08 17:44:08.963 20835 20835 D ffmpeg : creation_time : 2016-06-02 09:2
0:58
06-08 17:44:08.963 20835 20835 D ffmpeg : com.android.version: 6.0.1
06-08 17:44:08.963 20835 20835 D ffmpeg : Duration: 00:00:12.03, start: 0.000
000, bitrate: 17234 kb/s
06-08 17:44:08.963 20835 20835 D ffmpeg : Stream #0:0(eng): Video: h264 (Ba
seline) (avc1 / 0x31637661), yuv420p, 1920x1080, 16902 kb/s, SAR 1:1 DAR 16:9, 2
9.81 fps, 29.85 tbr, 90k tbn, 180k tbc (default)
06-08 17:44:08.963 20835 20835 D ffmpeg : Metadata:
06-08 17:44:08.963 20835 20835 D ffmpeg : rotate : 90
06-08 17:44:08.963 20835 20835 D ffmpeg : creation_time : 2016-06-02 09
:20:58
06-08 17:44:08.963 20835 20835 D ffmpeg : handler_name : VideoHandle
06-08 17:44:08.963 20835 20835 D ffmpeg : Side data:
06-08 17:44:08.963 20835 20835 D ffmpeg : displaymatrix: rotation of -90.
00 degrees
06-08 17:44:08.963 20835 20835 D ffmpeg : Stream #0:1(eng): Audio: aac (LC)
(mp4a / 0x6134706D), 48000 Hz, mono, fltp, 96 kb/s (default)
06-08 17:44:08.963 20835 20835 D ffmpeg : Metadata:
06-08 17:44:08.963 20835 20835 D ffmpeg : creation_time : 2016-06-02 09
:20:58
06-08 17:44:08.963 20835 20835 D ffmpeg : handler_name : SoundHandle
06-08 17:44:08.963 20835 20835 D ffmpeg : Please use -b:a or -b:v, -b is ambigu
ous
06-08 17:44:08.963 20835 20835 D ffmpeg : Codec AVOption preset (Set the encodi
ng preset (cf. x264 --fullhelp)) specified for output file #0 (/storage/emulated
/0/Pictures/scaled_video.mp4) has not been used for any stream. The most likely
reason is either wrong type (e.g. a video option with no video streams) or that
it is a private option of some encoder which was not actually used for any strea
m.
06-08 17:44:08.963 20835 20835 D ffmpeg : [mpeg4 @ 0xb5c44400] Invalid pixel as
pect ratio 5121/5120, limit is 255/255 reducing
06-08 17:44:08.963 20835 20835 D ffmpeg : Output #0, mp4, to '/storage/emulated
/0/Pictures/scaled_video.mp4':
06-08 17:44:08.963 20835 20835 D ffmpeg : Metadata:
06-08 17:44:08.963 20835 20835 D ffmpeg : major_brand : mp42
06-08 17:44:08.963 20835 20835 D ffmpeg : minor_version : 0
06-08 17:44:08.963 20835 20835 D ffmpeg : compatible_brands: isommp42
06-08 17:44:08.963 20835 20835 D ffmpeg : com.android.version: 6.0.1
06-08 17:44:08.963 20835 20835 D ffmpeg : encoder : Lavf57.25.100
06-08 17:44:08.963 20835 20835 D ffmpeg : Stream #0:0(eng): Video: mpeg4 (
[0][0][0] / 0x0020), yuv420p, 640x1138 [SAR 1:1 DAR 320:569], q=2-31, 2097 kb/s,
SAR 5121:5120 DAR 9:16, 15 fps, 15360 tbn, 15 tbc (default)
06-08 17:44:08.963 20835 20835 D ffmpeg : Metadata:
06-08 17:44:08.963 20835 20835 D ffmpeg : handler_name : VideoHandle
06-08 17:44:08.963 20835 20835 D ffmpeg : creation_time : 2016-06-02 09
:20:58
06-08 17:44:08.963 20835 20835 D ffmpeg : encoder : Lavc57.24.102
mpeg4
06-08 17:44:08.963 20835 20835 D ffmpeg : Side data:
06-08 17:44:08.963 20835 20835 D ffmpeg : unknown side data type 10 (24 b
ytes)
06-08 17:44:08.963 20835 20835 D ffmpeg : Stream #0:1(eng): Audio: aac (LC)
([64][0][0][0] / 0x0040), 48000 Hz, mono, fltp, 12 kb/s (default)
06-08 17:44:08.963 20835 20835 D ffmpeg : Metadata:
06-08 17:44:08.963 20835 20835 D ffmpeg : creation_time : 2016-06-02 09
:20:58
06-08 17:44:08.963 20835 20835 D ffmpeg : handler_name : SoundHandle
06-08 17:44:08.963 20835 20835 D ffmpeg : encoder : Lavc57.24.102
aac
06-08 17:44:08.963 20835 20835 D ffmpeg : Stream mapping:
06-08 17:44:08.963 20835 20835 D ffmpeg : Stream #0:0 -> #0:0 (h264 (native)
-> mpeg4 (native))
06-08 17:44:08.963 20835 20835 D ffmpeg : Stream #0:1 -> #0:1 (aac (native) -
> aac (native))
06-08 17:44:08.963 20835 20835 D ffmpeg : Press [q] to stop, [?] for help
06-08 17:44:08.963 20835 20835 D ffmpeg : frame= 2 fps=0.0 q=2.0 size= 1
29kB time=00:00:01.00 bitrate=1056.4kbits/s speed=1.66x
06-08 17:44:08.963 20835 20835 D ffmpeg : frame= 5 fps=4.0 q=2.0 size= 3
14kB time=00:00:01.00 bitrate=2566.0kbits/s dup=0 drop=1 speed=0.809x
06-08 17:44:08.963 20835 20835 D ffmpeg : frame= 8
06-08 17:44:08.963 20835 20835 D ffmpeg : FFmpeg:onFinish: -
Recording a video using MediaRecorder
21 juillet 2016, par Cédric PortmannI am currently using the TextureFromCameraActivity from Grafika to record a video in square ( 1:1 ) resolution. Therefor I the GLES20.glViewport so that the video gets moved to the top and it appears to be squared. Now I would like to record this square view using the MediaRecorder or at least record the camera with normal resolutiona and then crop it using FFmpeg. However I get the same error over and over again and I cant figure out why.
The error I get :
start called in an invalid state : 4
And yes I added all the necessary permissions.
android.permission.WRITE_EXTERNAL_STORAGE android.permission.CAMERA
android.permission.RECORD_VIDEO android.permission.RECORD_AUDIO
android.permission.STORAGE android.permission.READ_EXTERNAL_STORAGEHere the modified code :
https://github.com/google/grafika
Thanks for your help :D
package com.android.grafika;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.app.Activity;
import android.widget.Toast;
import com.android.grafika.gles.Drawable2d;
import com.android.grafika.gles.EglCore;
import com.android.grafika.gles.GlUtil;
import com.android.grafika.gles.Sprite2d;
import com.android.grafika.gles.Texture2dProgram;
import com.android.grafika.gles.WindowSurface;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
public class TextureFromCameraActivity extends Activity implements View.OnClickListener, SurfaceHolder.Callback,
SeekBar.OnSeekBarChangeListener {
private static final int DEFAULT_ZOOM_PERCENT = 0; // 0-100
private static final int DEFAULT_SIZE_PERCENT = 80; // 0-100
private static final int DEFAULT_ROTATE_PERCENT = 75; // 0-100
// Requested values; actual may differ.
private static final int REQ_CAMERA_WIDTH = 720;
private static final int REQ_CAMERA_HEIGHT = 720;
private static final int REQ_CAMERA_FPS = 30;
// The holder for our SurfaceView. The Surface can outlive the Activity (e.g. when
// the screen is turned off and back on with the power button).
//
// This becomes non-null after the surfaceCreated() callback is called, and gets set
// to null when surfaceDestroyed() is called.
private static SurfaceHolder sSurfaceHolder;
// Thread that handles rendering and controls the camera. Started in onResume(),
// stopped in onPause().
private RenderThread mRenderThread;
// Receives messages from renderer thread.
private MainHandler mHandler;
// User controls.
private SeekBar mZoomBar;
private SeekBar mSizeBar;
private SeekBar mRotateBar;
// These values are passed to us by the camera/render thread, and displayed in the UI.
// We could also just peek at the values in the RenderThread object, but we'd need to
// synchronize access carefully.
private int mCameraPreviewWidth, mCameraPreviewHeight;
private float mCameraPreviewFps;
private int mRectWidth, mRectHeight;
private int mZoomWidth, mZoomHeight;
private int mRotateDeg;
SurfaceHolder sh;
MediaRecorder recorder;
SurfaceHolder holder;
boolean recording = false;
public static final String TAG = "VIDEOCAPTURE";
private static final File OUTPUT_DIR = Environment.getExternalStorageDirectory();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
recorder = new MediaRecorder();
setContentView(R.layout.activity_texture_from_camera);
mHandler = new MainHandler(this);
SurfaceView cameraView = (SurfaceView) findViewById(R.id.cameraOnTexture_surfaceView);
sh = cameraView.getHolder();
cameraView.setClickable(true);// make the surface view clickable
sh.addCallback(this);
//prepareRecorder();
mZoomBar = (SeekBar) findViewById(R.id.tfcZoom_seekbar);
mSizeBar = (SeekBar) findViewById(R.id.tfcSize_seekbar);
mRotateBar = (SeekBar) findViewById(R.id.tfcRotate_seekbar);
mZoomBar.setProgress(DEFAULT_ZOOM_PERCENT);
mSizeBar.setProgress(DEFAULT_SIZE_PERCENT);
mRotateBar.setProgress(DEFAULT_ROTATE_PERCENT);
mZoomBar.setOnSeekBarChangeListener(this);
mSizeBar.setOnSeekBarChangeListener(this);
mRotateBar.setOnSeekBarChangeListener(this);
Button record_btn = (Button)findViewById(R.id.button);
record_btn.setOnClickListener(this);
initRecorder();
updateControls();
}
@Override
protected void onResume() {
Log.d(TAG, "onResume BEGIN");
super.onResume();
mRenderThread = new RenderThread(mHandler);
mRenderThread.setName("TexFromCam Render");
mRenderThread.start();
mRenderThread.waitUntilReady();
RenderHandler rh = mRenderThread.getHandler();
rh.sendZoomValue(mZoomBar.getProgress());
rh.sendSizeValue(mSizeBar.getProgress());
rh.sendRotateValue(mRotateBar.getProgress());
if (sSurfaceHolder != null) {
Log.d(TAG, "Sending previous surface");
rh.sendSurfaceAvailable(sSurfaceHolder, false);
} else {
Log.d(TAG, "No previous surface");
}
Log.d(TAG, "onResume END");
}
@Override
protected void onPause() {
Log.d(TAG, "onPause BEGIN");
super.onPause();
RenderHandler rh = mRenderThread.getHandler();
rh.sendShutdown();
try {
mRenderThread.join();
} catch (InterruptedException ie) {
// not expected
throw new RuntimeException("join was interrupted", ie);
}
mRenderThread = null;
Log.d(TAG, "onPause END");
}
@Override // SurfaceHolder.Callback
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated holder=" + holder + " (static=" + sSurfaceHolder + ")");
if (sSurfaceHolder != null) {
throw new RuntimeException("sSurfaceHolder is already set");
}
sSurfaceHolder = holder;
if (mRenderThread != null) {
// Normal case -- render thread is running, tell it about the new surface.
RenderHandler rh = mRenderThread.getHandler();
rh.sendSurfaceAvailable(holder, true);
} else {
// Sometimes see this on 4.4.x N5: power off, power on, unlock, with device in
// landscape and a lock screen that requires portrait. The surface-created
// message is showing up after onPause().
//
// Chances are good that the surface will be destroyed before the activity is
// unpaused, but we track it anyway. If the activity is un-paused and we start
// the RenderThread, the SurfaceHolder will be passed in right after the thread
// is created.
Log.d(TAG, "render thread not running");
}
recorder.setPreviewDisplay(holder.getSurface());
}
@Override // SurfaceHolder.Callback
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.d(TAG, "surfaceChanged fmt=" + format + " size=" + width + "x" + height +
" holder=" + holder);
if (mRenderThread != null) {
RenderHandler rh = mRenderThread.getHandler();
rh.sendSurfaceChanged(format, width, height);
} else {
Log.d(TAG, "Ignoring surfaceChanged");
return;
}
}
@Override // SurfaceHolder.Callback
public void surfaceDestroyed(SurfaceHolder holder) {
// In theory we should tell the RenderThread that the surface has been destroyed.
if (mRenderThread != null) {
RenderHandler rh = mRenderThread.getHandler();
rh.sendSurfaceDestroyed();
}
Log.d(TAG, "surfaceDestroyed holder=" + holder);
sSurfaceHolder = null;
}
@Override // SeekBar.OnSeekBarChangeListener
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (mRenderThread == null) {
// Could happen if we programmatically update the values after setting a listener
// but before starting the thread. Also, easy to cause this by scrubbing the seek
// bar with one finger then tapping "recents" with another.
Log.w(TAG, "Ignoring onProgressChanged received w/o RT running");
return;
}
RenderHandler rh = mRenderThread.getHandler();
// "progress" ranges from 0 to 100
if (seekBar == mZoomBar) {
//Log.v(TAG, "zoom: " + progress);
rh.sendZoomValue(progress);
} else if (seekBar == mSizeBar) {
//Log.v(TAG, "size: " + progress);
rh.sendSizeValue(progress);
} else if (seekBar == mRotateBar) {
//Log.v(TAG, "rotate: " + progress);
rh.sendRotateValue(progress);
} else {
throw new RuntimeException("unknown seek bar");
}
// If we're getting preview frames quickly enough we don't really need this, but
// we don't want to have chunky-looking resize movement if the camera is slow.
// OTOH, if we get the updates too quickly (60fps camera?), this could jam us
// up and cause us to run behind. So use with caution.
rh.sendRedraw();
}
@Override // SeekBar.OnSeekBarChangeListener
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override // SeekBar.OnSeekBarChangeListener
public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
/**
* Handles any touch events that aren't grabbed by one of the controls.
*/
public boolean onTouchEvent(MotionEvent e) {
float x = e.getX();
float y = e.getY();
switch (e.getAction()) {
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_DOWN:
//Log.v(TAG, "onTouchEvent act=" + e.getAction() + " x=" + x + " y=" + y);
if (mRenderThread != null) {
RenderHandler rh = mRenderThread.getHandler();
rh.sendPosition((int) x, (int) y);
// Forcing a redraw can cause sluggish-looking behavior if the touch
// events arrive quickly.
//rh.sendRedraw();
}
break;
default:
break;
}
return true;
}
/**
* Updates the current state of the controls.
*/
private void updateControls() {
String str = getString(R.string.tfcCameraParams, mCameraPreviewWidth,
mCameraPreviewHeight, mCameraPreviewFps);
TextView tv = (TextView) findViewById(R.id.tfcCameraParams_text);
tv.setText(str);
str = getString(R.string.tfcRectSize, mRectWidth, mRectHeight);
tv = (TextView) findViewById(R.id.tfcRectSize_text);
tv.setText(str);
str = getString(R.string.tfcZoomArea, mZoomWidth, mZoomHeight);
tv = (TextView) findViewById(R.id.tfcZoomArea_text);
tv.setText(str);
}
@Override
public void onClick(View view) {
if (recording) {
recorder.stop();
recording = false;
// Let's initRecorder so we can record again
initRecorder();
prepareRecorder();
} else {
recording = true;
recorder.start();
}
}
private void initRecorder() {
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
CamcorderProfile cpHigh = CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
String path = Environment.getExternalStorageDirectory() + File.separator
+ Environment.DIRECTORY_DCIM + File.separator + "AlphaRun";
recorder.setOutputFile(path);
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
}
private void prepareRecorder() {
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
/**
* Thread that handles all rendering and camera operations.
*/
private static class RenderThread extends Thread implements
SurfaceTexture.OnFrameAvailableListener {
// Object must be created on render thread to get correct Looper, but is used from
// UI thread, so we need to declare it volatile to ensure the UI thread sees a fully
// constructed object.
private volatile RenderHandler mHandler;
// Used to wait for the thread to start.
private Object mStartLock = new Object();
private boolean mReady = false;
private MainHandler mMainHandler;
private Camera mCamera;
private int mCameraPreviewWidth, mCameraPreviewHeight;
private EglCore mEglCore;
private WindowSurface mWindowSurface;
private int mWindowSurfaceWidth;
private int mWindowSurfaceHeight;
// Receives the output from the camera preview.
private SurfaceTexture mCameraTexture;
// Orthographic projection matrix.
private float[] mDisplayProjectionMatrix = new float[16];
private Texture2dProgram mTexProgram;
private final ScaledDrawable2d mRectDrawable =
new ScaledDrawable2d(Drawable2d.Prefab.RECTANGLE);
private final Sprite2d mRect = new Sprite2d(mRectDrawable);
private int mZoomPercent = DEFAULT_ZOOM_PERCENT;
private int mSizePercent = DEFAULT_SIZE_PERCENT;
private int mRotatePercent = DEFAULT_ROTATE_PERCENT;
private float mPosX, mPosY;
/**
* Constructor. Pass in the MainHandler, which allows us to send stuff back to the
* Activity.
*/
public RenderThread(MainHandler handler) {
mMainHandler = handler;
}
/**
* Thread entry point.
*/
@Override
public void run() {
Looper.prepare();
// We need to create the Handler before reporting ready.
mHandler = new RenderHandler(this);
synchronized (mStartLock) {
mReady = true;
mStartLock.notify(); // signal waitUntilReady()
}
// Prepare EGL and open the camera before we start handling messages.
mEglCore = new EglCore(null, 0);
openCamera(REQ_CAMERA_WIDTH, REQ_CAMERA_HEIGHT, REQ_CAMERA_FPS);
Looper.loop();
Log.d(TAG, "looper quit");
releaseCamera();
releaseGl();
mEglCore.release();
synchronized (mStartLock) {
mReady = false;
}
}
/**
* Waits until the render thread is ready to receive messages.
* <p>
* Call from the UI thread.
*/
public void waitUntilReady() {
synchronized (mStartLock) {
while (!mReady) {
try {
mStartLock.wait();
} catch (InterruptedException ie) { /* not expected */ }
}
}
}
/**
* Shuts everything down.
*/
private void shutdown() {
Log.d(TAG, "shutdown");
Looper.myLooper().quit();
}
/**
* Returns the render thread's Handler. This may be called from any thread.
*/
public RenderHandler getHandler() {
return mHandler;
}
/**
* Handles the surface-created callback from SurfaceView. Prepares GLES and the Surface.
*/
private void surfaceAvailable(SurfaceHolder holder, boolean newSurface) {
Surface surface = holder.getSurface();
mWindowSurface = new WindowSurface(mEglCore, surface, false);
mWindowSurface.makeCurrent();
// Create and configure the SurfaceTexture, which will receive frames from the
// camera. We set the textured rect's program to render from it.
mTexProgram = new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT);
int textureId = mTexProgram.createTextureObject();
mCameraTexture = new SurfaceTexture(textureId);
mRect.setTexture(textureId);
if (!newSurface) {
// This Surface was established on a previous run, so no surfaceChanged()
// message is forthcoming. Finish the surface setup now.
//
// We could also just call this unconditionally, and perhaps do an unnecessary
// bit of reallocating if a surface-changed message arrives.
mWindowSurfaceWidth = mWindowSurface.getWidth();
mWindowSurfaceHeight = mWindowSurface.getWidth();
finishSurfaceSetup();
}
mCameraTexture.setOnFrameAvailableListener(this);
}
/**
* Releases most of the GL resources we currently hold (anything allocated by
* surfaceAvailable()).
* </p><p>
* Does not release EglCore.
*/
private void releaseGl() {
GlUtil.checkGlError("releaseGl start");
if (mWindowSurface != null) {
mWindowSurface.release();
mWindowSurface = null;
}
if (mTexProgram != null) {
mTexProgram.release();
mTexProgram = null;
}
GlUtil.checkGlError("releaseGl done");
mEglCore.makeNothingCurrent();
}
/**
* Handles the surfaceChanged message.
* </p><p>
* We always receive surfaceChanged() after surfaceCreated(), but surfaceAvailable()
* could also be called with a Surface created on a previous run. So this may not
* be called.
*/
private void surfaceChanged(int width, int height) {
Log.d(TAG, "RenderThread surfaceChanged " + width + "x" + height);
mWindowSurfaceWidth = width;
mWindowSurfaceHeight = width;
finishSurfaceSetup();
}
/**
* Handles the surfaceDestroyed message.
*/
private void surfaceDestroyed() {
// In practice this never appears to be called -- the activity is always paused
// before the surface is destroyed. In theory it could be called though.
Log.d(TAG, "RenderThread surfaceDestroyed");
releaseGl();
}
/**
* Sets up anything that depends on the window size.
* </p><p>
* Open the camera (to set mCameraAspectRatio) before calling here.
*/
private void finishSurfaceSetup() {
int width = mWindowSurfaceWidth;
int height = mWindowSurfaceHeight;
Log.d(TAG, "finishSurfaceSetup size=" + width + "x" + height +
" camera=" + mCameraPreviewWidth + "x" + mCameraPreviewHeight);
// Use full window.
GLES20.glViewport(0, 700, width, height);
// Simple orthographic projection, with (0,0) in lower-left corner.
Matrix.orthoM(mDisplayProjectionMatrix, 0, 0, width, 0, height, -1, 1);
// Default position is center of screen.
mPosX = width / 2.0f;
mPosY = height / 2.0f;
updateGeometry();
// Ready to go, start the camera.
Log.d(TAG, "starting camera preview");
try {
mCamera.setPreviewTexture(mCameraTexture);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mCamera.startPreview();
}
/**
* Updates the geometry of mRect, based on the size of the window and the current
* values set by the UI.
*/
private void updateGeometry() {
int width = mWindowSurfaceWidth;
int height = mWindowSurfaceHeight;
int smallDim = Math.min(width, height);
// Max scale is a bit larger than the screen, so we can show over-size.
float scaled = smallDim * (mSizePercent / 100.0f) * 1.25f;
float cameraAspect = (float) mCameraPreviewWidth / mCameraPreviewHeight;
int newWidth = Math.round(scaled * cameraAspect);
int newHeight = Math.round(scaled);
float zoomFactor = 1.0f - (mZoomPercent / 100.0f);
int rotAngle = Math.round(360 * (mRotatePercent / 100.0f));
mRect.setScale(newWidth, newHeight);
mRect.setPosition(mPosX, mPosY);
mRect.setRotation(rotAngle);
mRectDrawable.setScale(zoomFactor);
mMainHandler.sendRectSize(newWidth, newHeight);
mMainHandler.sendZoomArea(Math.round(mCameraPreviewWidth * zoomFactor),
Math.round(mCameraPreviewHeight * zoomFactor));
mMainHandler.sendRotateDeg(rotAngle);
}
@Override // SurfaceTexture.OnFrameAvailableListener; runs on arbitrary thread
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
mHandler.sendFrameAvailable();
}
/**
* Handles incoming frame of data from the camera.
*/
private void frameAvailable() {
mCameraTexture.updateTexImage();
draw();
}
/**
* Draws the scene and submits the buffer.
*/
private void draw() {
GlUtil.checkGlError("draw start");
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
mRect.draw(mTexProgram, mDisplayProjectionMatrix);
mWindowSurface.swapBuffers();
GlUtil.checkGlError("draw done");
}
/**
* Opens a camera, and attempts to establish preview mode at the specified width
* and height with a fixed frame rate.
* </p><p>
* Sets mCameraPreviewWidth / mCameraPreviewHeight.
*/
private void openCamera(int desiredWidth, int desiredHeight, int desiredFps) {
if (mCamera != null) {
throw new RuntimeException("camera already initialized");
}
Camera.CameraInfo info = new Camera.CameraInfo();
// Try to find a front-facing camera (e.g. for videoconferencing).
int numCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numCameras; i++) {
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
mCamera = Camera.open(i);
break;
}
}
if (mCamera == null) {
Log.d(TAG, "No front-facing camera found; opening default");
mCamera = Camera.open(); // opens first back-facing camera
}
if (mCamera == null) {
throw new RuntimeException("Unable to open camera");
}
Camera.Parameters parms = mCamera.getParameters();
CameraUtils.choosePreviewSize(parms, desiredWidth, desiredHeight);
parms.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
// Try to set the frame rate to a constant value.
int thousandFps = CameraUtils.chooseFixedPreviewFps(parms, desiredFps * 1000);
// Give the camera a hint that we're recording video. This can have a big
// impact on frame rate.
parms.setRecordingHint(true);
mCamera.setParameters(parms);
int[] fpsRange = new int[2];
Camera.Size mCameraPreviewSize = parms.getPreviewSize();
parms.getPreviewFpsRange(fpsRange);
String previewFacts = mCameraPreviewSize.width + "x" + mCameraPreviewSize.height;
if (fpsRange[0] == fpsRange[1]) {
previewFacts += " @" + (fpsRange[0] / 1000.0) + "fps";
} else {
previewFacts += " @[" + (fpsRange[0] / 1000.0) +
" - " + (fpsRange[1] / 1000.0) + "] fps";
}
Log.i(TAG, "Camera config: " + previewFacts);
mCameraPreviewWidth = mCameraPreviewSize.width;
mCameraPreviewHeight = mCameraPreviewSize.height;
mMainHandler.sendCameraParams(mCameraPreviewWidth, mCameraPreviewHeight,
thousandFps / 1000.0f);
}
/**
* Stops camera preview, and releases the camera to the system.
*/
private void releaseCamera() {
if (mCamera != null) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
Log.d(TAG, "releaseCamera -- done");
}
}
}
}
</p> -
360 degree video of my OpenGL game
23 août 2016, par woidlerI want to make a 360 degree video of my OpenGL game.
Concerning the rendering :
Is it enough to render it in OpenGL with a specific projection matrix ?
If yes, which one ?
Or can I render it into a cube map, and then encode it ?
(Which will require much more rendering power and be more complicated, which I want to avoid)And how do I encode a 360 degree video with FFMPEG ?