Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
ffmpeg : use drawtext with quote inside text [closed]
19 juillet, par SulliI have a variable that takes its content from a file (I can't change the content of the file):
echo $variable It's my variable
I want to print that string on a video with ffmpeg:
ffmpeg -nostdin -i input.mp4 -vf drawtext="text='$variable': fontcolor=white:box=1:boxcolor=black@0.8: x=h/70: y=h/5*4.2" -codec:a copy output.mp4
when I do that, the quote inside $variable is not printed. I have read here that I need to escape the quote multiple times, some say 5 times, some say more.
So I have tried to use
variable=${variable//\'/'\\\\\'\'}
to add between 1 and 10 backslashes, but it never worked: either nothing is printed, or \ are printed:
It\s my variable
Can someone tell me what is the correct syntax, or the correct number of backslashes I should add?
-
Continuously stream audio from .m3u8 file between FFmpeg processes
18 juillet, par demerfMy webserver streams audio using HLS. I'm using a Python script to create an FFmpeg process that takes a random MP3 file and segments it so it can be delivered by the webserver. My issue occurs when the track ends. The player stops and the page needs to be reloaded to start the next track.
From my understanding the .m3u8 file is continuously updating with the latest segment which the browser asks for and it should be seamlessly transitioning between tracks because the segment number is incrementing properly across processes. Code starting the FFmpeg process:
def start_worker(self, track: Track): next_playing_hash = track.hash track_hash = track.hash input_path = os.path.join(self.source_path, track.filepath.name) segment_path = os.path.join(self.output_path, "segment_%03d.ts") output_path = os.path.join(self.output_path, "playlist.m3u8") command = ["ffmpeg", "-re", "-i", input_path, "-map", "a", "-c:a", "aac", "-b:a", "128k", "-f", "hls", "-hls_time", "8", "-threads", "2","-hls_list_size", "6", "-hls_flags", "delete_segments+append_list+discont_start+program_date_time", "-hls_segment_filename", segment_path, output_path] logging.info(f"Started Worker for {self.name}, playing {input_path}") self.current_worker = subprocess.Popen(command) self.last_played = track return self.current_worker
This is creating 8 second segments and replacing the 6th oldest segment with the newest. I suspect this could be an issue with the new process creating a new "playlist.m3u8" file. If so, what is a way around that?
-
How to install pytorch and opencv using a fixed conda channel order ?
18 juillet, par progquesterConda creates a pristine environment, configures a fixed channel order, and then starts installing pytorch torchvisioni pytorch-cuda and opencv, and it prompts for dependency conflicts. Do I have to install opencv via pip?
The same thing happens with python 3.10
$ conda create -n my_env3.9 python=3.9 $ conda activate my_env3.9 $ conda install pytorch torchvision pytorch-cuda=11.8 opencv Channels: - pytorch - nvidia - conda-forge - defaults Platform: linux-64 Collecting package metadata (repodata.json): done Solving environment: failed LibMambaUnsatisfiableError: Encountered problems while solving: - nothing provides libopencv 4.2.0 py36_5 needed by opencv-4.2.0-py36_5 Could not solve for environment specs The following packages are incompatible ├─ opencv =* * is installable with the potential options │ ├─ opencv [4.10.0|4.11.0] would require │ │ └─ libopencv [==4.10.0 headless_py310h05fcec3_10|==4.10.0 headless_py310h2251c23_11|...|==4.11.0 qt6_py39hd96f159_602], which requires │ │ └─ ffmpeg >=7.1.0,<8.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv [4.10.0|4.9.0] would require │ │ └─ libopencv [==4.10.0 headless_py310h3d4b477_1|==4.10.0 headless_py310hef7d0a5_0|...|==4.9.0 qt6_py39hed63795_614], which requires │ │ └─ ffmpeg >=6.1.1,<7.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 4.10.0 would require │ │ └─ libopencv [==4.10.0 headless_py310h8d94708_2|==4.10.0 headless_py38h5642e36_2|...|==4.10.0 qt6_py39hfd9fb6d_602], which requires │ │ └─ ffmpeg >=7.0.1,<8.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 4.10.0 would require │ │ └─ libopencv [==4.10.0 headless_py310h5bfabb9_4|==4.10.0 headless_py310h5bfabb9_5|...|==4.10.0 qt6_py39hdeb11db_605], which requires │ │ └─ ffmpeg >=6.1.2,<7.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 4.10.0 would require │ │ └─ libopencv [==4.10.0 headless_py311h63eac36_5|==4.10.0 headless_py311h63eac36_6|...|==4.10.0 qt6_py39h5d2977a_603], which requires │ │ └─ ffmpeg >=7.0.2,<8.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 4.11.0 would require │ │ └─ libopencv [==4.11.0 headless_py310h8ace835_4|==4.11.0 headless_py310h8ace835_5|...|==4.11.0 qt6_py39hbfaaa73_603], which requires │ │ └─ ffmpeg >=7.1.1,<8.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv [4.5.3|4.5.5|4.6.0] would require │ │ └─ libopencv [==4.5.3 py310hc72b5f5_8|==4.5.3 py38hc6b509d_8|...|==4.6.0 py39hf4bb9d8_2], which requires │ │ └─ ffmpeg >=4.4.2,<5.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv [4.6.0|4.7.0] would require │ │ └─ libopencv [==4.6.0 py310h5bd1119_9|==4.6.0 py310h6214075_5|...|==4.7.0 py39hf99ad11_5], which requires │ │ └─ ffmpeg >=5.1.2,<6.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv [4.7.0|4.8.0|4.8.1] would require │ │ └─ libopencv [==4.7.0 py310h245f934_4|==4.7.0 py310h3e876cf_5|...|==4.8.1 py39hf605482_5], which requires │ │ └─ ffmpeg >=6.0.0,<7.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 4.9.0 would require │ │ └─ libopencv [==4.9.0 headless_py310hae237af_14|==4.9.0 headless_py38h0f7b093_14|...|==4.9.0 qt6_py39h067c833_615], which requires │ │ └─ ffmpeg >=7.0.0,<8.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv [2.4.12|2.4.13|3.1.0|3.2.0] would require │ │ └─ python =2.7 *, which can be installed; │ ├─ opencv [2.4.13.4|3.2.0|3.3.0|3.4.1] would require │ │ └─ ffmpeg >=3.2.3,<3.2.6 *, which conflicts with any installable versions previously reported; │ ├─ opencv 3.1.0 would require │ │ └─ python =3.4 *, which can be installed; │ ├─ opencv [3.1.0|3.2.0] would require │ │ └─ python =3.5 *, which can be installed; │ ├─ opencv [3.1.0|3.2.0] would require │ │ └─ python =3.6 *, which can be installed; │ ├─ opencv [3.4.1|3.4.3|3.4.4|3.4.7] would require │ │ ├─ ffmpeg >=4.0.2,<4.1.0a0 *, which conflicts with any installable versions previously reported; │ │ └─ libopencv ==3.4.7 hc173e35_5, which requires │ │ └─ ffmpeg >=4.0.2,<4.1.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 3.4.1 would require │ │ └─ ffmpeg >=4.0.1,<4.1.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv [3.4.4|3.4.7|...|4.1.1] would require │ │ ├─ ffmpeg =4.1 *, which conflicts with any installable versions previously reported; │ │ └─ libopencv [==3.4.7 h0cc45ee_4|==4.1.1 h0cc45ee_3], which requires │ │ └─ ffmpeg =4.1 *, which conflicts with any installable versions previously reported; │ ├─ opencv [3.4.7|3.4.8|...|4.2.0] would require │ │ └─ libopencv [==3.4.7 h32d60f7_6|==3.4.7 py27_7|...|==4.2.0 py38_4], which requires │ │ └─ ffmpeg >=4.1.3,<4.2.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 4.2.0 would require │ │ └─ libopencv ==4.2.0 py36_5, which does not exist (perhaps a missing channel); │ ├─ opencv [4.2.0|4.3.0|4.4.0] would require │ │ └─ py-opencv [==4.2.0 py36h0b673f9_6|==4.3.0 py36h0b673f9_2|==4.4.0 py36h0b673f9_2], which requires │ │ └─ python >=3.6,<3.7.0a0 *, which can be installed; │ ├─ opencv [4.2.0|4.3.0] would require │ │ └─ libopencv [==4.2.0 py36_7|==4.2.0 py37_7|...|==4.3.0 py38_1], which requires │ │ └─ ffmpeg >=4.2.3,<4.3.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv [4.2.0|4.3.0|4.4.0] would require │ │ └─ py-opencv [==4.2.0 py37h43977f1_5|==4.2.0 py37h43977f1_6|==4.3.0 py37h43977f1_2|==4.4.0 py37h43977f1_2], which requires │ │ └─ python >=3.7,<3.8.0a0 *, which can be installed; │ ├─ opencv [4.2.0|4.3.0|4.4.0] would require │ │ └─ py-opencv [==4.2.0 py38h23f93f0_5|==4.2.0 py38h23f93f0_6|==4.3.0 py38h23f93f0_2|==4.4.0 py38h23f93f0_2], which requires │ │ └─ python >=3.8,<3.9.0a0 *, which can be installed; │ ├─ opencv [4.4.0|4.5.0|4.5.1|4.5.2] would require │ │ └─ libopencv [==4.4.0 py36_3|==4.4.0 py37_3|...|==4.5.2 py39h70bf20d_1], which requires │ │ └─ ffmpeg >=4.3.1,<4.4.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 4.5.0 would require │ │ └─ libopencv ==4.5.0 py36_5, which does not exist (perhaps a missing channel); │ ├─ opencv 4.5.0 would require │ │ └─ libopencv ==4.5.0 py36_6, which does not exist (perhaps a missing channel); │ ├─ opencv [4.5.3|4.5.5] would require │ │ └─ libopencv [==4.5.3 py31hbd5a65a_6|==4.5.3 py31he7a5e20_7|...|==4.5.5 py39hfb30bf4_6], which requires │ │ └─ ffmpeg >=4.3.2,<4.4.0a0 *, which conflicts with any installable versions previously reported; │ ├─ opencv 4.5.5 would require │ │ └─ libopencv [==4.5.5 py310h1897127_9|==4.5.5 py310hc83fb77_10|...|==4.5.5 py39he64e9e9_10], which requires │ │ └─ ffmpeg >=4.4.1,<5.0a0 *, which conflicts with any installable versions previously reported; │ └─ opencv [3.3.1|3.4.1|...|4.6.0] conflicts with any installable versions previously reported; └─ pin on python 3.9.* =* * is not installable because it requires └─ python =3.9 *, which conflicts with any installable versions previously reported. Pins seem to be involved in the conflict. Currently pinned specs: - python=3.9
-
macOS : ffmpeg runs OK but ffprobe fails to find a dynamic library [closed]
17 juillet, par Kim SilvermanI'm running macOS 15.5 on an M4 MacBook Pro. I have some
.mov
movie files, produced by taking screen recordings. I want to extract the audio from them, normalize its volume (it contains speech which is too quiet), perhaps also attenuating some background noise, and then reinsert the modified audio back into the movies. It seems to me thatffmpeg
will support these needs. It has an accompanying toolffprobe
which will report on the content structure (how many audio tracks, etc) of a movie file.I installed
ffmpeg
usingbrew
and can successfully run it:$ ffmpeg -version ffmpeg version 2.2.4 built on Jun 27 2014 09:57:37 with llvm-gcc 4.2.1 (LLVM build 2336.11.00) configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --arch=x86_64 --enable-runtime-cpudetect 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
But if I try to launch the associated tool ffprobe, it fails looking for a library:
$ ffprobe dyld[90050]: Library not loaded: @@HOMEBREW_CELLAR@@/ffmpeg/4.4_2/lib/libavdevice.58.dylib Referenced from: <1BF90DFA-AFA6-3011-BF50-B3515C3A7477> /opt/brew/Cellar/ffmpeg/4.4_2/bin/ffprobe Reason: tried: '/usr/local/lib/libavdevice.58.dylib' (no such file), '/usr/lib/libavdevice.58.dylib' (no such file, not in dyld cache) Abort trap: 6
I uninstalled then reinstalled, updated, and upgrade brew and then ffmpeg, but the behaviour remains the same.
The two tools are in different places:
$ ls -l `which ffmpeg` -rwxr-xr-x@ 1 kimsilverman staff 17474952 Jun 27 2014 /usr/local/bin/ffmpeg $ ls -l `which ffprobe` lrwxr-xr-x 1 kimsilverman staff 36 Jul 16 21:21 /opt/homebrew/bin/ffprobe -> ../Cellar/ffmpeg/7.1.1_3/bin/ffprobe
And I notice that
ffmpeg
is 11 years old, whereasffprobe
is dated today. -
Replacing deprecated AVStream codec parameter in libav
17 juillet, par xtingrayA long time ago, I implemented a C++ class to create MP4 video files from an array of images. The code works pretty well, nevertheless, I discovered a deprecation warning that I want to rid off. The parameter "codec" from the AVStream structure has been deprecated and I want to replace it.
Here is my current working code:
AVOutputFormat *outputFormat = av_guess_format("ffh264", movieFile.toLocal8Bit().data(), nullptr); if (!outputFormat) return false; enum AVCodecID videoCodecID = outputFormat->video_codec; AVCodec *videoCodec = avcodec_find_encoder(videoCodecID); if (!videoCodec) return false; AVStream *stream = avformat_new_stream(formatContext, videoCodec); if (!stream) return false; AVCodecContext *videoCodecContext = stream->codec; // <- codec is a deprecated parameter videoCodecContext->width = videoW; videoCodecContext->height = videoH;
Now, to replace the "codec" parameter, the libav developers team recommends using the parameter "codecpar" (AVCodecParameters) that was included in the AVStream structure. The example they use to share is this:
if (avcodec_parameters_to_context(videoCodecContext, stream->codecpar) < 0) return nullptr;
Note: codecpar (AVCodecParameters) is a data structure itself.
Unfortunately, when I try to use that code, I got this problem: usually, all the information stored in the codecpar parameter comes from the data structure from a previous video file that was opened previously. In other words, the information already exists. In my case, the situation is different because I am creating an MP4 file from scratch so there is no previous codecpar record to use, therefore I have to create a new instance of AVCodecParameters structure by myself, setting every variable manually.
As far, I was able to set all the variables from the codecpar structure, except for two:
uint8_t * extradata int extradata_size
Note: currently I can create an MP4 file "successfully" without setting those variables, but the file is incomplete and when I try to play it using "mplayer" I got this error message:
[extract_extradata @ 0x55b5bb7e45c0] No start code is found.
I was researching these two fields, and it seems they store some kind of information related to the codec, which in my case is H264.
So, my specific question is: if I am setting a codecpar variable (AVCodecParameters) from scratch, how can I set values for the fields extradata and extradata_size in the right way for the codec H264?