
Recherche avancée
Médias (1)
-
Bug de détection d’ogg
22 mars 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Video
Autres articles (13)
-
Encoding and processing into web-friendly formats
13 avril 2011, parMediaSPIP automatically converts uploaded files to internet-compatible formats.
Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
All uploaded files are stored online in their original format, so you can (...) -
Use, discuss, criticize
13 avril 2011, parTalk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
A discussion list is available for all exchanges between users. -
Supporting all media types
13 avril 2011, parUnlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)
Sur d’autres sites (4935)
-
video after ffmpeg command conversion is not playing on windows
10 décembre 2015, par Hemant KumarI am stuck at a very weird and complex problem, hoping if anyone know the solution :
I am converting user uploaded video using ffmpeg command on server and it was working fine as well. Today I found that if a video is recorded by a webcam from windows, is playing well in linux as well as on windows where as if user is creating a video by webcam from linux, is playing only on linux (any browser). On window it’s screen either show loading icon or black screen while audio is working fine.
I am using following codec :
['-strict', '-2', '-preset slow', '-maxrate 500k', '-bufsize 1000k', vfOption, '-threads 0', '-ab 64k', '-movflags faststart','-vf scale=-1:480', '-metadata:s:v:0 rotate=0', '-vcodec libx264']
I work on linux and using html5 player on my website. I am converting video in mp4 format.
Input :
ffmpeg -i /<server path="path">/stream_FE2AF05B-E630-1F7B-390B-37325B31B362.flv -strict -2 -vcodec libx264 -preset slow -vb 500k -maxrate 500k -bufsize 1000k -vf 'scale=-1:480 ' -threads 0 -ab 64k -s 640x480 -movflags faststart -metadata:s:v:0 rotate=0 /<server path="path">/testing.mp4
</server></server>Output :
ffmpeg version 2.2.5 Copyright (c) 2000-2014 the FFmpeg developers
built on Aug 1 2014 09:24:02 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libtheora --enable-libx264 --enable-libvpx --enable-libmp3lame
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, flv, from '/<server path="path">/stream_FE2AF05B-E630-1F7B-390B-37325B31B362.flv':
Metadata:
canSeekToEnd : true
Duration: 00:00:04.04, start: 0.000000, bitrate: 636 kb/s
Stream #0:0: Video: flv1, yuv420p, 640x480, 1k tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: nellymoser, 44100 Hz, mono, flt
[libx264 @ 0x23c5340] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x23c5340] profile High, level 5.2
[libx264 @ 0x23c5340] 264 - core 142 r2453 ea0ca51 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=24 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=cbr mbtree=1 bitrate=500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=500 vbv_bufsize=1000 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/<server path="path">/testing.mp4':
Metadata:
canSeekToEnd : true
encoder : Lavf55.33.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x480, q=-1--1, 500 kb/s, 16k tbn, 1k tbc
Metadata:
rotate : 0
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, mono, fltp, 64 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (flv -> libx264)
Stream #0:1 -> #0:1 (nellymoser -> aac)
Press [q] to stop, [?] for help
[mp4 @ 0x23c0200] Starting second pass: moving the moov atom to the beginning of the file2 drop=0
frame= 4020 fps=706 q=-1.0 Lsize= 355kB time=00:00:04.08 bitrate= 712.0kbits/s dup=3931 drop=0
video:271kB audio:32kB subtitle:0 data:0 global headers:0kB muxing overhead 16.957901%
[libx264 @ 0x23c5340] frame I:17 Avg QP:27.55 size: 7119
[libx264 @ 0x23c5340] frame P:1013 Avg QP:25.37 size: 88
[libx264 @ 0x23c5340] frame B:2990 Avg QP:27.32 size: 22
[libx264 @ 0x23c5340] consecutive B-frames: 0.8% 0.0% 0.1% 99.1%
[libx264 @ 0x23c5340] mb I I16..4: 42.0% 55.1% 2.9%
[libx264 @ 0x23c5340] mb P I16..4: 0.3% 0.4% 0.0% P16..4: 0.6% 0.1% 0.0% 0.0% 0.0% skip:98.6%
[libx264 @ 0x23c5340] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.2% 0.0% 0.0% direct: 0.0% skip:99.8% L0:35.7% L1:64.3% BI: 0.0%
[libx264 @ 0x23c5340] 8x8 transform intra:55.0% inter:84.5%
[libx264 @ 0x23c5340] direct mvs spatial:87.6% temporal:12.4%
[libx264 @ 0x23c5340] coded y,uvDC,uvAC intra: 33.4% 51.9% 0.7% inter: 0.0% 0.1% 0.0%
[libx264 @ 0x23c5340] i16 v,h,dc,p: 26% 54% 15% 5%
[libx264 @ 0x23c5340] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 16% 53% 3% 1% 2% 2% 3% 3%
[libx264 @ 0x23c5340] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 20% 13% 14% 5% 7% 7% 11% 8%
[libx264 @ 0x23c5340] i8c dc,h,v,p: 43% 31% 23% 3%
[libx264 @ 0x23c5340] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x23c5340] ref P L0: 80.9% 9.0% 6.9% 2.6% 0.7%
[libx264 @ 0x23c5340] ref B L0: 89.4% 8.6% 1.8% 0.2%
[libx264 @ 0x23c5340] ref B L1: 91.0% 9.0%
[libx264 @ 0x23c5340] kb/s:551.72
</server></server>
Outout from file recorded on window :
Input :
ffmpeg -i /<server path="path">/stream_window.flv -strict -2 -vcodec libx264 -preset slow -vb 500k -maxrate 500k -bufsize 1000k -vf 'scale=-1:480 ' -threads 0 -ab 64k -s 640x480 -movflags faststart -metadata:s:v:0 rotate=0 /<server path="path">/testing_1.mp4
</server></server>Output :
ffmpeg version 2.2.5 Copyright (c) 2000-2014 the FFmpeg developers
built on Aug 1 2014 09:24:02 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libtheora --enable-libx264 --enable-libvpx --enable-libmp3lame
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, flv, from '/<server path="path">/stream_window.flv':
Metadata:
canSeekToEnd : true
Duration: 00:00:09.22, start: 0.000000, bitrate: 420 kb/s
Stream #0:0: Video: flv1, yuv420p, 640x480, 1k tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: nellymoser, 44100 Hz, mono, flt
[libx264 @ 0x1e09fc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x1e09fc0] profile High, level 5.2
[libx264 @ 0x1e09fc0] 264 - core 142 r2453 ea0ca51 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=24 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=cbr mbtree=1 bitrate=500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=500 vbv_bufsize=1000 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/<server path="path">/testing_1.mp4':
Metadata:
canSeekToEnd : true
encoder : Lavf55.33.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x480, q=-1--1, 500 kb/s, 16k tbn, 1k tbc
Metadata:
rotate : 0
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, mono, fltp, 64 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (flv -> libx264)
Stream #0:1 -> #0:1 (nellymoser -> aac)
Press [q] to stop, [?] for help
[mp4 @ 0x1e06220] Starting second pass: moving the moov atom to the beginning of the file7 drop=0
frame= 8936 fps=703 q=-1.0 Lsize= 771kB time=00:00:09.26 bitrate= 681.5kbits/s dup=8907 drop=0
video:585kB audio:73kB subtitle:0 data:0 global headers:0kB muxing overhead 17.106213%
[libx264 @ 0x1e09fc0] frame I:40 Avg QP:29.54 size: 7449
[libx264 @ 0x1e09fc0] frame P:2248 Avg QP:30.88 size: 69
[libx264 @ 0x1e09fc0] frame B:6648 Avg QP:39.17 size: 22
[libx264 @ 0x1e09fc0] consecutive B-frames: 0.8% 0.0% 0.1% 99.1%
[libx264 @ 0x1e09fc0] mb I I16..4: 36.8% 60.7% 2.5%
[libx264 @ 0x1e09fc0] mb P I16..4: 0.2% 0.3% 0.0% P16..4: 0.4% 0.0% 0.0% 0.0% 0.0% skip:98.9%
[libx264 @ 0x1e09fc0] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.2% 0.0% 0.0% direct: 0.0% skip:99.8% L0:34.2% L1:65.8% BI: 0.0%
[libx264 @ 0x1e09fc0] 8x8 transform intra:60.6% inter:87.6%
[libx264 @ 0x1e09fc0] direct mvs spatial:72.8% temporal:27.2%
[libx264 @ 0x1e09fc0] coded y,uvDC,uvAC intra: 36.3% 62.8% 4.7% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x1e09fc0] i16 v,h,dc,p: 33% 46% 15% 7%
[libx264 @ 0x1e09fc0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 19% 46% 3% 1% 1% 1% 2% 4%
[libx264 @ 0x1e09fc0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 17% 14% 9% 4% 4% 5% 5% 7%
[libx264 @ 0x1e09fc0] i8c dc,h,v,p: 42% 31% 23% 4%
[libx264 @ 0x1e09fc0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x1e09fc0] ref P L0: 82.6% 9.9% 5.2% 1.7% 0.5%
[libx264 @ 0x1e09fc0] ref B L0: 87.1% 11.0% 1.4% 0.4%
[libx264 @ 0x1e09fc0] ref B L1: 90.3% 9.7%
[libx264 @ 0x1e09fc0] kb/s:536.03
</server></server>
Can anyone figure what could be the problem ?
@LordNeckbeard : Please find the command and its output above. Thanks
-
Issue when combining 2 video files [after matching the specs]
6 décembre 2015, par RuneBasically I got a .mp4 and a .flv file which I want to concatenate (the .mp4 should be the intro).
So after having asked a previous question regarding this I went ahead and converted the intro video to an .flv with matching specifications of the second video.
First I got the specifications of the second (.flv) video using ffprobe. This was the output :
{
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "High",
"codec_type": "video",
"codec_time_base": "1/50",
"codec_tag_string": "[0][0][0][0]",
"codec_tag": "0x0000",
"width": 646,
"height": 364,
"coded_width": 656,
"coded_height": 368,
"has_b_frames": 2,
"sample_aspect_ratio": "1:1",
"display_aspect_ratio": "323:182",
"pix_fmt": "yuv420p",
"level": 30,
"chroma_location": "left",
"refs": 5,
"is_avc": "true",
"nal_length_size": "4",
"r_frame_rate": "25/1",
"avg_frame_rate": "25/1",
"time_base": "1/1000",
"start_pts": 80,
"start_time": "0.080000",
"bit_rate": "400000",
"bits_per_raw_sample": "8",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0
}
},
{
"index": 1,
"codec_name": "aac",
"codec_long_name": "AAC (Advanced Audio Coding)",
"profile": "LC",
"codec_type": "audio",
"codec_time_base": "1/44100",
"codec_tag_string": "[0][0][0][0]",
"codec_tag": "0x0000",
"sample_fmt": "fltp",
"sample_rate": "44100",
"channels": 2,
"channel_layout": "stereo",
"bits_per_sample": 0,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/1000",
"start_pts": 241,
"start_time": "0.241000",
"bit_rate": "96000",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0
}
}
],
"format": {
"filename": "vid2.flv",
"nb_streams": 2,
"nb_programs": 0,
"format_name": "flv",
"format_long_name": "FLV (Flash Video)",
"start_time": "0.080000",
"duration": "371.920000",
"size": "23876671",
"bit_rate": "513587",
"probe_score": 100,
"tags": {
"audiosize": "4476626",
"canSeekToEnd": "true",
"datasize": "23876671",
"videosize": "19004263",
"hasAudio": "true",
"hasCuePoints": "false",
"hasKeyframes": "true",
"hasMetadata": "true",
"hasVideo": "true",
"lasttimestamp": "372",
"metadatacreator": "flvtool++ (Facebook, Motion project, dweatherford)",
"totalframes": "9298",
"encoder": "Lavf56.36.100"
}
}
}Here’s my command :
-i prefix.mp4 -b:v 400k -b:a 96k -r 25 -ar 44100 -acodec aac -vf scale=646:364 -strict -2 prefix.flv
.This produces the following output (as well as the video file) :
ffmpeg version N-76137-gb0bb1dc Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 4.100 / 55. 4.100
libavcodec 57. 7.100 / 57. 7.100
libavformat 57. 8.102 / 57. 8.102
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 12.100 / 6. 12.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.100 / 2. 0.100
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'prefix.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.8.102
Duration: 00:00:05.31, start: 0.000000, bitrate: 1589 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1205 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 384 kb/s (default)
Metadata:
handler_name : SoundHandler
Output #0, flv, to 'prefix.flv':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.8.102
Stream #0:0(und): Video: flv1 (flv) ([2][0][0][0] / 0x0002), yuv420p, 646x364 [SAR 2912:2907 DAR 16:9], q=2-31, 400 kb/s, 25 fps, 1k tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc57.7.100 flv
Stream #0:1(und): Audio: aac ([10][0][0][0] / 0x000A), 44100 Hz, 5.1, fltp, 96 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc57.7.100 aac
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> flv1 (flv))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame= 79 fps=0.0 q=10.7 size= 381kB time=00:00:03.43 bitrate= 908.7kbits/frame= 132 fps=0.0 q=10.1 Lsize= 548kB time=00:00:05.31 bitrate= 844.1kbits/s
video:479kB audio:62kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.161623%
[aac @ 0000021aa893eae0] Qavg: 177.292I then run the outputted video file and it runs just like the old one.
I then concatenate the ouputted intro file with my main video file using the following command (tmp.txt contains the 2 files) :
-f concat -i tmp.txt -c copy newvid.flv
This produces the following output :
ffmpeg version N-76137-gb0bb1dc Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 4.100 / 55. 4.100
libavcodec 57. 7.100 / 57. 7.100
libavformat 57. 8.102 / 57. 8.102
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 12.100 / 6. 12.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.100 / 2. 0.100
libpostproc 54. 0.100 / 54. 0.100
Input #0, concat, from 'tmp.txt':
Duration: N/A, start: 0.000000, bitrate: 496 kb/s
Stream #0:0: Video: flv1, yuv420p, 646x364, 400 kb/s, 25 fps, 25 tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: aac (LC), 44100 Hz, 5.1, fltp, 96 kb/s
[flv @ 00000257b5f0e180] Codec for stream 0 does not use global headers but container format requires global headers
[flv @ 00000257b5f0e180] Codec for stream 1 does not use global headers but container format requires global headers
Output #0, flv, to 'newvid.flv':
Metadata:
encoder : Lavf57.8.102
Stream #0:0: Video: flv1 ([2][0][0][0] / 0x0002), yuv420p, 646x364, q=2-31, 400 kb/s, 25 fps, 25 tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: aac ([10][0][0][0] / 0x000A), 44100 Hz, 5.1, 96 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[flv @ 00000257b56947e0] Packet mismatch 486539264 7424
[flv @ 00000257b56947e0] Auto-inserting h264_mp4toannexb bitstream filter
[flv @ 00000257b5f0e180] Non-monotonous DTS in output stream 0:0; previous: 5263, current: 5255; changing to 5263. This may result in incorrect timestamps in the output file.
frame= 6359 fps=0.0 q=-1.0 size= 15906kB time=00:04:14.30 bitrate= 512.4kbits/frame= 9428 fps=0.0 q=-1.0 Lsize= 23835kB time=00:06:17.05 bitrate= 517.8kbits/s
video:19016kB audio:4403kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.777447%When I try to run the final video (newvid.flv) it plays like this :
It starts off playing the intro just fine.
However, when the intro is finished the video freezes while the sound of the actual video continues for the entire duration of the video.Thus in conclusion what is lacking is the video of the second vid (the audio is fine).
I’m new at using ffmpeg but I’ve tried my best to solve this, which is why I’m asking for your help.
I’d certainly appreciate if someone could help me out.
-
Tap to record like in vine using javacv
8 décembre 2015, par human123I am trying to implement a tap to record feature like in vine. A sample for handling recording (not touch to record) provided in javacv is https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java. I am trying to modify it so that in onPreviewFrame method frames are added to buffer only when user has his finger placed on screen. These frames are then tried to be combined into final video in stopRecording method.
The issue is that if I set the timestamp as given in below code snippet (in stopRecording method)
if (t > recorder.getTimestamp())
{
recorder.setTimestamp(t);
}the behavior is as below
Case 1
If I tap on screen to record for 2 seconds and take the finger away from screen for 3 seconds and then again place finger back on screen to record for another 4 seconds the resulting video is like,
For 1st 2 seconds video has recorded content. For next 3 seconds (time when finger is put away from screen). video just shows the last frame recorded when finger was placed on screen last. Then the video has recorded video content for next 4 seconds. So there seems to be an issue in handling video recording when finger is removed from screen.
Case 2
Next I removed the code setting time stamp to recorder(the code snippet given above) in stopRecording method.
Now the resulting video (for the same steps tried in case 1) does not contain the middle 3 seconds(which is what is required) when finger was taken away from screen. But video is playing at a faster rate. So it seems that we need to set time stamp so that video plays at normal rate.
Full code of my activity is given below. (Please note that video recording is mainly handled from onPreviewFrame and stopRecording methods)
public class TouchToRecordActivity extends Activity implements OnClickListener, View.OnTouchListener {
private final static String CLASS_LABEL = "TouchToRecordActivity";
private final static String LOG_TAG = CLASS_LABEL;
private String ffmpeg_link = "/mnt/sdcard/stream.mp4";
long startTime = 0;
boolean recording = false;
boolean rec = false;
private FFmpegFrameRecorder recorder;
private boolean isPreviewOn = false;
private int sampleAudioRateInHz = 44100;
private int imageWidth = 640;
private int imageHeight = 480;
private int destWidth = 480;
private int frameRate = 30;
/* audio data getting thread */
private AudioRecord audioRecord;
private AudioRecordRunnable audioRecordRunnable;
private Thread audioThread;
volatile boolean runAudioThread = true;
/* video data getting thread */
private Camera cameraDevice;
private CameraView cameraView;
private Frame yuvImage = null;
/* layout setting */
private final int bg_screen_bx = 232;
private final int bg_screen_by = 128;
private final int bg_screen_width = 700;
private final int bg_screen_height = 500;
private final int bg_width = 1123;
private final int bg_height = 715;
private final int live_width = 640;
private final int live_height = 480;
private int screenWidth, screenHeight;
private Button btnRecorderControl;
/* The number of seconds in the continuous record loop (or 0 to disable loop). */
final int RECORD_LENGTH = 20;
Frame[] images;
long[] timestamps;
ShortBuffer[] samples;
int imagesIndex, samplesIndex;
long firstTime = 0;
long startPauseTime = 0;
long totalPauseTime = 0;
long pausedTime = 0;
long stopPauseTime = 0;
long totalTime = 0;
long totalRecordedTS = 0;
private TextView txtTimer;
private Handler mHandler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.touch_main);
initLayout();
}
@Override
protected void onDestroy() {
super.onDestroy();
recording = false;
if (cameraView != null) {
cameraView.stopPreview();
}
if (cameraDevice != null) {
cameraDevice.stopPreview();
cameraDevice.release();
cameraDevice = null;
}
}
private void initLayout() {
/* get size of screen */
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
RelativeLayout.LayoutParams layoutParam = null;
LayoutInflater myInflate = null;
myInflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout topLayout = new RelativeLayout(this);
setContentView(topLayout);
LinearLayout preViewLayout = (LinearLayout) myInflate.inflate(R.layout.touch_main, null);
layoutParam = new RelativeLayout.LayoutParams(screenWidth, screenHeight);
topLayout.addView(preViewLayout, layoutParam);
txtTimer = (TextView) preViewLayout.findViewById(R.id.txtTimer);
/* add control button: start and stop */
btnRecorderControl = (Button) findViewById(R.id.recorder_control);
btnRecorderControl.setText("Start");
btnRecorderControl.setOnClickListener(this);
/* add camera view */
int display_width_d = (int) (1.0 * bg_screen_width * screenWidth / bg_width);
int display_height_d = (int) (1.0 * bg_screen_height * screenHeight / bg_height);
int prev_rw, prev_rh;
if (1.0 * display_width_d / display_height_d > 1.0 * live_width / live_height) {
prev_rh = display_height_d;
prev_rw = (int) (1.0 * display_height_d * live_width / live_height);
} else {
prev_rw = display_width_d;
prev_rh = (int) (1.0 * display_width_d * live_height / live_width);
}
layoutParam = new RelativeLayout.LayoutParams(prev_rw, prev_rh);
layoutParam.topMargin = (int) (1.0 * bg_screen_by * screenHeight / bg_height);
layoutParam.leftMargin = (int) (1.0 * bg_screen_bx * screenWidth / bg_width);
cameraDevice = Camera.open();
Log.i(LOG_TAG, "cameara open");
cameraView = new CameraView(this, cameraDevice);
topLayout.addView(cameraView, layoutParam);
topLayout.setOnTouchListener(this);
Log.i(LOG_TAG, "cameara preview start: OK");
}
//---------------------------------------
// initialize ffmpeg_recorder
//---------------------------------------
private void initRecorder() {
Log.w(LOG_TAG, "init recorder");
if (RECORD_LENGTH > 0) {
imagesIndex = 0;
images = new Frame[RECORD_LENGTH * frameRate];
timestamps = new long[images.length];
for (int i = 0; i < images.length; i++) {
images[i] = new Frame(destWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
timestamps[i] = -1;
}
} else if (yuvImage == null) {
yuvImage = new Frame(destWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
Log.i(LOG_TAG, "create yuvImage");
}
Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link);
recorder = new FFmpegFrameRecorder(ffmpeg_link, destWidth, imageHeight, 1);
recorder.setFormat("mp4");
recorder.setVideoCodecName("libx264");
recorder.setSampleRate(sampleAudioRateInHz);
// Set in the surface changed method
recorder.setFrameRate(frameRate);
Log.i(LOG_TAG, "recorder initialize success");
audioRecordRunnable = new AudioRecordRunnable();
audioThread = new Thread(audioRecordRunnable);
runAudioThread = true;
}
public void startRecording() {
initRecorder();
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(mUpdateTimeTask, 100);
try {
recorder.start();
startTime = System.currentTimeMillis();
recording = true;
audioThread.start();
} catch (FFmpegFrameRecorder.Exception e) {
e.printStackTrace();
}
}
public void stopRecording() {
runAudioThread = false;
try {
audioThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
audioRecordRunnable = null;
audioThread = null;
if (recorder != null && recording) {
if (RECORD_LENGTH > 0) {
Log.v(LOG_TAG, "Writing frames");
try {
int firstIndex = imagesIndex % samples.length;
int lastIndex = (imagesIndex - 1) % images.length;
if (imagesIndex <= images.length) {
firstIndex = 0;
lastIndex = imagesIndex - 1;
}
if ((startTime = timestamps[lastIndex] - RECORD_LENGTH * 1000000L) < 0) {
startTime = 0;
}
if (lastIndex < firstIndex) {
lastIndex += images.length;
}
int videoCounter = 0;
for (int i = firstIndex; i <= lastIndex; i++) {
if (timestamps[i] == -1) {
Log.v(LOG_TAG, "frame not recorded");
}
if (timestamps[i] != -1) {
long t = timestamps[i % timestamps.length] - startTime;
if (t >= 0) {
videoCounter++;
/*if (((i % images.length) != 0) && images[i % images.length] != images[(i % images.length) - 1]) {
if (t > recorder.getTimestamp()) {
recorder.setTimestamp(t);
}*/
Log.v(LOG_TAG, "imageIndex=" + (i % images.length));
recorder.record(images[i % images.length]);
/* }*/
Log.v(LOG_TAG, "videoCounter=" + videoCounter);
}
}
}
firstIndex = samplesIndex % samples.length;
lastIndex = (samplesIndex - 1) % samples.length;
if (samplesIndex <= samples.length) {
firstIndex = 0;
lastIndex = samplesIndex - 1;
}
if (lastIndex < firstIndex) {
lastIndex += samples.length;
}
for (int i = firstIndex; i <= lastIndex; i++) {
if (timestamps[i] != -1) {
recorder.recordSamples(samples[i % samples.length]);
}
}
} catch (FFmpegFrameRecorder.Exception e) {
Log.v(LOG_TAG, e.getMessage());
e.printStackTrace();
}
}
recording = false;
Log.v(LOG_TAG, "Finishing recording, calling stop and release on recorder");
try {
recorder.stop();
recorder.release();
} catch (FFmpegFrameRecorder.Exception e) {
e.printStackTrace();
}
recorder = null;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (recording) {
stopRecording();
}
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.v(LOG_TAG, "ACTION_DOWN" + recording);
if (!recording) {
startRecording();
} else {
stopPauseTime = System.currentTimeMillis();
totalPauseTime = stopPauseTime - startPauseTime - ((long) (1.0 / (double) frameRate) * 1000);
pausedTime += totalPauseTime;
}
rec = true;
setTotalVideoTime();
btnRecorderControl.setText(getResources().getString(R.string.stop));
break;
case MotionEvent.ACTION_MOVE:
rec = true;
setTotalVideoTime();
break;
case MotionEvent.ACTION_UP:
Log.v(LOG_TAG, "ACTION_UP");
rec = false;
startPauseTime = System.currentTimeMillis();
break;
}
return true;
}
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
if (recording) {
setTotalVideoTime();
}
mHandler.postDelayed(this, 500);
}
};
private synchronized void setTotalVideoTime() {
totalTime = System.currentTimeMillis() - firstTime - pausedTime - ((long) (1.0 / (double) frameRate) * 1000);
if (totalTime > 0)
txtTimer.setText(getRecordingTimeFromMillis(totalTime));
}
private String getRecordingTimeFromMillis(long millis) {
String strRecordingTime = null;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
int hours = minutes / 60;
if (hours >= 0 && hours < 10)
strRecordingTime = "0" + hours + ":";
else
strRecordingTime = hours + ":";
if (hours > 0)
minutes = minutes % 60;
if (minutes >= 0 && minutes < 10)
strRecordingTime += "0" + minutes + ":";
else
strRecordingTime += minutes + ":";
seconds = seconds % 60;
if (seconds >= 0 && seconds < 10)
strRecordingTime += "0" + seconds;
else
strRecordingTime += seconds;
return strRecordingTime;
}
//---------------------------------------------
// audio thread, gets and encodes audio data
//---------------------------------------------
class AudioRecordRunnable implements Runnable {
@Override
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
// Audio
int bufferSize;
ShortBuffer audioData;
int bufferReadResult;
bufferSize = AudioRecord.getMinBufferSize(sampleAudioRateInHz,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleAudioRateInHz,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
if (RECORD_LENGTH > 0) {
samplesIndex = 0;
samples = new ShortBuffer[RECORD_LENGTH * sampleAudioRateInHz * 2 / bufferSize + 1];
for (int i = 0; i < samples.length; i++) {
samples[i] = ShortBuffer.allocate(bufferSize);
}
} else {
audioData = ShortBuffer.allocate(bufferSize);
}
Log.d(LOG_TAG, "audioRecord.startRecording()");
audioRecord.startRecording();
/* ffmpeg_audio encoding loop */
while (runAudioThread) {
if (RECORD_LENGTH > 0) {
audioData = samples[samplesIndex++ % samples.length];
audioData.position(0).limit(0);
}
//Log.v(LOG_TAG,"recording? " + recording);
bufferReadResult = audioRecord.read(audioData.array(), 0, audioData.capacity());
audioData.limit(bufferReadResult);
if (bufferReadResult > 0) {
Log.v(LOG_TAG, "bufferReadResult: " + bufferReadResult);
// If "recording" isn't true when start this thread, it never get's set according to this if statement...!!!
// Why? Good question...
if (recording && rec) {
Log.v(LOG_TAG, "Recording audio");
if (RECORD_LENGTH <= 0) try {
recorder.recordSamples(audioData);
//Log.v(LOG_TAG,"recording " + 1024*i + " to " + 1024*i+1024);
} catch (FFmpegFrameRecorder.Exception e) {
Log.v(LOG_TAG, e.getMessage());
e.printStackTrace();
}
}
}
}
Log.v(LOG_TAG, "AudioThread Finished, release audioRecord");
/* encoding finish, release recorder */
if (audioRecord != null) {
audioRecord.stop();
audioRecord.release();
audioRecord = null;
Log.v(LOG_TAG, "audioRecord released");
}
}
}
//---------------------------------------------
// camera thread, gets and encodes video data
//---------------------------------------------
class CameraView extends SurfaceView implements SurfaceHolder.Callback, PreviewCallback {
private SurfaceHolder mHolder;
private Camera mCamera;
public CameraView(Context context, Camera camera) {
super(context);
Log.w("camera", "camera view");
mCamera = camera;
mHolder = getHolder();
mHolder.addCallback(CameraView.this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mCamera.setPreviewCallback(CameraView.this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
stopPreview();
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
stopPreview();
Camera.Parameters camParams = mCamera.getParameters();
List sizes = camParams.getSupportedPreviewSizes();
// Sort the list in ascending order
Collections.sort(sizes, new Comparator() {
public int compare(final Camera.Size a, final Camera.Size b) {
return a.width * a.height - b.width * b.height;
}
});
camParams.setPreviewSize(imageWidth, imageHeight);
Log.v(LOG_TAG, "Setting imageWidth: " + imageWidth + " imageHeight: " + imageHeight + " frameRate: " + frameRate);
camParams.setPreviewFrameRate(frameRate);
Log.v(LOG_TAG, "Preview Framerate: " + camParams.getPreviewFrameRate());
mCamera.setParameters(camParams);
List videoSizes = mCamera.getParameters().getSupportedVideoSizes();
// Set the holder (which might have changed) again
try {
mCamera.setPreviewDisplay(holder);
mCamera.setPreviewCallback(CameraView.this);
startPreview();
} catch (Exception e) {
Log.e(LOG_TAG, "Could not set preview display in surfaceChanged");
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
try {
mHolder.addCallback(null);
mCamera.setPreviewCallback(null);
} catch (RuntimeException e) {
// The camera has probably just been released, ignore.
}
}
public void startPreview() {
if (!isPreviewOn && mCamera != null) {
isPreviewOn = true;
mCamera.startPreview();
}
}
public void stopPreview() {
if (isPreviewOn && mCamera != null) {
isPreviewOn = false;
mCamera.stopPreview();
}
}
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (audioRecord == null || audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
startTime = System.currentTimeMillis();
return;
}
if (RECORD_LENGTH > 0) {
int i = imagesIndex++ % images.length;
Log.v(LOG_TAG, "recording:" + recording + "rec:" + rec);
if (recording && rec) {
yuvImage = images[i];
timestamps[i] = 1000 * (System.currentTimeMillis() - startTime);
totalRecordedTS++;
} else {
Log.v(LOG_TAG, "recording is paused");
yuvImage = null;
timestamps[i] = -1;
}
}
/* get video data */
if (yuvImage != null && recording && rec) {
if (data.length != imageWidth * imageHeight) {
Camera.Size sz = camera.getParameters().getPreviewSize();
imageWidth = sz.width;
imageHeight = sz.height;
destWidth = imageHeight;
Log.v(LOG_TAG, "data length:" + data.length);
}
ByteBuffer bb = (ByteBuffer) yuvImage.image[0].position(0); // resets the buffer
int start = 2 * ((imageWidth - destWidth) / 4); // this must be even
for (int row = 0; row < imageHeight * 3 / 2; row++) {
bb.put(data, start, destWidth);
start += imageWidth;
}
}
}
}
@Override
public void onClick(View v) {
if (!recording) {
startRecording();
Log.w(LOG_TAG, "Start Button Pushed");
btnRecorderControl.setText("Stop");
} else {
// This will trigger the audio recording loop to stop and then set isRecorderStart = false;
stopRecording();
Log.w(LOG_TAG, "Stop Button Pushed");
btnRecorderControl.setText("Start");
}
}}Changes made as per Alex Cohn’s suggestions
Suggestion 1 - Estimate average frame rate
public void stopRecording() {
..............................
if (((i % images.length) != 0) && images[i % images.length] != images[(i % images.length) - 1]) {
if (t > recorder.getTimestamp()) {
t += 1000000 / frameRate;
recorder.setTimestamp(t);
}
recorder.record(images[i % images.length]);
}
..........................................
}Change made was adding t += 1000000 / frameRate ; But this caused the video to freeze (as in case 1 described above) in portions when finger was placed away from screen.
Suggestion 2 - Modification in onPreviewFrame()
long[] timestampsForRecorder;
private void initRecorder() {
Log.w(LOG_TAG, "init recorder");
if (RECORD_LENGTH > 0) {
.......................................................
timestampsForRecorder = new long[images.length];
for (int i = 0; i < images.length; i++) {
images[i] = new Frame(destWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
timestamps[i] = -1;
timestampsForRecorder[i] = -1;
}
} else if (yuvImage == null) {
yuvImage = new Frame(destWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
Log.i(LOG_TAG, "create yuvImage");
}
...................................................
}
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (audioRecord == null || audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
startTime = SystemClock.elapsedRealtime();
return;
}
if (RECORD_LENGTH > 0) {
int i = imagesIndex++ % images.length;
Log.v(LOG_TAG, "recording:" + recording + "rec:" + rec);
if (recording && rec) {
yuvImage = images[i];
long thisFrameTime = SystemClock.elapsedRealtime();
timestamps[i] = thisFrameTime;
long lastFrameTime = timestamps[(int) (imagesIndex == 0 ? startTime : ((imagesIndex-1) % images.length))];
Log.v(LOG_TAG, "lastFrameTime:" + lastFrameTime+",stopPauseTime:" + stopPauseTime);
if (lastFrameTime > stopPauseTime) {
timestampsForRecorder[i] = 1000 * (thisFrameTime - Math.max(stopPauseTime, lastFrameTime));
}
}
}
.....................................................
}
public void stopRecording() {
.......................................................
if (recorder != null && recording) {
if (RECORD_LENGTH > 0) {
Log.v(LOG_TAG, "Writing frames");
try {
int firstIndex = imagesIndex % samples.length;
int lastIndex = (imagesIndex - 1) % images.length;
if (imagesIndex <= images.length) {
firstIndex = 0;
lastIndex = imagesIndex - 1;
}
if ((startTime = timestampsForRecorder[lastIndex] - RECORD_LENGTH * 1000000L) < 0) {
startTime = 0;
}
if (lastIndex < firstIndex) {
lastIndex += images.length;
}
for (int i = firstIndex; i <= lastIndex; i++) {
if (timestampsForRecorder[i] != -1) {
long t = timestampsForRecorder[i % timestampsForRecorder.length] - startTime;
if (t >= 0) {
if (((i % images.length) != 0) && images[i % images.length] != images[(i % images.length) - 1]) {
if (t > recorder.getTimestamp()) {
recorder.setTimestamp(t);
}
Log.v(LOG_TAG, "imageIndex=" + (i % images.length));
recorder.record(images[i % images.length]);
}
}
}
}
.............................................
} catch (FFmpegFrameRecorder.Exception e) {
.................................
}
}
...........................................
}
}The video recorded using this was having the issue in case 2 mentioned above. ie,It was playing at a faster rate