I am new to streaming and am trying to figure out how to transcode streams via ffmpeg.
I have a few raw rtp uncompressed streams where some are on address 239.x.x.x and others are on 169.x.x.x.
I want to setup an RTSP server to grab those streams and transcode them into H264 and stream them out to a new address and port.
I have tried some ffmpeg commands but I keep getting errors about having to compile ffmpeg with pthreads.
I have no idea how to do that so does anyone know what commands I can use that will work with the current windows version of ffmpeg?
For now, I am just trying to save the stream to a file to see if that works. Command I am using is:
ffmpeg -i rtp://224.1.1.10:6972 transcoded test.mp4
and the return I get in the command line is
ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.3.1 (GCC) 20190414
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
[udp # 000002cb292abf40] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
[udp # 000002cb292bc200] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
rtp://224.1.1.10:6972: Immediate exit requested
Exiting normally, received signal 2.
Try TCP instead of UDP. If your server outputs TCP you can try adding the input option(s) -rtsp_flags prefer_tcp and/or -rtsp_transport tcp (place them before -i).
Or use a build of ffmpeg that supports pthreads.
Related
I'm re-posting this question in a modified form because I'm told that stack overflow doesn't allow anyone to ask for the location of documentation. So now I'm not asking for documentation, I just want working examples of how the QSV enabled filters are used, with a specific question on why async doesn't work with vpp_qsv .
I have a PC running Windows which is QSV capable. I've found the codec and at least one QSV filter which really speed up decoding and encoding AVC (x264) videos.
But the experience is extremely aggravating, as I cannot find a list anywhere that I can find on what the filters and arguments actually are.
The closest I've come for vpp_qsv is this:
https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_vpp_qsv.c
It's a good start, but it has no examples of what the arguments actually are.
Source code doesn't explain how the filters actually work. However, this source code does say that async_depth is a valid qualifier.
The few examples I've been able to find in various places (including stackoverflow) do not work.
By experimentation, I've found that this works:
ffmpeg -hide_banner -init_hw_device qsv=qsv -hwaccel qsv -i "input.mts" -c:a aac -c:v h264_qsv -preset veryslow -vf "vpp_qsv=cw=628:cx=0:w=640:h=480" -q:v 30 "output.mp4"
I can add other things to the filter. For example:
"vpp_qsv=deinterlace=2:cw=628:cx=0:w=640:h=480"
will work. However, this will NOT work:
"vpp_qsv=cw=628:cx=0:w=640:h=480:async_depth=4"
even though there are examples posted that say it will.
[Parsed_vpp_qsv_0 # 0000000005bff8c0] Option 'async_depth' not found [AVFilterGraph # 0000000007327dc0] Error initializing filter 'vpp_qsv' with args 'cw=628:cx=0:w=640:h=480:async_depth=4' Error reinitializing filters! Failed to inject frame into filter network: Option not found Error while processing the decoded data for stream #0:0
I also have been unable to find good examples of using more than one QSV enabled filter at the same time.
I'm using the newest version of ffmpeg I can find:
I:\ffmpeg -version ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 10.2.0 (Rev6, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml 2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enab le-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --ena ble-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-lib zimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang - -enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine - -enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libv orbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint libavutil 56. 70.100 / 56. 70.100 libavcodec 58.134.100 / 58.134.100 libavformat 58. 76.100 / 58. 76.100 libavdevice 58. 13.100 / 58. 13.100 libavfilter 7.110.100 / 7.110.100 libswscale 5. 9.100 / 5. 9.100 libswresample 3. 9.100 / 3. 9.100 libpostproc 55. 9.100 / 55. 9.100
and the output of "ffmpeg -filters" says I have the various QSV enabled filters on my system.
I have searched dozens and dozens of sites including Intel and ffmpeg.org and I cannot find a clear explanation of how the various QSV enabled filters work, with examples that will actually execute on my system. Could someone please point me to where this filter is explained? (This is NOT, I repeat, NOT a banned request for documentation. I'm asking how to use a specific qualifier in a specific filter.)
I am trying to convert a video that have multiple video streams and one audio stream from mxf format to mp4 format and getting an error. How can i solve this problem? Thank you.
E:\video>ffmpeg -loglevel error -y -i E:\video\19_12_2018\Files\MEDIA\media_data.mxf -map 0 -c:v h264_nvenc -acodec copy nvidia_output.mp4
[h264_nvenc # 0000020b30c86e80] OpenEncodeSessionEx failed: out of memory (10)
[h264_nvenc # 0000020b30c86e80] No NVENC capable devices found
Error initializing output stream 0:2 -- Error while opening encoder for output stream #0:2 - maybe incorrect parameters such as bit_rate, rate, width or height
[h264_nvenc # 00000204c1e37040] OpenEncodeSessionEx failed: out of memory (10)
[h264_nvenc # 00000204c1e37040] No NVENC capable devices found
[h264_nvenc # 00000204c1e37040] Nvenc unloaded
[jpeg2000 # 00000204c2d90080] End mismatch 1
Last message repeated 1 times
Error initializing output stream 0:2 -- Error while opening encoder for output stream #0:2 - maybe incorrect parameters such as bit_rate, rate, width or height
My FFPROBE output
E:\video>ffmpeg ffprobe
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
The error you're seeing is expected, if you're using a consumer-grade NVIDIA GPU wherein the maximum simultaneous NVENC session limit of 2 is enforced at the firmware and driver level. See the NVIDIA GPU Matrix for more information on this.
There are two ways you can overcome this limitation:
1. Explicitly select the video stream(s) you desire to encode, via -map options, such that only two video streams are encoded at any given time per session. The example below explicitly selects the first and second video stream only:
E:\video>ffmpeg -loglevel error -y -i E:\video\19_12_2018\Files\MEDIA\media_data.mxf -map 0:v:0 -map 0:v:1 -map:0:a -c:v h264_nvenc -acodec copy nvidia_output.mp4
It would be awesome if you'd provide the ffprobe output for the input file you're working with, and that way, we can suggest what to do with the other video streams. An alternative to such would be falling back to a software-based encoder (such as x264) if so needed.
2. Override the aforementioned NVENC session count limit above: This will require you to patch the NVIDIA driver, as documented in this repository. Instructions for Linux are also available here.
I have a problem on connect to a rtsp camera using ffplay.
The camera is under a router that permits only the TCP protocol.
I can watch the camera using ffplay only if I am in the same network of the camera.
So, when I am out, using this command line
ffplay rtsp://address:554/onvif1
or this
ffplay -rtsp_transport tcp rtsp://address:554/onvif1
I cannot watch the camera.
This is the output of ffplay (the latest).
[rtsp # 059ee680] Nonmatching transport in server reply 0B f=0/0
rtsp://address:554:/onvif1: Invalid data found when processing input
Trying with VLC and I can watch the camera without any problem, both when I am in the same network or when I am out. The VLC output says that VLC uses TCP.
Has someone got a suggestion?
Sure, as you can see below vlc works without any problem.
FFMpeg works only with a local camera but not with a remote camera. Forcing tcp as rtsp protocol seems to have no effect.
try to capture a remote camera (doesn't work)
denis#tomcat:~/Scaricati/ffmpeg-git-20181227-amd64-static$ **./ffmpeg -v verbose -i rtsp://address:554/onvif1 a.avi**
ffmpeg version N-47834-gb5e0a0fe3a-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 25.100 / 56. 25.100
libavcodec 58. 42.104 / 58. 42.104
libavformat 58. 25.100 / 58. 25.100
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 46.101 / 7. 46.101
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
[tcp # 0x5f86700] Starting connection attempt to address port 554
try to capture a remote camera forcing tcp (doesn't work)
denis#tomcat:~/Scaricati/ffmpeg-git-20181227-amd64-static$ **./ffmpeg -v verbose -rtsp_transport tcp -i rtsp://address:554/onvif1 a.avi**
ffmpeg version N-47834-gb5e0a0fe3a-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 25.100 / 56. 25.100
libavcodec 58. 42.104 / 58. 42.104
libavformat 58. 25.100 / 58. 25.100
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 46.101 / 7. 46.101
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
[tcp # 0x5515740] Starting connection attempt to address port 554
Using vlc (works)
denis#tomcat:~/Scaricati/ffmpeg-git-20181227-amd64-static$ **vlc -v**
VLC media player 3.0.3 Vetinari (revision 3.0.3-1-0-gc2bb759264)
[000056417a4461a0] main libvlc: Esecuzione di vlc con l'interfaccia predefinita. Usa 'cvlc' per utilizzare vlc senza interfaccia.
[000056417a4da540] main playlist: playlist is empty
[00007fcd00000eb0] live555 demux warning: no data received in 10s. Switching to TCP
[00007fcd0000b2d0] main decoder error: buffer deadlock prevented
[000056417a505bf0] pulse audio output warning: starting late (-591 us)
[000056417a505bf0] main audio output warning: playback way too early (-260338): playing silence
[000056417a505bf0] main audio output warning: playback too late (67682): up-sampling
[000056417a505bf0] main audio output warning: playback too early (-60916): down-sampling
[000056417a505bf0] main audio output warning: playback way too early (-191284): playing silence
[000056417a505bf0] main audio output warning: playback way too late (252312): flushing buffers
[000056417a505bf0] pulse audio output warning: starting late (-5953 us)
[000056417a505bf0] main audio output warning: playback way too early (-701316): playing silence
[000056417a505bf0] main audio output warning: playback way too early (-332484): playing silence
[000056417a505bf0] main audio output warning: playback too late (125861): up-sampling
[000056417a505bf0] main audio output warning: playback way too late (297954): flushing buffers
[000056417a505bf0] main audio output warning: playback way too early (-993047): playing silence
[00007fcd0000b2d0] avcodec decoder warning: thread type 1: disabling hardware acceleration
[000056417a505bf0] main audio output warning: playback too late (107083): up-sampling
[000056417a505bf0] main audio output warning: playback way too late (235778): flushing buffers
[00007fcce0001cc0] egl_x11 gl error: cannot select OpenGL API
[000056417a505bf0] main audio output warning: playback way too early (-657714): playing silence
[000056417a505bf0] main audio output warning: playback way too late (238668): flushing buffers
[00007fccf8160b40] main video output warning: picture is too late to be displayed (missing 691 ms)
[00007fccf8160b40] main video output warning: picture is too late to be displayed (missing 491 ms)
[00007fccf8160b40] main video output warning: picture is too late to be displayed (missing 290 ms)
[00007fccf8160b40] main video output warning: picture is too late to be displayed (missing 89 ms)
[000056417a505bf0] main audio output warning: playback way too early (-652182): playing silence
[000056417a505bf0] main audio output warning: playback too late (72927): up-sampling
[000056417a505bf0] main audio output warning: playback too late (98876): up-sampling
[000056417a4da540] main playlist: end of playlist, exiting
I've been using FFMPEG on Windows to:
Convert iTunes M4A files to MP3s (with a bit rate of 128k); and
Create 30 sec sample MP3s of the above MP3s (same bit rate).
When I run FFMEG on a Windows 7 64 bit machine, the size of the MP3s (both for 1. & 2.) is in line with the rough calculation of:
(Audio length in seconds) X (Bit rate)
For example, a 4 minute audio yields an approx. 3.7MB MP3 file; a 30 second sample MP3 is approx. 470KB.
However when I run the same FFMPEG binary (copied from the Windows 7 machine) on a Windows 10 64 bit machine, all of the MP3s (both for 1. and for 2.) are inflated by approx 5MB. I'm using the same batch file on both machines to execute FFMEG with the required parameters, so pretty confident the difference is not down to user error.
My questions are:
Why is there this apparent 5MB overhead on Windows 10? and more importantly;
What can I do to remove this?
The large file size is a problem as the sample MP3s are to be put on a website for people to listen to a snippet of the song, and the webpage with multiple tags takes a long time to load completely (several minutes).
Here is the version and lib info:
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --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-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
And here are the command lines I'm using:
ffmpeg -i input.m4a -id3v2_version 3 -b:a 128k -output.mp3
ffmpeg -i input.m4a -ss 30 -t 30 -af "afade=in:st=30:d=5,afade=out:st=55:d=5" -id3v2_version 3 -b:a 128k -output.mp3
Used the FFMPEG switch -vn to remove the video stream from the output, and that dramatically reduced the size of the MP3s (down to what was expected).
Turns out there was a difference between the FFMPEG parameters being used on each machine. On one machine the "sample" MP3 was starting from the beginning of the track (-ss 0) and this was the one with the album cover art PNG embedded in the video stream). The other machine's parameters was starting the "sample" from 30 seconds in (-ss 30) and this was not include the album cover art.
Interesting difference - not sure if it's deliberate - but that explains what was happening.
In the provided example I was trying to transcode a 4K h264 source to a 1080p h264 output using Nvidia's Hardware acceleration.
Relevant information:
ffmpeg version git-2017-12-25-613f789 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --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-amf --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 56. 7.100 / 56. 7.100
libavcodec 58. 9.100 / 58. 9.100
libavformat 58. 3.100 / 58. 3.100
libavdevice 58. 0.100 / 58. 0.100
libavfilter 7. 7.100 / 7. 7.100
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
Command used:
ffmpeg -c:v h264_cuvid -i "4K_input.mp4" -c:v h264_nvenc -preset slow -s 1920x1080 -c:a copy output.mkv
Relevant PC Specs:
GPU: (Gigabyte) GeForce GTX 1070 Ti
CPU: Intel Core i7 7700K
Memory: 8GB DDR4 2400MHz Single Channel.
SSD: Crucial CT525MX3
While the Nvidia Desktop recording has absolutely no issues to record live h264 video in up to 50Mbps bitrates, this encoding at below 2600kbps was extremely slow utilizing barely 35% GPU.
I was unable to utilize 100% of the GPU on any video parameters.
This is why I could use some advice concerning how to identify a (suspected) bottleneck.
"GPU" transcoding does not work that way. There are fixed function circuits dedicated to h264 encoding on Nvidia GPUs that are not part of the vector unit pool. This is why you specify h264_nvenc (nvenc is Nvidia specific) and not a generic gpu encoder.
TLDR, you won't reach 100% GPU because its not really using the GPU. Its using a separate component that comes with your GPU.