Tag Archives: ffmpeg

[Solved] Qt Error: undefined reference to xxxxx

Error reporting information:

first of all, it is necessary to distinguish the two types of error : undefined reference to xxxxx and "XXXX was not declared in this scope". The former is because the compiler can find the declaration of the function, but cannot find the definition of the function, so it reports an error; The latter is not found at all. You should first check whether the header file is missing.

For undefined reference to xxxxx, there are two situations at present

1. The path to ffmpeg in the pro file is not correct
2. The header file is written in C, but without extern "C" {}

 

How to Solve MacOS ffmpeg killed Error


tags: MacOS Debug Tips

Question

Recently, I wanted to download the live playback course in nailing with the tried and true method, but some errors suddenly appeared when executing ffmpeg on the command line:

[1]    40344 killed     ffmpeg

 

Solution:

This problem can be solved by compiling and installing from the source code through the following command

brew tap homebrew-ffmpeg/ffmpeg
brew install homebrew-ffmpeg/ffmpeg/ffmpeg

At this time, enter ffmpeg in the terminal to get:

❯ ffmpeg
ffmpeg version 5.0 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 13.1.6 (clang-1316.0.21.2)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.0-with-options_2 --enable-shared --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --enable-opencl --enable-videotoolbox --enable-neon --disable-htmlpages
  libavutil      57. 17.100/57. 17.100
  libavcodec     59. 18.100/59. 18.100
  libavformat    59. 16.100/59. 16.100
  libavdevice    59.  4.100/59.  4.100
  libavfilter     8. 24.100/ 8. 24.100
  libswscale      6.  4.100/ 6.  4.100
  libswresample   4.  3.100/ 4.  3.100
  libpostproc    56.  3.100/56.  3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

[Solved] webrtc Compile Error: ERROR: The installation of the Chrome OS default fonts failed.

Installing Chrome OS fonts.
Installing Chrome OS fonts to /usr/local/share/fonts/chromeos.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:02:09 --:--:--     0curl: (7) Failed to connect to commondatastorage.googleapis.com port 443: 连接超时
Traceback (most recent call last):
  File "./build/linux/install-chromeos-fonts.py", line 120, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./build/linux/install-chromeos-fonts.py", line 67, in main
    subprocess.check_call(['curl', '-L', url, '-o', tarball])
  File "/usr/lib/python2.7/subprocess.py", line 541, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['curl', '-L', 'https://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/notofonts-20161129.tar.bz2', '-o', '/usr/local/share/fonts/chromeos/notofonts-20161129.tar.bz2']' returned non-zero exit status 7
ERROR: The installation of the Chrome OS default fonts failed.
This is expected if your repo is installed on a remote file system.
It is recommended to install your repo on a local file system.
You can skip the installation of the Chrome OS default founts with
the command line option: --no-chromeos-fonts.

Compile webrtc configuration report error: ERROR: The installation of the Chrome OS default fonts failed.
This means that the installation of the Chrome fonts failed, so far found that this has any effect on the use of webrtc later, you can add -no-chromeos-fonts after the command as prompted, meaning not to install the fonts.

./build/install-build-deps.sh --no-chromeos-fonts

[Solved] MacOS Compile ffmpeg Error: ERROR: openssl not found

On a whim today, I suddenly want to start studying the source code of ffmpeg. After downloading all the dependent libraries, I use the command configure

sh configure --prefix=/usr/local/ffmpeg \
--enable-gpl \
--enable-version3 \
--enable-nonfree \
--enable-postproc \
--enable-libass \
--disable-libcelt \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopencore-amrnb \
--enable-libopencore-amrwb \
--enable-libopenjpeg \
--enable-openssl \
--enable-libopus \
--enable-libspeex \
--enable-libtheora \
--enable-libvorbis \
--enable-libvpx \
--enable-libx264 \
--enable-libxvid \
--disable-static \
--disable-x86asm \
--enable-shared

appear. Error: an error is reported when OpenSSL is not found. The version of OpenSSL I use is

Then the solution is seen from here

export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"

After writing, configure succeeded!

If you encounter some other problems, such as the following, you only need to delete the corresponding file and reconfigure it

config.h is unchanged
libavutil/avconfig.h is unchanged
libavfilter/filter_list.c is unchanged
libavcodec/codec_list.c is unchanged
libavcodec/parser_list.c is unchanged
libavcodec/bsf_list.c is unchanged
libavformat/demuxer_list.c is unchanged
libavformat/muxer_list.c is unchanged
libavdevice/indev_list.c is unchanged
libavdevice/outdev_list.c is unchanged
libavformat/protocol_list.c is unchanged
ffbuild/config.sh is unchanged

[Solved] error: taking address of temporary array av_make_error_string((char[AV_ERROR_MAX_STRING_SI…




/**
 * Convenience macro, the return value should be used only directly in
 * function arguments but never stand-alone.
 */
//#define av_err2str(errnum) \
 //   av_make_error_string((char[AV_ERROR_MAX_STRING_SIZE]){0}, AV_ERROR_MAX_STRING_SIZE, errnum)

//Modify as the following:


av_always_inline char* av_err2str(int errnum)
{
    static char str[AV_ERROR_MAX_STRING_SIZE];
    memset(str, 0, sizeof(str));
    return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum);
}

Modify libavutil/error.h:132 as the above.

[Solved] unesolved external symbol _imp_fprintf referenced in funciton _showerror

There are two problems when debugging projects written in ffmpeg with vs2015:

Question 1:

“LNK2019 unresolved external symbol __imp____iob_func reference in function _ShowError”

Solution: add this sentence to the source code: extern “C” {file _iob_func [3] = {* stdin, * stdout, * stderr};}

Question 2:

“unesolved external symbol _imp_fprintf referenced in funciton _showerror”

Solution: right-click the item — properties — configuration — linker — input — additional dependencies to add the library legacy_stdio_definitions.lib

[Solved] ffmpeg error reporting: subprocess. Calledprocesserror: Command ‘ffmpeg, unknown encoder: “libx264″“

0x00 problem description

Today we are compressing the video into different quality in the lab, so we need to use the FFmpeg tool (we have to say that this tool is really powerful), but when we install it, we call out the following mistakes when we call it in Python script.

subprocess.CalledProcessError: Command 'ffmpeg -i /data/xiangtao/dataset/celeb-DF/0_Celeb-real/id0_0000.mp4 -vf select="eq(pict_type\,I)" -vsync vfr -qscale:v 2 -f image2 /data/xiangtao/dataset/tmp/VA-MLP/celeb-DF/11-12/id0_0000/%02d.jpg' returned non-zero exit status 127.

The reason is that libx264 encoder is not installed,

Unknown encoder: "libx264"

0x01 solution

Baidu has been trying several ways for a long time, most of the solutions have to be reinstalled FFmpeg, then install the libx264 Library in the process of installation, try it all wrong, and later discovered that there is a package in the python environment, then ffmpeg will uninstall the python script, which calls for the use of this package. Based on this idea, I reinstalled the ffmpeg package and solved it perfectly!!!

0x02 specific steps

    1. if ffmpeg is available in the current Python environment, uninstall it first
pip uninstall ffmpeg
or
conda uninstall ffmpeg

Reinstall

pip install ffmpeg
or
conda install ffmpeg

0x03 some gossip

srs Error: demux SPS/PPS : avc decode sequence header

SRS reports errors as follows:

[31m[2021-10-23 17:43:55.682][Error][31374][5ns94367][4] serve error
code=3001 : service cycle : rtmp: stream service : rtmp: receive
thread : handle publish message : rtmp: consume message : rtmp:
consume video : meta update video : demux SPS/PPS : avc decode
sequence header

This error means that SRS cannot obtain SPS and PPS information when receiving the code stream.
then select to disconnect from the streaming end. At this time, if the streaming end continues to push the stream, av_interleaved_write_frame (…) will report – 32, and the print log is:

broken pipe

The following encoder parameters need to be set:

if(octx->oformat->flags & AVFMT_GLOBALHEADER)
{
	printf("set video GLOBAL_HEADER\n");
	enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
octx Represents the output context

Explain PPS and SPS, two-byte areas in the code stream, which are very important for decoding. If they are not found, decoding will
fail because they store the parameters set by the encoder, such as the height and width of the video, the sampling rate of the audio, the number of channels, etc
explain the meaning of the above code segment. It will detect the encapsulation format of the output context to determine whether AV is set_CODEC_FLAG_GLOBAL_HEADER.
The function of the AV_CODEC_FLAG_GLOBAL_header flag is to add PPS and SPS in front of each keyframe from the original encoding to the byte area of extradate. Then, when decoding, you have to read PPS and SPS from extradate and put them in front of each keyframe.

[How to Solve] ffprobe ‘***: No such file or directory‘

Error reporting solution: ffprobe ‘* * *: no such file or directory’

Explain the error message solution

explain

This blog is used to record the solution to the error reported by ffprobe when I use the splieter open source music separation tool on the Linux server.

Error message

Traceback (most recent call last):
  File "~/miniconda3/envs/spleeter/lib/python3.6/site-packages/spleeter/audio/ffmpeg.py", line 101, in load
    probe = ffmpeg.probe(path)
  File "~/miniconda3/envs/spleeter/lib/python3.6/site-packages/ffmpeg/_probe.py", line 23, in probe
    raise Error('ffprobe', out, err)
ffmpeg._run.Error: ffprobe error (see stderr output for detail)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_spleeter.py", line 9, in <module>
    separate(sys.argv[1], sys.argv[2], sys.argv[3])
  File "test_spleeter.py", line 7, in separate
    separator.separate_to_file(test_files[0], pre_dir)
  File "~/miniconda3/envs/spleeter/lib/python3.6/site-packages/spleeter/separator.py", line 380, in separate_to_file
    sample_rate=self._sample_rate,
  File "~/miniconda3/envs/spleeter/lib/python3.6/site-packages/spleeter/audio/ffmpeg.py", line 105, in load
    e.stderr.decode()
spleeter.SpleeterError: An error occurs with ffprobe (see ffprobe output below)

ffprobe version 4.2.4-1ubuntu0.1 Copyright (c) 2007-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100/56. 31.100
  libavcodec     58. 54.100/58. 54.100
  libavformat    58. 29.100/58. 29.100
  libavdevice    58.  8.100/58.  8.100
  libavfilter     7. 57.100/ 7. 57.100
  libavresample   4.  0.  0/ 4.  0.  0
  libswscale      5.  5.100/ 5.  5.100
  libswresample   3.  5.100/ 3.  5.100
  libpostproc    55.  5.100/55.  5.100
u: No such file or directory

Solution

    1. background description
  1. When I first saw the error message, it was inexplicable. Because there was no problem when testing directly locally, in order to let others try it later, I used the Flask framework to encapsulate Spleeter into a small web page to display it, but this error was reported.

    Search directly online from the beginning ffprobe No such file or directory, The solutions found are basically saying that ffmpeg or ffprobe is not installed, but these two tools have indeed been installed here. After searching for a long time, the problem has not been solved, and then I found a similar error on Spleeter Github Issues #364 .

(base) C:\Users\smcco>python -m spleeter separate -i C:\Users\smcco\Music\Power Rangers Time Force Theme.mp3 -p spleeter:5stems -o output
ERROR:spleeter:An error occurs with ffprobe (see ffprobe output below)

ffprobe version 4.2 Copyright (c) 2007-2019 the FFmpeg developers
  built with gcc 9.1.1 (GCC) 20190807
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --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 --enable-libopenmpt
  libavutil      56. 31.100/56. 31.100
  libavcodec     58. 54.100/58. 54.100
  libavformat    58. 29.100/58. 29.100
  libavdevice    58.  8.100/58.  8.100
  libavfilter     7. 57.100/ 7. 57.100
  libswscale      5.  5.100/ 5.  5.100
  libswresample   3.  5.100/ 3.  5.100
  libpostproc    55.  5.100/55.  5.100
C:\Users\smcco\Music\Power: No such file or directory

No solution was found through this, but I was inspired to think that the absolute path should be used, so I set the path to the absolute path. The error is still not solved, but an error message is changed:

Traceback (most recent call last):
  File "~/miniconda3/envs/spleeter/lib/python3.6/site-packages/spleeter/audio/ffmpeg.py", line 101, in load
    probe = ffmpeg.probe(path)
  File "~/miniconda3/envs/spleeter/lib/python3.6/site-packages/ffmpeg/_probe.py", line 23, in probe
    raise Error('ffprobe', out, err)
ffmpeg._run.Error: ffprobe error (see stderr output for detail)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_spleeter.py", line 9, in <module>
    separate(sys.argv[1], sys.argv[2], sys.argv[3])
  File "test_spleeter.py", line 7, in separate
    separator.separate_to_file(test_files[0], pre_dir)
  File "~/miniconda3/envs/spleeter/lib/python3.6/site-packages/spleeter/separator.py", line 380, in separate_to_file
    sample_rate=self._sample_rate,
  File "~/miniconda3/envs/spleeter/lib/python3.6/site-packages/spleeter/audio/ffmpeg.py", line 105, in load
    e.stderr.decode()
spleeter.SpleeterError: An error occurs with ffprobe (see ffprobe output below)

ffprobe version 4.2.4-1ubuntu0.1 Copyright (c) 2007-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100/56. 31.100
  libavcodec     58. 54.100/58. 54.100
  libavformat    58. 29.100/58. 29.100
  libavdevice    58.  8.100/58.  8.100
  libavfilter     7. 57.100/ 7. 57.100
  libavresample   4.  0.  0/ 4.  0.  0
  libswscale      5.  5.100/ 5.  5.100
  libswresample   3.  5.100/ 3.  5.100
  libpostproc    55.  5.100/55.  5.100
/: Is a directory

At this time, I realized! ! !There is a problem with the file path that I passed in by myself!

Cause analysis

Review the last line of the error message:u: No such file or directory, Which is expressing:There is no file or directory named u. I always thought that u was a specific prefix reported by ffprobe, but only now I discovered that it refers to the file name that was not found.

It turns out that the file name to be separated in my code to Spleeter should be test_files, not test_files[0]. The reason why I used more [0] is because at the beginning, the default test_files represents a list of file names. There is only one time, just take the first one, but the Flask framework just forgot to do it. In the end, a file name was directly assigned to test_files instead of a list.

At this point, if we look at the error message on Spleeter Github Issues #364 , we will find that this error is also caused by a problem with the input file name. There are spaces in the input file name, which directly leads to multiple parameters in the command line. Instead of a complete path.

Concrete steps

Modify the correct file path name passed to Spleeter.

How to Use ffmpeg to convert MP4 and other formats to MP3 format

Single conversion

command

ffmpeg -i {input file} {output file}

Example

Mp4 to MP3

ffmpeg -i foo.mp4 foobar.mp3

flv 转 mp3

ffmpeg -i foo.flv foobar.mp3

mp4 transfer wav

ffmpeg -i foo.mp4 foobar.wav

wav transfer mp3

ffmpeg -i foo.wav foobar.mp3

Batch conversion

For example, there are *. MP4 files under the folder. To batch convert them to XX. MP3 files, you can use the following methods

for i in ./*.mp4
do
ffmpeg -i $i ${i}.mp3
done

For another example, all files under the folder should be converted into XX. MP3 files in batch. You can use the following methods

for i in ./*
do
ffmpeg -i $i ${i}.mp3
done

Connect two videos

ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4

Multiple audio merging

ffmpeg.exe -i "concat:1.mp3|2.mp3" -acodec copy output.mp3

AVD FFmpeg avcodec_ A solution of open2 returning – 1 (operation not permitted)

I’m working on Android hard decoding recently. Various attempts have been made on the compatible implementation of soft decoding and hard decoding. Later, I suddenly found that it was unable to decode normally, and even failed to open codec appeared.

Use RET = avcodec_ Open2 (CTX, codec, nullptr) the return value is – 1, and the error message is “operation not permitted”. It’s a headache for me. For Android development, permissions, alas AVStream* st = pFormatCtx->streams[streamIdx]; codec_context_ = avcodec_alloc_context3(pCodec); if (!codec_context_) { AVLOGE("Failed to allocate the codec context."); return -1; } if (avcodec_parameters_to_context(codec_context_, st->codecpar) < 0) { AVLOGE("Failed to copy codec parameters to decoder context."); return -1; } if (enable_hw_decode_) { if (codec_context_->codec_id == AV_CODEC_ID_H264) { pCodec = avcodec_find_decoder_by_name("h264_mediacodec"); if (pCodec) { avcodec_free_context(&codec_context_); codec_context_ = avcodec_alloc_context3(pCodec); using_hw_decode_ = true; } } } int ret = 0; if ((ret = avcodec_open2(codec_context_, pCodec, nullptr)) < 0) { AVLOGE("Failed to open codec. ret = %d, %s", ret, PAVUtils::get_error_string(ret)); return -1; }

Because it was copied once at first, but later, if hard decoding was used, the coder was selected again. As a result, the newly applied avcodec context failed to copy the operation parameters from stream to context. When I was using_ hw_ decode_ = Add avcodec before true _ parameters_ to_ context(codec_ context_, st-> codecpar); and it will work normally
it's strange why the relevant parameters are not copied, instead of returning invalid_ Par returns no instead_ What about permit?