
Recherche avancée
Médias (1)
-
SPIP - plugins - embed code - Exemple
2 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
Autres articles (98)
-
Supporting all media types
13 avril 2011, parUnlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)
-
Changer le statut par défaut des nouveaux inscrits
26 décembre 2015, parPar défaut, lors de leur inscription, les nouveaux utilisateurs ont le statut de visiteur. Ils disposent de certains droits mais ne peuvent pas forcément publier leurs contenus eux-même etc...
Il est possible de changer ce statut par défaut. en "rédacteur".
Pour ce faire, un administrateur webmestre du site doit aller dans l’espace privé de SPIP en ajoutant ecrire/ à l’url de son site.
Une fois dans l’espace privé, il lui faut suivre les menus configuration > Interactivité et activer (...) -
Encoding and processing into web-friendly formats
13 avril 2011, parMediaSPIP automatically converts uploaded files to internet-compatible formats.
Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
All uploaded files are stored online in their original format, so you can (...)
Sur d’autres sites (10609)
-
ffmpeg capture video and audio produced corrupt output
18 décembre 2020, par wheelie tipsI have two separate FFmpeg commands that each works well on its own, one for capturing video and the other for capturing audio from the same device ; the captured audio is :


ffmpeg -f alsa -thread_queue_size 16384 -i hw:CARD=C4K,DEV=0 -acodec aac /home/pi/Videos/temp.wav



and the captured video is :


ffmpeg -y -nostdin -f v4l2 -threads auto -input_format yuyv422 -fflags +genpts -flags +global_header -thread_queue_size 16384 -i /dev/video0 -s 1280x720 -r 25 -vcodec h264_v4l2m2m -num_output_buffers 32 -num_capture_buffers 16 -keyint_min 25 -force_key_frames "expr:gte(t,n_forced*1)" -g 50 -b:v 6M -pix_fmt nv12 -f mpegts -muxdelay 0 -muxpreload 0 -movflags +faststart /home/pi/Videos/output.mp4



I’ve tried to combine the two into one call to produce one video file with the audio channel, but whatever I’ve been attempting, the results output were messed up ; obviously, I’m missing something, for example, my latest attempt prodused a frozen image video with the audio channel :


ffmpeg -y -nostdin -f v4l2 -threads auto -input_format yuyv422 -fflags +genpts -flags +global_header -thread_queue_size 16384 -i /dev/video0 -f alsa -thread_queue_size 16384 -i hw:CARD=C4K,DEV=0 -acodec aac -s 1280x720 -r 25 -vcodec h264_v4l2m2m -num_output_buffers 32 -num_capture_buffers 16 -keyint_min 25 -force_key_frames "expr:gte(t,n_forced*1)" -g 50 -b:v 6M -b:a 128K -pix_fmt nv12 -f mpegts -muxdelay 0 -muxpreload 0 -movflags +faststart /home/pi/Videos/output.mp4 -loglevel debug



the full output of the above command :


ffmpeg version ca55240 Copyright (c) 2000-2020 the FFmpeg developers
 built with gcc 8 (Debian 8.3.0-6)
 configuration: --prefix=/home/pi/ffmpeg_build --pkg-config-flags='pkg-config --static' --extra-cflags=-I/home/pi/ffmpeg_build/include --extra-ldflags=-L/home/pi/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/pi/bin --enable-gpl --enable-gnutls --disable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --disable-libx265 --enable-nonfree --arch=aarch64 --disable-libxml2 --enable-libwebp --enable-libdrm
 libavutil 56. 51.100 / 56. 51.100
 libavcodec 58. 91.100 / 58. 91.100
 libavformat 58. 45.100 / 58. 45.100
 libavdevice 58. 10.100 / 58. 10.100
 libavfilter 7. 85.100 / 7. 85.100
 libswscale 5. 7.100 / 5. 7.100
 libswresample 3. 7.100 / 3. 7.100
 libpostproc 55. 7.100 / 55. 7.100
Splitting the commandline.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-nostdin' ... matched as option 'stdin' (enable or disable interaction on standard input) with argument 0.
Reading option '-f' ... matched as option 'f' (force format) with argument 'v4l2'.
Reading option '-threads' ... matched as AVOption 'threads' with argument 'auto'.
Reading option '-input_format' ... matched as AVOption 'input_format' with argument 'yuyv422'.
Reading option '-fflags' ... matched as AVOption 'fflags' with argument '+genpts'.
Reading option '-flags' ... matched as AVOption 'flags' with argument '+global_header'.
Reading option '-thread_queue_size' ... matched as option 'thread_queue_size' (set the maximum number of queued packets from the demuxer) with argument '16384'.
Reading option '-i' ... matched as input url with argument '/dev/video0'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'alsa'.
Reading option '-thread_queue_size' ... matched as option 'thread_queue_size' (set the maximum number of queued packets from the demuxer) with argument '16384'.
Reading option '-i' ... matched as input url with argument 'hw:CARD=C4K,DEV=0'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'aac'.
Reading option '-s' ... matched as option 's' (set frame size (WxH or abbreviation)) with argument '1280x720'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '25'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'h264_v4l2m2m'.
Reading option '-num_output_buffers' ... matched as AVOption 'num_output_buffers' with argument '32'.
Reading option '-num_capture_buffers' ... matched as AVOption 'num_capture_buffers' with argument '16'.
Reading option '-keyint_min' ... matched as AVOption 'keyint_min' with argument '25'.
Reading option '-force_key_frames' ... matched as option 'force_key_frames' (force key frames at specified timestamps) with argument 'expr:gte(t,n_forced*1)'.
Reading option '-g' ... matched as AVOption 'g' with argument '50'.
Reading option '-b:v' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '6M'.
Reading option '-b:a' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '128K'.
Reading option '-pix_fmt' ... matched as option 'pix_fmt' (set pixel format) with argument 'nv12'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'mpegts'.
Reading option '-muxdelay' ... matched as option 'muxdelay' (set the maximum demux-decode delay) with argument '0'.
Reading option '-muxpreload' ... matched as option 'muxpreload' (set the initial demux-decode delay) with argument '0'.
Reading option '-movflags' ... matched as AVOption 'movflags' with argument '+faststart'.
Reading option '/home/pi/Videos/output.mp4' ... matched as output url.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option nostdin (enable or disable interaction on standard input) with argument 0.
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url /dev/video0.
Applying option f (force format) with argument v4l2.
Applying option thread_queue_size (set the maximum number of queued packets from the demuxer) with argument 16384.
Successfully parsed a group of options.
Opening an input file: /dev/video0.
[video4linux2,v4l2 @ 0x55a0c86b40] fd:3 capabilities:84a00001
[video4linux2,v4l2 @ 0x55a0c86b40] Current input_channel: 0, input_name: Input 1, input_std: 0
[video4linux2,v4l2 @ 0x55a0c86b40] Querying the device for the current frame size
[video4linux2,v4l2 @ 0x55a0c86b40] Setting frame size to 1920x1080
[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).
[video4linux2,v4l2 @ 0x55a0c86b40] All info found Input #0, video4linux2,v4l2, from '/dev/video0':
 Duration: N/A, start: 0.000000, bitrate: 1988671 kb/s
 Stream #0:0, 1, 1/1000000: Video: rawvideo, 1 reference frame (YUY2 / 0x32595559), yuyv422, 1920x1080, 0/1, 1988671 kb/s, 59.94 fps, 59.94 tbr, 1000k tbn, 1000k tbc Successfully opened the file.
Parsing a group of options: input url hw:CARD=C4K,DEV=0.
Applying option f (force format) with argument alsa.
Applying option thread_queue_size (set the maximum number of queued packets from the demuxer) with argument 16384.
Successfully parsed a group of options.
Opening an input file: hw:CARD=C4K,DEV=0.
[alsa @ 0x55a0c89630] All info found
Guessed Channel Layout for Input Stream #1.0 : stereo Input #1, alsa, from 'hw:CARD=C4K,DEV=0':
 Duration: N/A, start: 1608286705.387903, bitrate: 1536 kb/s
 Stream #1:0, 1, 1/1000000: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s Successfully opened the file.
Parsing a group of options: output url /home/pi/Videos/output.mp4.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument aac.
Applying option s (set frame size (WxH or abbreviation)) with argument 1280x720.
Applying option r (set frame rate (Hz value, fraction or abbreviation)) with argument 25.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument h264_v4l2m2m.
Applying option force_key_frames (force key frames at specified timestamps) with argument expr:gte(t,n_forced*1).
Applying option b:v (video bitrate (please use -b:v)) with argument 6M.
Applying option b:a (video bitrate (please use -b:v)) with argument 128K.
Applying option pix_fmt (set pixel format) with argument nv12.
Applying option f (force format) with argument mpegts.
Applying option muxdelay (set the maximum demux-decode delay) with argument 0.
Applying option muxpreload (set the initial demux-decode delay) with argument 0.
Successfully parsed a group of options.
Opening an output file: /home/pi/Videos/output.mp4.
[file @ 0x55a0ca7210] Setting default whitelist 'file,crypto,data'
Successfully opened the file.
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_v4l2m2m))
 Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native)) cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
 Last message repeated 3 times
[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
 Last message repeated 12 times
[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).
 Last message repeated 2 times
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).
 Last message repeated 23 times
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
 Last message repeated 1452 times
[rawvideo @ 0x55a0c89130] PACKET SIZE: 4147200, STRIDE: 3840 detected 4 logical cores [graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting 'video_size' to value '1920x1080'
[graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting 'pix_fmt' to value '1'
[graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting 'time_base' to value '1/1000000'
[graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting 'frame_rate' to value '7013/117'
[graph 0 input from stream 0:0 @ 0x55a0ca9080] w:1920 h:1080 pixfmt:yuyv422 tb:1/1000000 fr:7013/117 sar:0/1
[scaler_out_0_0 @ 0x55a0cb0060] Setting 'w' to value '1280'
[scaler_out_0_0 @ 0x55a0cb0060] Setting 'h' to value '720'
[scaler_out_0_0 @ 0x55a0cb0060] Setting 'flags' to value 'bicubic'
[scaler_out_0_0 @ 0x55a0cb0060] w:1280 h:720 flags:'bicubic' interl:0 [format @ 0x55a0cb05b0] Setting 'pix_fmts' to value 'nv12'
[AVFilterGraph @ 0x55a0ca2730] query_formats: 5 queried, 4 merged, 0 already done, 0 delayed
[scaler_out_0_0 @ 0x55a0cb0060] w:1920 h:1080 fmt:yuyv422 sar:0/1 -> w:1280 h:720 fmt:nv12 sar:0/1 flags:0x4 [h264_v4l2m2m @ 0x55a0ca5610] probing device /dev/video12 [h264_v4l2m2m @ 0x55a0ca5610] driver 'bcm2835-codec' on card 'bcm2835-codec-isp' in mplane mode [h264_v4l2m2m @ 0x55a0ca5610] v4l2 capture format not supported [h264_v4l2m2m @ 0x55a0ca5610] probing device /dev/video11 [h264_v4l2m2m @ 0x55a0ca5610] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode [h264_v4l2m2m @ 0x55a0ca5610] Using device /dev/video11 [h264_v4l2m2m @ 0x55a0ca5610] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode [h264_v4l2m2m @ 0x55a0ca5610] requesting formats: output=NV12 capture=H264 [h264_v4l2m2m @ 0x55a0ca5610] output: NV12 32 buffers initialized: 1280x0720, sizeimage 01382400, bytesperline 00001280 [h264_v4l2m2m @ 0x55a0ca5610] capture: H264 16 buffers initialized: 1280x0720, sizeimage 00524288, bytesperline 00000000 [h264_v4l2m2m @ 0x55a0ca5610] Failed to set number of B-frames: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Failed to get number of B-frames [h264_v4l2m2m @ 0x55a0ca5610] Failed to set header mode: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Encoder: bit rate = 6000000 [h264_v4l2m2m @ 0x55a0ca5610] Failed to set frame level rate control: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Failed to set gop size: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Encoder: repeat parameter sets = 1 [h264_v4l2m2m @ 0x55a0ca5610] Encoder Context: id (27), profile (-99), frame rate(25/1), number b-frames (0), gop size (50), bit rate (6000000), qmin (-1), qmax (-1) [h264_v4l2m2m @ 0x55a0ca5610] Failed to set minimum video quantizer scale: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Failed to set maximum video quantizer scale: Invalid argument Forced keyframe at time 0.000000 [h264_v4l2m2m @ 0x55a0ca5610] Encoder: force key frame = 0 cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[graph_1_in_1_0 @ 0x55a0d465d0] Setting 'time_base' to value '1/48000'
[graph_1_in_1_0 @ 0x55a0d465d0] Setting 'sample_rate' to value '48000'
[graph_1_in_1_0 @ 0x55a0d465d0] Setting 'sample_fmt' to value 's16'
[graph_1_in_1_0 @ 0x55a0d465d0] Setting 'channel_layout' to value '0x3'
[graph_1_in_1_0 @ 0x55a0d465d0] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x3
[format_out_0_1 @ 0x55a0d46af0] Setting 'sample_fmts' to value 'fltp'
[format_out_0_1 @ 0x55a0d46af0] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[format_out_0_1 @ 0x55a0d46af0] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_1'
[AVFilterGraph @ 0x55a0d45c10] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 0x55a0d47740] [SWR @ 0x55a0d47890] Using s16p internally between filters
[auto_resampler_0 @ 0x55a0d47740] ch:2 chl:stereo fmt:s16 r:48000Hz -> ch:2 chl:stereo fmt:fltp r:48000Hz [mpegts @ 0x55a0caec00] service 1 using PCR in pid=256, pcr_period=80ms [mpegts @ 0x55a0caec00] muxrate VBR, sdt every 500 ms, pat/pmt every 100 ms Output #0, mpegts, to '/home/pi/Videos/output.mp4':
 Metadata:
 encoder : Lavf58.45.100
 Stream #0:0, 0, 1/90000: Video: h264 (h264_v4l2m2m), 1 reference frame, nv12(progressive), 1280x720, 0/1, q=-1--1, 6000 kb/s, 25 fps, 90k tbn, 25 tbc
 Metadata:
 encoder : Lavc58.91.100 h264_v4l2m2m
 Stream #0:1, 0, 1/90000: Audio: aac (LC), 48000 Hz, stereo, fltp, delay 1024, 128 kb/s
 Metadata:
 encoder : Lavc58.91.100 aac
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) [rawvideo @ 0x55a0c89130] PACKET SIZE: 4147200, STRIDE: 3840 Clipping frame in rate conversion by 0.132942 cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
 Last message repeated 17 times
^Cframe= 2 fps=0.3 q=-0.0 Lsize= 183kB time=00:21:16.64 bitrate= 1.2kbits/s speed= 189x
video:24kB audio:101kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 46.992252% Input file #0 (/dev/video0):
 Input stream #0:0 (video): 34 packets read (8294400 bytes); 2 frames decoded;
 Total: 34 packets (8294400 bytes) demuxed Input file #1 (hw:CARD=C4K,DEV=0):
 Input stream #1:0 (audio): 2712 packets read (1233148 bytes); 2712 frames decoded (308287 samples);
 Total: 2712 packets (1233148 bytes) demuxed Output file #0 (/home/pi/Videos/output.mp4):
 Output stream #0:0 (video): 2 frames encoded; 2 packets muxed (24588 bytes);
 Output stream #0:1 (audio): 301 frames encoded (308224 samples); 302 packets muxed (103182 bytes);
 Total: 304 packets (127770 bytes) muxed
2714 frames successfully decoded, 0 decoding errors [AVIOContext @ 0x55a0ca7100] Statistics: 0 seeks, 1 writeouts [aac @ 0x55a0ca65e0] Qavg: 165.061 Exiting normally, received signal 2.



can anyone please help me figure this out ?


Thanks much !


RS


-
Linker error by trying example program with ffmpeg
11 mars, par ChrisI think this might be a stupid question and I'm just blind but that thing is driving me nuts for hours now.
I downloaded ffmpeg and build it. Now I want to try the thing out in a program but I can't setup cmake to link ffmpeg properly and have no idea what is wrong.


The linker always tells me this :


christoph@christoph-ThinkPad-T490:~/develop/ffmpg_example/build$ make
[ 50%] Linking CXX executable test
CMakeFiles/test.dir/main.cxx.o: In function `main':
main.cxx:(.text+0x180): undefined reference to `av_register_all()'
main.cxx:(.text+0x1a7): undefined reference to `avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)'
main.cxx:(.text+0x1ce): undefined reference to `avformat_find_stream_info(AVFormatContext*, AVDictionary**)'
main.cxx:(.text+0x206): undefined reference to `av_dump_format(AVFormatContext*, int, char const*, int)'
main.cxx:(.text+0x2bb): undefined reference to `avcodec_find_decoder(AVCodecID)'
main.cxx:(.text+0x2fc): undefined reference to `avcodec_alloc_context3(AVCodec const*)'
main.cxx:(.text+0x316): undefined reference to `avcodec_copy_context(AVCodecContext*, AVCodecContext const*)'
main.cxx:(.text+0x361): undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
main.cxx:(.text+0x377): undefined reference to `av_frame_alloc()'
main.cxx:(.text+0x383): undefined reference to `av_frame_alloc()'
main.cxx:(.text+0x3ba): undefined reference to `avpicture_get_size(AVPixelFormat, int, int)'
main.cxx:(.text+0x3d0): undefined reference to `av_malloc(unsigned long)'
main.cxx:(.text+0x3ff): undefined reference to `avpicture_fill(AVPicture*, unsigned char const*, AVPixelFormat, int, int)'
main.cxx:(.text+0x43d): undefined reference to `sws_getContext(int, int, AVPixelFormat, int, int, AVPixelFormat, int, SwsFilter*, SwsFilter*, double const*)'
main.cxx:(.text+0x465): undefined reference to `av_read_frame(AVFormatContext*, AVPacket*)'
main.cxx:(.text+0x49f): undefined reference to `avcodec_decode_video2(AVCodecContext*, AVFrame*, int*, AVPacket const*)'
main.cxx:(.text+0x4fd): undefined reference to `sws_scale(SwsContext*, unsigned char const* const*, int const*, int, int, unsigned char* const*, int const*)'
main.cxx:(.text+0x545): undefined reference to `av_free_packet(AVPacket*)'
main.cxx:(.text+0x556): undefined reference to `av_free(void*)'
main.cxx:(.text+0x565): undefined reference to `av_frame_free(AVFrame**)'
main.cxx:(.text+0x574): undefined reference to `av_frame_free(AVFrame**)'
main.cxx:(.text+0x580): undefined reference to `avcodec_close(AVCodecContext*)'
main.cxx:(.text+0x58f): undefined reference to `avcodec_close(AVCodecContext*)'
main.cxx:(.text+0x59e): undefined reference to `avformat_close_input(AVFormatContext**)'
collect2: error: ld returned 1 exit status
CMakeFiles/test.dir/build.make:87: recipe for target 'test' failed
make[2]: *** [test] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/test.dir/all' failed
make[1]: *** [CMakeFiles/test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2



The cmake list looks like this :


cmake_minimum_required(VERSION 3.16)

project(ffmpeg_test)

add_library(avformat STATIC IMPORTED)
set_target_properties(avformat
 PROPERTIES IMPORTED_LOCATION /home/christoph/develop/FFmpeg/build/lib/libavformat.a
)
add_library(avcodec STATIC IMPORTED)
set_target_properties(avcodec
 PROPERTIES IMPORTED_LOCATION /home/christoph/develop/FFmpeg/build/lib/libavcodec.a
)
add_library(swscale STATIC IMPORTED)
set_target_properties(swscale
 PROPERTIES IMPORTED_LOCATION /home/christoph/develop/FFmpeg/build/lib/libswscale.a
)
add_library(avutil STATIC IMPORTED)
set_target_properties(avutil
 PROPERTIES IMPORTED_LOCATION /home/christoph/develop/FFmpeg/build/lib/libavutil.a
)
add_executable(test main.cxx)

target_link_libraries(test PRIVATE
 /home/christoph/develop/FFmpeg/build/lib/libavformat.a
 avcodec
 swscale
 avutil
)
target_include_directories(test PRIVATE /home/christoph/develop/FFmpeg/build/include)



And here are the ffmpeg libs :


christoph@christoph-ThinkPad-T490:~/develop/FFmpeg/build/lib$ ll
total 277840
drwxr-xr-x 3 christoph christoph 4096 Dez 7 23:59 ./
drwxr-xr-x 17 christoph christoph 4096 Dez 7 23:59 ../
-rw-r--r-- 1 christoph christoph 173479270 Dez 7 23:59 libavcodec.a
-rw-r--r-- 1 christoph christoph 2174910 Dez 7 23:59 libavdevice.a
-rw-r--r-- 1 christoph christoph 37992438 Dez 7 23:59 libavfilter.a
-rw-r--r-- 1 christoph christoph 59222040 Dez 7 23:59 libavformat.a
-rw-r--r-- 1 christoph christoph 4759514 Dez 7 23:59 libavutil.a
-rw-r--r-- 1 christoph christoph 695698 Dez 7 23:59 libswresample.a
-rw-r--r-- 1 christoph christoph 6164398 Dez 7 23:59 libswscale.a
drwxr-xr-x 2 christoph christoph 4096 Dez 7 23:59 pkgconfig/



And this is the example code :


#include

#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libswscale></libswscale>swscale.h>

// compatibility with newer API
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
#define av_frame_alloc avcodec_alloc_frame
#define av_frame_free avcodec_free_frame
#endif

void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {
 FILE *pFile;
 char szFilename[32];
 int y;
 
 // Open file
 sprintf(szFilename, "frame%d.ppm", iFrame);
 pFile=fopen(szFilename, "wb");
 if(pFile==NULL)
 return;
 
 // Write header
 fprintf(pFile, "P6\n%d %d\n255\n", width, height);
 
 // Write pixel data
 for(y=0; ydata[0]+y*pFrame->linesize[0], 1, width*3, pFile);
 
 // Close file
 fclose(pFile);
}

int main(int argc, char *argv[]) {
 // Initalizing these to NULL prevents segfaults!
 AVFormatContext *pFormatCtx = NULL;
 int i, videoStream;
 AVCodecContext *pCodecCtxOrig = NULL;
 AVCodecContext *pCodecCtx = NULL;
 AVCodec *pCodec = NULL;
 AVFrame *pFrame = NULL;
 AVFrame *pFrameRGB = NULL;
 AVPacket packet;
 int frameFinished;
 int numBytes;
 uint8_t *buffer = NULL;
 struct SwsContext *sws_ctx = NULL;

 if(argc < 2) {
 printf("Please provide a movie file\n");
 return -1;
 }
 // Register all formats and codecs
 av_register_all();
 
 // Open video file
 if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0)
 return -1; // Couldn't open file
 
 // Retrieve stream information
 if(avformat_find_stream_info(pFormatCtx, NULL)<0)
 return -1; // Couldn't find stream information
 
 // Dump information about file onto standard error
 av_dump_format(pFormatCtx, 0, argv[1], 0);
 
 // Find the first video stream
 videoStream=-1;
 for(i=0; inb_streams; i++)
 if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
 videoStream=i;
 break;
 }
 if(videoStream==-1)
 return -1; // Didn't find a video stream
 
 // Get a pointer to the codec context for the video stream
 pCodecCtxOrig=pFormatCtx->streams[videoStream]->codec;
 // Find the decoder for the video stream
 pCodec=avcodec_find_decoder(pCodecCtxOrig->codec_id);
 if(pCodec==NULL) {
 fprintf(stderr, "Unsupported codec!\n");
 return -1; // Codec not found
 }
 // Copy context
 pCodecCtx = avcodec_alloc_context3(pCodec);
 if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {
 fprintf(stderr, "Couldn't copy codec context");
 return -1; // Error copying codec context
 }

 // Open codec
 if(avcodec_open2(pCodecCtx, pCodec, NULL)<0)
 return -1; // Could not open codec
 
 // Allocate video frame
 pFrame=av_frame_alloc();
 
 // Allocate an AVFrame structure
 pFrameRGB=av_frame_alloc();
 if(pFrameRGB==NULL)
 return -1;

 // Determine required buffer size and allocate buffer
 numBytes=avpicture_get_size(AV_PIX_FMT_RGB24, pCodecCtx->width,
 pCodecCtx->height);
 buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
 
 // Assign appropriate parts of buffer to image planes in pFrameRGB
 // Note that pFrameRGB is an AVFrame, but AVFrame is a superset
 // of AVPicture
 avpicture_fill((AVPicture *)pFrameRGB, buffer, AV_PIX_FMT_RGB24,
 pCodecCtx->width, pCodecCtx->height);
 
 // initialize SWS context for software scaling
 sws_ctx = sws_getContext(pCodecCtx->width,
 pCodecCtx->height,
 pCodecCtx->pix_fmt,
 pCodecCtx->width,
 pCodecCtx->height,
 AV_PIX_FMT_RGB24,
 SWS_BILINEAR,
 NULL,
 NULL,
 NULL
 );

 // Read frames and save first five frames to disk
 i=0;
 while(av_read_frame(pFormatCtx, &packet)>=0) {
 // Is this a packet from the video stream?
 if(packet.stream_index==videoStream) {
 // Decode video frame
 avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
 
 // Did we get a video frame?
 if(frameFinished) {
 // Convert the image from its native format to RGB
 sws_scale(sws_ctx, (uint8_t const * const *)pFrame->data,
 pFrame->linesize, 0, pCodecCtx->height,
 pFrameRGB->data, pFrameRGB->linesize);
 
 // Save the frame to disk
 if(++i<=5)
 SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, 
 i);
 }
 }
 
 // Free the packet that was allocated by av_read_frame
 av_free_packet(&packet);
 }
 
 // Free the RGB image
 av_free(buffer);
 av_frame_free(&pFrameRGB);
 
 // Free the YUV frame
 av_frame_free(&pFrame);
 
 // Close the codecs
 avcodec_close(pCodecCtx);
 avcodec_close(pCodecCtxOrig);

 // Close the video file
 avformat_close_input(&pFormatCtx);
 
 return 0;
}



-
Python opencv ffmpeg threading exit functions
29 novembre 2020, par scacchii'm trying to finish the audio/video recording loop by pressing a key (or by other event), if i use the simple time.sleep() in the main loop work perfectly, after 5 second stop video and create file, if i use the function keyboard_pressed() doesnt execute stop_AVrecording() correctly and file_manager().
What's im doing wrong ?
Thanks in advance


from __future__ import print_function, division
import numpy as np
import cv2
import pyaudio
import wave
import threading
import time
import subprocess
import os
import keyboard

class VideoRecorder:
 "Video class based on openCV"
 def __init__(self, name="temp_video.avi", fourcc="MJPG", sizex=640, sizey=480, fps=30):
 self.open = True
 self.fps = fps # fps should be the minimum constant rate at which the camera can
 self.fourcc = fourcc # capture images (with no decrease in speed over time; testing is required)
 self.frameSize = (sizex, sizey) # video formats and sizes also depend and vary according to the camera used
 self.video_filename = name
 self.video_cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)
 self.video_writer = cv2.VideoWriter_fourcc(*self.fourcc)
 self.video_out = cv2.VideoWriter(self.video_filename, self.video_writer, self.fps, self.frameSize)
 self.frame_counts = 1
 self.start_time = time.time()

 def record(self):
 "Video starts being recorded"
 counter = 1
 timer_start = time.time()
 timer_current = 0
 while self.open:
 ret, video_frame = self.video_cap.read()
 if ret:
 self.video_out.write(video_frame)
 # print(str(counter) + " " + str(self.frame_counts) + " frames written " + str(timer_current))
 self.frame_counts += 1
 counter += 1
 timer_current = time.time() - timer_start
 #time.sleep(1/self.fps)
 # gray = cv2.cvtColor(video_frame, cv2.COLOR_BGR2GRAY)
 cv2.imshow('video_frame', video_frame)
 cv2.waitKey(1)
 else:
 break

 def stop(self):
 "Finishes the video recording therefore the thread too"
 if self.open:
 self.open=False
 self.video_out.release()
 self.video_cap.release()
 cv2.destroyAllWindows()

 def start(self):
 "Launches the video recording function using a thread"
 video_thread = threading.Thread(target=self.record)
 video_thread.start()

class AudioRecorder():
 "Audio class based on pyAudio and Wave"
 def __init__(self, filename="temp_audio.wav", rate=44100, fpb=1024, channels=2):
 self.open = True
 self.rate = rate
 self.frames_per_buffer = fpb
 self.channels = channels
 self.format = pyaudio.paInt16
 self.audio_filename = filename
 self.audio = pyaudio.PyAudio()
 self.stream = self.audio.open(format=self.format,
 channels=self.channels,
 rate=self.rate,
 input=True,
 frames_per_buffer = self.frames_per_buffer)
 self.audio_frames = []

 def record(self):
 "Audio starts being recorded"
 self.stream.start_stream()
 while self.open:
 data = self.stream.read(self.frames_per_buffer)
 self.audio_frames.append(data)
 if not self.open:
 break

 def stop(self):
 "Finishes the audio recording therefore the thread too"
 if self.open:
 self.open = False
 self.stream.stop_stream()
 self.stream.close()
 self.audio.terminate()
 waveFile = wave.open(self.audio_filename, 'wb')
 waveFile.setnchannels(self.channels)
 waveFile.setsampwidth(self.audio.get_sample_size(self.format))
 waveFile.setframerate(self.rate)
 waveFile.writeframes(b''.join(self.audio_frames))
 waveFile.close()

 def start(self):
 "Launches the audio recording function using a thread"
 audio_thread = threading.Thread(target=self.record)
 audio_thread.start()

def start_AVrecording(filename="test"):
 global video_thread
 global audio_thread
 video_thread = VideoRecorder()
 audio_thread = AudioRecorder()
 audio_thread.start()
 video_thread.start()
 return filename


def start_video_recording(filename="test"):
 global video_thread
 video_thread = VideoRecorder()
 video_thread.start()
 return filename

def start_audio_recording(filename="test"):
 global audio_thread
 audio_thread = AudioRecorder()
 audio_thread.start()
 return filename

def stop_AVrecording(filename="test"):
 audio_thread.stop()
 frame_counts = video_thread.frame_counts
 elapsed_time = time.time() - video_thread.start_time
 recorded_fps = frame_counts / elapsed_time
 print("total frames " + str(frame_counts))
 print("elapsed time " + str(elapsed_time))
 print("recorded fps " + str(recorded_fps))
 video_thread.stop()

 # Makes sure the threads have finished
 while threading.active_count() > 1:
 time.sleep(1)

 # Merging audio and video signal
 if abs(recorded_fps - 6) >= 0.01: # If the fps rate was higher/lower than expected, re-encode it to the expected
 print("Re-encoding")
 cmd = "ffmpeg -r " + str(recorded_fps) + " -i temp_video.avi -pix_fmt yuv420p -r 6 temp_video2.avi"
 subprocess.call(cmd, shell=True)
 print("Muxing")
 cmd = "ffmpeg -y -ac 2 -channel_layout stereo -i temp_audio.wav -i temp_video2.avi -pix_fmt yuv420p " + filename + ".avi"
 subprocess.call(cmd, shell=True)
 else:
 print("Normal recording\nMuxing")
 cmd = "ffmpeg -y -ac 2 -channel_layout stereo -i temp_audio.wav -i temp_video.avi -pix_fmt yuv420p " + filename + ".avi"
 subprocess.call(cmd, shell=True)
 print("..")

def file_manager(filename="test"):
 "Required and wanted processing of final files"
 local_path = os.getcwd()
 if os.path.exists(str(local_path) + "/temp_audio.wav"):
 os.remove(str(local_path) + "/temp_audio.wav")
 if os.path.exists(str(local_path) + "/temp_video.avi"):
 os.remove(str(local_path) + "/temp_video.avi")
 if os.path.exists(str(local_path) + "/temp_video2.avi"):
 os.remove(str(local_path) + "/temp_video2.avi")
 # if os.path.exists(str(local_path) + "/" + filename + ".avi"):
 # os.remove(str(local_path) + "/" + filename + ".avi")

def keyboard_pressed():
 while True:
 if keyboard.is_pressed('q'): # if key 'q' is pressed
 print('------------You Pressed Q Key!--------------')
 #time.sleep(5)
 break


if __name__ == '__main__':
 start_AVrecording()
 #time.sleep(5)
 keyboard_pressed()
 print('-------------Time Sleep-------------------')
 time.sleep(5)
 print('-------------Stop AVrecording-------------')
 stop_AVrecording()
 print('-------------File Manager-----------------')
 file_manager()
 print('-----------------End----------------------')



'''