Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
What is the best way to merge (concat) mp4 files in android ?
26 mars 2017, par GlimpseI am build an camera app which will allow users to pause & resume recording of an video. Currently pause & resume is possible using MediaRecorder but only for SDK >= 24.
For version SDK < 24 I am using mediaRecorder.stop() & mediaRecorder.start(). Now I must merge those separate mp4 files into one.
This is the current approach using FFMPEG (but with no luck):
private void mergeVideos() { if (filePaths.size() == 1) { cropVideoToSquare(); return; } List
cmdList = new ArrayList<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < filePaths.size(); i++) { cmdList.add("-i"); cmdList.add(filePaths.get(i)); sb.append("[").append(i).append(":0] [").append(i).append(":1]"); } sb.append(" concat=n=").append(filePaths.size()).append(":v=1:a=1 [v] [a]"); cmdList.add("-filter_complex"); cmdList.add("\'" + sb.toString() + "\'"); cmdList.add("-map"); cmdList.add("\'[v]\'"); cmdList.add("-map"); cmdList.add("\'[a]\'"); cmdList.add("-preset"); cmdList.add("ultrafast"); final String mergedVideoLocation = CameraHelper.generateVideoNameWithPath(); cmdList.add(mergedVideoLocation); sb = new StringBuilder(); for (String str : cmdList) { sb.append(str).append(" "); } String[] cmd = cmdList.toArray(new String[cmdList.size()]); try { ffmpeg = FFmpeg.getInstance(this); ffmpeg.execute(cmd, new MergingHandler() { @Override public void onSuccess(String message) { Log.d("mergeVideos", "onSuccess"); currentFilePath = mergedVideoLocation; cropVideoToSquare(); } @Override public void onFailure(String message) { Log.d("mergeVideos", "onFailure: " + message); pDialog.dismiss(); } @Override public void onStart() { Log.d("mergeVideos", "onStart"); pDialog.show(); } }); } catch (FFmpegCommandAlreadyRunningException e) { e.printStackTrace(); } } The exception that I am getting:
ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.8 (GCC) configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --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/home/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= libavutil 55. 17.103 / 55. 17.103 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Pictures/CameraFeatures/VID_20170326_100318.mp4': Metadata: major_brand : 3gp4 minor_version : 0 compatible_brands: isom3gp4 creation_time : 2017-03-26 08:03:24 Duration: 00:00:04.82, start: 0.000000, bitrate: N/A Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 7764 kb/s, 30.02 fps, 30 tbr, 90k tbn, 300 tbc (default) Metadata: rotate : 90 creation_time : 2017-03-26 08:03:24 handler_name : VideoHandle Side data: displaymatrix: rotation of -90.00 degrees Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default) Metadata: creation_time : 2017-03-26 08:03:24 handler_name : SoundHandle /storage/emulated/0/Pictures/CameraFeatures/VID_20170326_100328.mp4: No such file or directory
Can someone point out what am I doing wrong?
-
ffmpeg dont change time duration
26 mars 2017, par combo_ciI tried to convert a UDP stream (that genrated from DVB signal) to HLS m3u8 file with this code:
ffmpeg -i udp://239.1.2.1:60001 -acodec aac -strict -2 -vcodec libx264 -hls_wrap 100 -f hls /var/www/html/ts/1.m3u8
and output m3u8 file is :
#EXTM3U #EXT-X-VERSION:3 #EXT-X-TARGETDURATION:3 #EXT-X-MEDIA-SEQUENCE:66 #EXTINF:0.960000, 21.ts #EXTINF:2.080000, 22.ts #EXTINF:2.400000, 23.ts #EXTINF:1.760000, 24.ts #EXTINF:2.080000, 20.ts
I tried to change the target duration to 10 in this file with the option
-segment_time 10
but the target duration doesn't change in m3u8 file, can anybody help me with this problem? -
ffmpeg : How can a MOV with transparent background be created ?
25 mars 2017, par MatI'm trying - with no success at all - to convert the green pixels of a background into transparent ones and output the result as clip with ffmpeg. N.b. I do not want to lay the clip over anything; I'm not having a problem with that. What I want is a clip with transparent background for the OpenShot video editor (the chromakey filter of which doesn't work satisfyingly).
What I have tried (amongst 1 zillion other things over the last 15 hrs.) was
ffmpeg.exe -i in.mov -vf chromakey=0x008001:0.115:0.0 -c:v qtrle out.mov
but the pixels simply would not be transparent. Seemingly, nothing happens. I reckon the filter is ok, because it works fine in a complex chain (overlaying a background image).
The output of ffprompt -show_stream -show_format of out.mov is as follows:
[STREAM] index=0 codec_name=qtrle codec_long_name=QuickTime Animation (RLE) video profile=unknown codec_type=video codec_time_base=1/30 codec_tag_string=rle codec_tag=0x20656c72 width=1920 height=1080 coded_width=1920 coded_height=1080 has_b_frames=0 sample_aspect_ratio=1:1 display_aspect_ratio=16:9 pix_fmt=bgra level=-99 color_range=N/A color_space=unknown color_transfer=unknown color_primaries=unknown chroma_location=unspecified field_order=progressive timecode=N/A refs=1 id=N/A r_frame_rate=30/1 avg_frame_rate=30/1 time_base=1/15360 start_pts=0 start_time=0.000000 duration_ts=54789 duration=3.566992 bit_rate=822383192 max_bit_rate=N/A bits_per_raw_sample=N/A nb_frames=107 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=1 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng TAG:handler_name=DataHandler TAG:encoder=Lavc57.64.101 qtrle [/STREAM] [STREAM] 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=mp4a codec_tag=0x6134706d sample_fmt=fltp sample_rate=44100 channels=2 channel_layout=stereo bits_per_sample=0 id=N/A r_frame_rate=0/0 avg_frame_rate=0/0 time_base=1/44100 start_pts=926 start_time=0.020998 duration_ts=157481 duration=3.570998 bit_rate=132103 max_bit_rate=132103 bits_per_raw_sample=N/A nb_frames=153 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=1 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng TAG:handler_name=DataHandler [/STREAM] [FORMAT] filename=out.mov nb_streams=2 nb_programs=0 format_name=mov,mp4,m4a,3gp,3g2,mj2 format_long_name=QuickTime / MOV start_time=0.000000 duration=3.567000 size=366708874 bit_rate=822447712 probe_score=100 TAG:major_brand=qt TAG:minor_version=512 TAG:compatible_brands=qt TAG:encoder=Lavf57.56.101 [/FORMAT]
I have a "sample" clip which shows the behaviour I want, with the following stream and information:
[STREAM] index=0 codec_name=qtrle codec_long_name=QuickTime Animation (RLE) video profile=unknown codec_type=video codec_time_base=1/24 codec_tag_string=rle codec_tag=0x20656c72 width=1920 height=1080 coded_width=1920 coded_height=1080 has_b_frames=0 sample_aspect_ratio=0:1 display_aspect_ratio=0:1 pix_fmt=bgra level=-99 color_range=N/A color_space=unknown color_transfer=unknown color_primaries=unknown chroma_location=unspecified field_order=progressive timecode=N/A refs=1 id=N/A r_frame_rate=24/1 avg_frame_rate=24/1 time_base=1/12288 start_pts=0 start_time=0.000000 duration_ts=74760 duration=6.083984 bit_rate=49226848 max_bit_rate=N/A bits_per_raw_sample=N/A nb_frames=146 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=1 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng TAG:handler_name=DataHandler TAG:encoder=Lavc57.24.102 qtrle [/STREAM] [STREAM] index=1 codec_name=aac codec_long_name=AAC (Advanced Audio Coding) profile=LC codec_type=audio codec_time_base=1/48000 codec_tag_string=mp4a codec_tag=0x6134706d sample_fmt=fltp sample_rate=48000 channels=2 channel_layout=stereo bits_per_sample=0 id=N/A r_frame_rate=0/0 avg_frame_rate=0/0 time_base=1/48000 start_pts=0 start_time=0.000000 duration_ts=293856 duration=6.122000 bit_rate=53537 max_bit_rate=128000 bits_per_raw_sample=N/A nb_frames=288 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=1 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng TAG:handler_name=DataHandler [/STREAM] [FORMAT] filename=templateOK.mov nb_streams=2 nb_programs=0 format_name=mov,mp4,m4a,3gp,3g2,mj2 format_long_name=QuickTime / MOV start_time=0.000000 duration=6.144000 size=37478506 bit_rate=48800138 probe_score=100 TAG:major_brand=qt TAG:minor_version=512 TAG:compatible_brands=qt TAG:encoder=Lavf57.25.100 [/FORMAT]
and I simply am not able to spot the relevant difference.
The input, output and the working template can be found here.
(The security issue you might see when clicking the link comes from the server certificate being self-signed. You can accept a temporal exception. Btw: The ridiculous file size of the output file will be the next nut to crack. Probably something about compression.)
-
Embedding many small movies in page (gif vs mp4 vs webm vs ?)
25 mars 2017, par genekoganI am making a webpage which will contain around 20-25 small-resolution (~56x56) and short-length (~3 sec) movies which will be set to autoplay and loop, so they will be looping on the page at all times. They are mostly dispersed throughout the page, so cannot easily be merged into bigger movies.
I'm trying to decide on the right format to use, balancing filesize, quality, and processor overhead.
mp4 seems the best option in terms of quality and filesize, however embedding many small mp4s on the page felt to me slow and made my computer get hot. Despite the fact that if they were one mp4, it would be only around 300x240 -- it seems there is a lot of CPU overhead if they are divided.
gif is lower quality and bigger filesize, but the CPU performance felt smoother. I can't prove it though because I didn't measure it -- are gif's known to be better performance than mp4?
I have not tried other formats (webm, avi, ogg, etc) but I am unsure of how supported all of these formats are by most browsers and I want the webpage to be viewable from multiple browsers/countries.
How can I determine the best format to use for these videos? Is there a tool which can measure the CPU performance of my webpage so I can quantify the performance issues?
-
Solved : ffmpeg : How can a MOV with transparent background be created ?
25 mars 2017, par Mat(Remark: the error sat, as usual, between back-rest and keyboard. Thanks, Mulvya!)
Hi, specialists!
I'm trying - with no success at all - to convert the green pixels of a background into transparent ones and output the result as clip with ffmpeg. N.b. I do not want to lay the clip over anything; I'm not having a problem with that. What I want is a clip with transparent background for the OpenShot video editor (the chromakey filter of which doesn't work satisfyingly).
What I have tried (amongst a felt 1 zillion other things over the last 15 hrs.) was
ffmpeg.exe -i in.mov -vf chromakey=0x008001:0.115:0.0 -c:v qtrle out.mov
but the pixels simply would not be transparent. Seemingly, nothing happens. I reckon the filter is ok, because it works fine in a complex chain (overlaying a background image).
The output of ffprompt -show_stream -show_format of out.mov is as follows:
[STREAM] index=0 codec_name=qtrle codec_long_name=QuickTime Animation (RLE) video profile=unknown codec_type=video codec_time_base=1/30 codec_tag_string=rle codec_tag=0x20656c72 width=1920 height=1080 coded_width=1920 coded_height=1080 has_b_frames=0 sample_aspect_ratio=1:1 display_aspect_ratio=16:9 pix_fmt=bgra level=-99 color_range=N/A color_space=unknown color_transfer=unknown color_primaries=unknown chroma_location=unspecified field_order=progressive timecode=N/A refs=1 id=N/A r_frame_rate=30/1 avg_frame_rate=30/1 time_base=1/15360 start_pts=0 start_time=0.000000 duration_ts=54789 duration=3.566992 bit_rate=822383192 max_bit_rate=N/A bits_per_raw_sample=N/A nb_frames=107 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=1 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng TAG:handler_name=DataHandler TAG:encoder=Lavc57.64.101 qtrle [/STREAM] [STREAM] 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=mp4a codec_tag=0x6134706d sample_fmt=fltp sample_rate=44100 channels=2 channel_layout=stereo bits_per_sample=0 id=N/A r_frame_rate=0/0 avg_frame_rate=0/0 time_base=1/44100 start_pts=926 start_time=0.020998 duration_ts=157481 duration=3.570998 bit_rate=132103 max_bit_rate=132103 bits_per_raw_sample=N/A nb_frames=153 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=1 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng TAG:handler_name=DataHandler [/STREAM] [FORMAT] filename=out.mov nb_streams=2 nb_programs=0 format_name=mov,mp4,m4a,3gp,3g2,mj2 format_long_name=QuickTime / MOV start_time=0.000000 duration=3.567000 size=366708874 bit_rate=822447712 probe_score=100 TAG:major_brand=qt TAG:minor_version=512 TAG:compatible_brands=qt TAG:encoder=Lavf57.56.101 [/FORMAT]
I have a "sample" clip which shows the behaviour I want, with the following stream and information:
[STREAM] index=0 codec_name=qtrle codec_long_name=QuickTime Animation (RLE) video profile=unknown codec_type=video codec_time_base=1/24 codec_tag_string=rle codec_tag=0x20656c72 width=1920 height=1080 coded_width=1920 coded_height=1080 has_b_frames=0 sample_aspect_ratio=0:1 display_aspect_ratio=0:1 pix_fmt=bgra level=-99 color_range=N/A color_space=unknown color_transfer=unknown color_primaries=unknown chroma_location=unspecified field_order=progressive timecode=N/A refs=1 id=N/A r_frame_rate=24/1 avg_frame_rate=24/1 time_base=1/12288 start_pts=0 start_time=0.000000 duration_ts=74760 duration=6.083984 bit_rate=49226848 max_bit_rate=N/A bits_per_raw_sample=N/A nb_frames=146 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=1 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng TAG:handler_name=DataHandler TAG:encoder=Lavc57.24.102 qtrle [/STREAM] [STREAM] index=1 codec_name=aac codec_long_name=AAC (Advanced Audio Coding) profile=LC codec_type=audio codec_time_base=1/48000 codec_tag_string=mp4a codec_tag=0x6134706d sample_fmt=fltp sample_rate=48000 channels=2 channel_layout=stereo bits_per_sample=0 id=N/A r_frame_rate=0/0 avg_frame_rate=0/0 time_base=1/48000 start_pts=0 start_time=0.000000 duration_ts=293856 duration=6.122000 bit_rate=53537 max_bit_rate=128000 bits_per_raw_sample=N/A nb_frames=288 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=1 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng TAG:handler_name=DataHandler [/STREAM] [FORMAT] filename=templateOK.mov nb_streams=2 nb_programs=0 format_name=mov,mp4,m4a,3gp,3g2,mj2 format_long_name=QuickTime / MOV start_time=0.000000 duration=6.144000 size=37478506 bit_rate=48800138 probe_score=100 TAG:major_brand=qt TAG:minor_version=512 TAG:compatible_brands=qt TAG:encoder=Lavf57.25.100 [/FORMAT]
and I simply am not able to spot the relevant difference.
Any suggestions would be highly appreciated!
Cheers,
Mat
The input, output and the working template can be found here.
(The security issue you might see when clicking the link comes from the server certificate being self-signed. You can accept a temporal exception. Btw: The ridiculous file size of the output file will be the next nut to crack. Probably s.t. about compression.)