Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Use ffmpeg on OSX Xcode Project for Mac
21 décembre 2018, par cmarioI am planning to create a new app for personal use on my Mac that uses FFMPEG library, to store a feed from a RTSP IP camera.
Following this official installation procedure from FFMPEG I have manage to successfully achieve the following 2 steps:
To get ffmpeg for OS X, you first have to install Homebrew. If you don't want to use Homebrew, see the section below.
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then:
- brew install automake fdk-aac git lame libass libtool libvorbis libvpx \ opus sdl shtool texi2html theora wget x264 xvid yasmQuestion: My question here because I am confused, is how to import a library into Xcode so I can use it in the application I am about to build for my Mac. I can see plenty of GitHub projects related to FFMPEG with IOS/Android, but none for OSX.
All the FFMPEG commands under terminal are working fine, such as converting a video etc.
-
Piping images to FFmpeg stdin
21 décembre 2018, par Vincent BavaroGood morning, I need to stream trough hls many images that come in a folder as if they were video frames. I don't know prior how many they are so I believe I need to keep FFmpeg opened and passing them via stdin. I read this article already create video from growing image sequence and I changed the c# code to fit my problem like this :
using System; using System.IO; using System.Threading; using System.Threading.Tasks; using System.Diagnostics; using System.ComponentModel; namespace Example { public class Example { static void Main() { AsyncMain().GetAwaiter().GetResult(); } static async Task AsyncMain() { Console.WriteLine("Press any button to quit."); var maintask = RunFFMPEG(); var readtask = Task.Run(() => Console.Read()); await Task.WhenAny(maintask, readtask); } static async Task RunFFMPEG() { await Task.Run(() => { const int fps = 30; const string outfile = "video_seg_%05d.ts"; const string dir = @"C:\Users\funny\Desktop\in\"; const string pattern = "{0}.bmp"; const string path = dir + pattern; const string args = "-y -re -f image2pipe -framerate 2 -i - -c:v libx264 -r {0} -s 1920x1200 -b:v 256000 -flags +global_header -map 0 -f segment -segment_time 10 -segment_list_size 0 -segment_list list.m3u8 -segment_format mpegts {1}"; const int startNum = 0; const int endNum = 100; var pinf = new ProcessStartInfo("ffmpeg", string.Format(args, fps, outfile)); pinf.UseShellExecute = false; pinf.RedirectStandardInput = true; pinf.WorkingDirectory = dir; Console.WriteLine("Starting ffmpeg..."); var proc = Process.Start(pinf); using (var stream = new BinaryWriter(proc.StandardInput.BaseStream)) { for (var i = startNum; i < endNum; i++) { var file = string.Format(path, i.ToString("D4")); System.Threading.SpinWait.SpinUntil(() => File.Exists(file) && CanReadFile(file)); Console.WriteLine("Found file: " + file); stream.Write(File.ReadAllBytes(file)); } } proc.WaitForExit(); Console.WriteLine("Closed ffmpeg."); }); } static bool CanReadFile(string file) { //Needs to be able to read file FileStream fs = null; try { fs = File.OpenRead(file); return true; } catch (IOException) { return false; } finally { if (fs != null) fs.Close(); } } } }
When I run the script, I get the following screen :
Press any button to quit. Starting ffmpeg... ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 8.2.1 (GCC) 20181017 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 / 55. 3.100
And it stays like this even though I have images in my folder and they keep coming. Anyone can tell me why isn't it processing? (I've tried to run the FFmpeg command alone on a fixed number of images without piping and it works.)
-
To concatenate more than two video using FFMPEG
21 décembre 2018, par Alok Kumar VermaI've been working on FFMPEG, this is indeed not an easy task since I've succeeded in doing some work. I'm done with concatenating two videos using ffmpeg but somehow when it comes to more than two it does not work. So I'm finding out some command to do my task.
The thing I did is to merge two videos are :
String complexCommand[] = {"-y", "-i", "/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-i", "/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-strict", "experimental", "-filter_complex", "[0:v]scale=1920x1080,setsar=1:1[v0];[1:v] scale=iw*min(1920/iw\\,1080/ih):ih*min(1920/iw\\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\\,1080/ih))/2:(1080-ih*min(1920/iw\\,1080/ih))/2,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1", "-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "1920x1080", "-vcodec", "libx264","-crf","27","-q","4","-preset", "ultrafast", savingPath};
The above is working fine for two videos. I've tried altering my code for three videos but it does not work.
What I've done in the above code is :
- Added one more input after the second one
- Changed the concat=3:v=1:a=1
But it does not merge and gave me this error in my LogCat :
FAILED with output : 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 '/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.25.100 Duration: 00:02:47.09, start: 0.000000, bitrate: 245 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 112 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata: handler_name : SoundHandler Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2013-12-15 13:11:41 Duration: 00:03:51.08, start: 0.000000, bitrate: 1693 kb/s Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1498 kb/s, 25 fps, 25 tbr, 50 tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s (default) Metadata: creation_time : 2013-12-15 13:11:41 handler_name : IsoMedia File Produced by Google, 5-11-2011 Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4': Metadata: major_brand : isom minor_version : 0 compatible_brands: isom3gp4 creation_time : 2015-05-30 02:06:06 Duration: 00:04:48.48, start: 0.000000, bitrate: 3608 kb/s Stream #2:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 720x480, 3478 kb/s, 30.28 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: creation_time : 2015-05-30 02:06:06 handler_name : VideoHandle encoder : Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 125 kb/s (default) Metadata: creation_time : 2015-05-30 02:06:06 handler_name : SoundHandle [Parsed_setsar_1 @ 0xa9ea9220] num:den syntax is deprecated, please use num/den or named options instead [Parsed_setsar_4 @ 0xa9ea9310] num:den syntax is deprecated, please use num/den or named options instead [Parsed_setsar_1 @ 0xa9ea92c0] num:den syntax is deprecated, please use num/den or named options instead [Parsed_setsar_4 @ 0xa9ea93b0] num:den syntax is deprecated, please us
I've tried one more command which works fine for concatenating two videos but still it does not work for more than two videos :
String complexCommand[] = {"-y", "-i", "/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-i", "/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-i", "/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4", "-strict", "experimental", "-filter_complex", "[0:v]scale=480x640,setsar=1:1[v0];[1:v]scale=480x640,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=3:v=1:a=1", "-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "480x640", "-vcodec", "libx264","-crf","27","-q","4","-preset", "ultrafast", savingPath};
You can clearly see in the above code that I've tried using this for the three videos but still no luck. Will appreciate your help. Thanks.
EDITS
After following the LordNeckbeard's suggestion from the comment section, I've used his suggestion in my code but after doing that still no luck however the console's output got changed and here is the command which I used :
String complexCommand[] = {"-y", "-i", "/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4", "-i", "/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4", "-i", "/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4", "-strict", "experimental", "-filter_complex", "[0:v]scale=480x640,setsar=1[v0];[1:v]scale=480x640,setsar=1[v1];[v0][0:a][v1][1:a] concat=n=3:v=1:a=1", "-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "480x640", "-vcodec", "libx264","-crf","27","-preset", "ultrafast", savingPath};
Here you can clearly see that I've used setsar=1 and used -crf only.
And the logs are :
FAILED with output : 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 '/mnt/m_external_sd/Videos/VID-20161221-WA0000.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.25.100 Duration: 00:02:47.09, start: 0.000000, bitrate: 245 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 112 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata: handler_name : SoundHandler Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/Videos/Brodha V - Aathma Raama [Music Video]_HD.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2013-12-15 13:11:41 Duration: 00:03:51.08, start: 0.000000, bitrate: 1693 kb/s Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1498 kb/s, 25 fps, 25 tbr, 50 tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s (default) Metadata: creation_time : 2013-12-15 13:11:41 handler_name : IsoMedia File Produced by Google, 5-11-2011 Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/m_external_sd/DCIM/Sinha's POP/20150530_073113.mp4': Metadata: major_brand : isom minor_version : 0 compatible_brands: isom3gp4 creation_time : 2015-05-30 02:06:06 Duration: 00:04:48.48, start: 0.000000, bitrate: 3608 kb/s Stream #2:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 720x480, 3478 kb/s, 30.28 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: creation_time : 2015-05-30 02:06:06 handler_name : VideoHandle encoder : Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 125 kb/s (default) Metadata: creation_time : 2015-05-30 02:06:06 handler_name : SoundHandle [Parsed_concat_4 @ 0xa7ea91d0] Input link in2:v0 parameters (size 720x480, SAR 0:1) do not match the corresponding output link in0:v0 parameters (480x640, SAR 1:1) [Parsed_concat_4 @ 0xa7ea91d0] Failed to configure output pad on Parsed_concat_4 Error configuring complex filters. Invalid argument
NOTE: I have tried using setsar=1/1 but still got the same result.
-
FFmpeg : how to concat 2 videos ? (1 with no audio tracks, 1 with 2 audio tracks) ?
21 décembre 2018, par SomeoneInNeedOfHelpffmpeg -i NoAudio.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i 2Audio.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
My output.mp4 ends up with only 1 Audio. What am I missing?
-
chroma key my command for filter white background works but filter white and black ?
21 décembre 2018, par userpovffmpeg -i bakground.avi -i overlay.avi -filter_complex "[1:v]chromakey=0xFFFFFF:0.02:0[keyed]; [0:v][keyed]overlay[out]" -map "[out]" output.avi
this command filter white and black
I need filter only white color
please help me