
Recherche avancée
Médias (91)
-
Chuck D with Fine Arts Militia - No Meaning No
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Paul Westerberg - Looking Up in Heaven
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Le Tigre - Fake French
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Thievery Corporation - DC 3000
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Dan the Automator - Relaxation Spa Treatment
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Gilberto Gil - Oslodum
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
Autres articles (106)
-
Keeping control of your media in your hands
13 avril 2011, parThe vocabulary used on this site and around MediaSPIP in general, aims to avoid reference to Web 2.0 and the companies that profit from media-sharing.
While using MediaSPIP, you are invited to avoid using words like "Brand", "Cloud" and "Market".
MediaSPIP is designed to facilitate the sharing of creative media online, while allowing authors to retain complete control of their work.
MediaSPIP aims to be accessible to as many people as possible and development is based on expanding the (...) -
Multilang : améliorer l’interface pour les blocs multilingues
18 février 2011, parMultilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela. -
Personnaliser les catégories
21 juin 2013, parFormulaire de création d’une catégorie
Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
On peut modifier ce formulaire dans la partie :
Administration > Configuration des masques de formulaire.
Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)
Sur d’autres sites (10159)
-
Failed to play MP3 audio with ffmpeg API in Linux
15 janvier, par wangt13I am working on an audioplayer by using FFMPEG library, and ALSA.

The following codes failed to playback the MP3 media smoothly (it is slower and noisy), I checked the FFMPEG codes and examples, but I did not the right solutions.

#include 
#include 
#include <alsa></alsa>asoundlib.h>

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

int init_pcm_play(snd_pcm_t **playback_handle,snd_pcm_uframes_t chunk_size,unsigned int rate,int bits_per_sample,int channels)
{
 snd_pcm_hw_params_t *hw_params;
 snd_pcm_format_t format;

 //1. openPCM,
 if (0 > snd_pcm_open(playback_handle, "default", SND_PCM_STREAM_PLAYBACK, 0))
 {
 printf("snd_pcm_open err\n");
 return -1;
 }
 //2. snd_pcm_hw_params_t
 if(0 > snd_pcm_hw_params_malloc (&hw_params))
 {
 printf("snd_pcm_hw_params_malloc err\n");
 return -1;
 }
 //3. hw_params
 if(0 > snd_pcm_hw_params_any (*playback_handle, hw_params))
 {
 printf("snd_pcm_hw_params_any err\n");
 return -1;
 }
 //4.
 if (0 > snd_pcm_hw_params_set_access (*playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED))
 {
 printf("snd_pcm_hw_params_any err\n");
 return -1;
 }

 //5. SND_PCM_FORMAT_U8,8
 if(8 == bits_per_sample) {
 format = SND_PCM_FORMAT_U8;
 }
 if(16 == bits_per_sample) {
 format = SND_PCM_FORMAT_S16_LE;
 }
 if (0 > snd_pcm_hw_params_set_format (*playback_handle, hw_params, format))
 {
 printf("snd_pcm_hw_params_set_format err\n");
 return -1;
 }

 //6.
 if (0 > snd_pcm_hw_params_set_rate_near (*playback_handle, hw_params, &rate, 0))
 {
 printf("snd_pcm_hw_params_set_rate_near err\n");
 return -1;
 }
 //7.
 if (0 > snd_pcm_hw_params_set_channels(*playback_handle, hw_params, 2))
 {
 printf("snd_pcm_hw_params_set_channels err\n");
 return -1;
 }

 //8. set hw_params
 if (0 > snd_pcm_hw_params (*playback_handle, hw_params))
 {
 printf("snd_pcm_hw_params err\n");
 return -1;
 }

 snd_pcm_hw_params_get_period_size(hw_params, &chunk_size, 0);

 snd_pcm_hw_params_free (hw_params);

 return 0;
}

int main(int argc, char *argv[])
{
 AVFormatContext *pFormatCtx = NULL; //for opening multi-media file
 int audioStream = -1;
 AVCodecContext *pCodecCtx = NULL;
 AVCodec *pCodec = NULL; // the codecer
 AVFrame *pFrame = NULL;
 AVPacket *packet;
 uint8_t *out_buffer;
 struct SwrContext *au_convert_ctx;
 snd_pcm_t *playback_handle;
 int bits_per_sample = 0;

 if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL) != 0) {
 printf("Failed to open video file!");
 return -1; // Couldn't open file
 }

 if(avformat_find_stream_info(pFormatCtx,NULL)<0)
 {
 printf("Failed to find stream info.\n");
 return -1;
 }

 audioStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);
 if (audioStream == -1) {
 printf("Din't find a video stream!");
 return -1;// Didn't find a video stream
 }

 av_dump_format(pFormatCtx, audioStream, NULL, false);

 // Find the decoder for the video stream
 pCodec = avcodec_find_decoder(pFormatCtx->streams[audioStream]->codecpar->codec_id);
 if (pCodec == NULL) {
 printf("Unsupported codec!\n");
 return -1; // Codec not found
 }

 // Copy context
 pCodecCtx = avcodec_alloc_context3(pCodec);
 AVCodecParameters *pCodecParam = pFormatCtx->streams[audioStream]->codecpar;

 if (avcodec_parameters_to_context(pCodecCtx, pCodecParam) < 0) {
 printf("Failed to set codec params\n");
 return -1;
 }
 // Open codec
 if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
 printf("Failed to open decoder!\n");
 return -1; // Could not open codec
 }
 packet = av_packet_alloc();
 pFrame = av_frame_alloc();

 uint64_t iInputLayout = av_get_default_channel_layout(pCodecCtx->channels);
 enum AVSampleFormat eInputSampleFormat = pCodecCtx->sample_fmt;
 int iInputSampleRate = pCodecCtx->sample_rate;


 uint64_t iOutputLayout = av_get_default_channel_layout(pCodecCtx->channels);
 int iOutputChans = pCodecCtx->channels;
 enum AVSampleFormat eOutputSampleFormat = AV_SAMPLE_FMT_S16;
 int iOutputSampleRate = pCodecCtx->sample_rate;

 au_convert_ctx = swr_alloc_set_opts(NULL,iOutputLayout, eOutputSampleFormat, iOutputSampleRate,
 iInputLayout,eInputSampleFormat, iInputSampleRate, 0, NULL);
 swr_init(au_convert_ctx);
 int iConvertLineSize = 0;
 int iConvertBuffSize = av_samples_get_buffer_size(&iConvertLineSize, iOutputChans, pCodecCtx->frame_size, eOutputSampleFormat, 0);
 printf("ochans: %d, ifrmsmp: %d, osfmt: %d, cbufsz: %d\n", iOutputChans, pCodecCtx->frame_size, eOutputSampleFormat, iConvertBuffSize);
 out_buffer = (uint8_t *) av_malloc(iConvertBuffSize);

 if(eOutputSampleFormat == AV_SAMPLE_FMT_S16 )
 {
 bits_per_sample = 16;
 }
 /*** alsa handle ***/
 init_pcm_play(&playback_handle,256, iOutputSampleRate,bits_per_sample,2);

 if (0 > snd_pcm_prepare (playback_handle))
 {
 printf("snd_pcm_prepare err\n");
 return -1;
 }

 while (av_read_frame(pFormatCtx, packet) >= 0) {
 if (packet->stream_index == audioStream) {
 avcodec_send_packet(pCodecCtx, packet);
 while (avcodec_receive_frame(pCodecCtx, pFrame) == 0) {
 int outframes = swr_convert(au_convert_ctx, &out_buffer, pCodecCtx->frame_size, (const uint8_t **) pFrame->data, pFrame->nb_samples); // 转换音频
 snd_pcm_writei(playback_handle, out_buffer, outframes);
 av_frame_unref(pFrame);
 }
 }
 av_packet_unref(packet);
 }
 swr_free(&au_convert_ctx);
 snd_pcm_close(playback_handle);
 av_freep(&out_buffer);

 return 0;
}



Running the codes can show following logs.


./ap_alsa ./dooralarm.mp3
[mp3 @ 0x1e72020] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '(null)':
 Metadata:
 genre : Blues
 id3v2_priv.XMP : <?xpacket begin="\xef\xbb\xbf" id="W5M0MpCehiHzreSzNTczkc9d"?>\x0a\x0a \x0a s
 Stream #0:0: Audio: mp3, 22050 Hz, mono, fltp, 48 kb/s
ochans: 1, ifrmsmp: 576, osfmt: 1, cbufsz: 1152



I am using the FFMPEG-4.4.4, and Linux-kernel-5.10.20.


-
FFMPEG : Specifying Output Stream Type When Combing Multiple Filters
7 mai 2021, par Leonard BednerI currently have 3 separate
ffmpeg
commands that do the following :

- 

- Overlay a watermark on a video :
ffmpeg -i samplegreen.webm -i foregrounds/myimage.png -r 30 -filter_complex "overlay=(W-w)/2:H-h" -af "adelay=700" output.mp4
- Overlay the results of 1) onto a beach video :
ffmpeg -i backgrounds/beachsunsetmp4.mp4 -i output.mp4 -filter_complex "[1:v]chromakey=0x005d0b:0.1485:0.03[ckout];[0:v][ckout]overlay[o]" -map [o] -map 1:a -shortest somefolder/sample_video.mp4
- Merge the audio of the results of 2) with another audio file :
ffmpeg -i somefolder/sample_video.mp4 -i backgrounds/beachsunsetmp4.mp3 -filter_complex '[0:a][1:a]amerge=inputs=2[a]' -map 0:v -map '[a]' -c:v copy -ac 2 -shortest anotherfolder/sample_video.mp4








Now, this all works as intended, however, I was looking into attempting to combine them all into a single command, combining all the filters, like so :


ffmpeg -i samplegreen.webm -i foregrounds/myimage.png -r 30 -i backgrounds/beachsunsetmp4.mp4 -i backgrounds/beachsunsetmp4.mp3 -filter_complex \
 "[0]overlay=(W-w)/2:H-h[output_1]; \
 [output_1]chromakey=0x005d0b:0.1485:0.03[ckout]; \
 [2:v][ckout]overlay[output_2]; \
 [output_2][3:a] amerge=inputs=2 [output_3]" \
 -af "adelay=700" -map [output_3] shortest final.mp4



It fails with the following error (
Media type mismatch between the 'Parsed_overlay_2' filter output pad 0 (video) and the 'Parsed_amerge_3' filter input pad 0 (audio)
) :

ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
 built with Apple clang version 11.0.0 (clang-1100.0.33.17)
 configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.2_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
 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
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 7.100 / 5. 7.100
 libswresample 3. 7.100 / 3. 7.100
 libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from 'samplegreen.webm':
 Metadata:
 encoder : Chrome
 Duration: N/A, start: 0.000000, bitrate: N/A
 Stream #0:0(eng): Video: vp8, yuv420p(progressive), 1280x720, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn, 1k tbc (default)
 Metadata:
 alpha_mode : 1
 Stream #0:1(eng): Audio: opus, 48000 Hz, mono, fltp (default)
Input #1, png_pipe, from 'foregrounds/myimage.png':
 Duration: N/A, bitrate: N/A
 Stream #1:0: Video: png, rgba(pc), 350x86, 25 tbr, 25 tbn, 25 tbc
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'backgrounds/beachsunsetmp4.mp4':
 Metadata:
 major_brand : mp42
 minor_version : 0
 compatible_brands: mp42mp41
 creation_time : 2021-02-16T18:24:40.000000Z
 Duration: 00:00:32.53, start: 0.000000, bitrate: 3032 kb/s
 Stream #2:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 3027 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
 Metadata:
 creation_time : 2021-02-16T18:24:40.000000Z
 handler_name : ?Mainconcept Video Media Handler
 encoder : AVC Coding
[mp3 @ 0x7f86cf809000] Estimating duration from bitrate, this may be inaccurate
Input #3, mp3, from 'backgrounds/beachsunsetmp4.mp3':
 Metadata:
 date : 2021-02-18 06:49
 id3v2_priv.XMP : <?xpacket begin="\xef\xbb\xbf" id="W5M0MpCehiHzreSzNTczkc9d"?>\x0a\x0a \x0a s
 Stream #3:0: Audio: mp3, 48000 Hz, stereo, fltp, 128 kb/s
[Parsed_overlay_2 @ 0x7f86cd4039c0] Media type mismatch between the 'Parsed_overlay_2' filter output pad 0 (video) and the 'Parsed_amerge_3' filter input pad 0 (audio)
[AVFilterGraph @ 0x7f86cd402a40] Cannot create the link overlay:0 -> amerge:0
Error initializing complex filters.
Invalid argument



As far as I can tell, the issue is that the filter,
amerge
, wants 2 audio streams. Normally, I could take the input stream argument (which is a video), and make it use the audio by doing something like[0:a][1:a]amerge=inputs=2[results]
. However, since my input stream is the output of a preceding filter, that doesn't seem to work (i.e. [output_2:a]). It bombs out with :

[matroska,webm @ 0x7fecca000000] Invalid stream specifier: output_2:a.
 Last message repeated 1 times
Stream specifier 'output_2:a' in filtergraph description [0]overlay=(W-w)/2:H-h[output_1]; [output_1]chromakey=0x005d0b:0.1485:0.03[ckout]; [2:v][ckout]overlay[output_2]; [output_2:a][3:a] amerge=inputs=2 [output_3] matches no streams.



So all of that said... Is there a way to specify that I'd like to use the audio stream from the output of a preceding filter ? Or any other ways to combine all of these filters into a single command ?


Thanks.


Any help would be greatly appreciated !


- Overlay a watermark on a video :
-
movenc : Add an F4V muxer
17 septembre 2012, par Clément Bœschmovenc : Add an F4V muxer
F4V is Adobe’s mp4/iso media variant, with the most significant
addition/change being supporting other flash codecs than just
aac/h264.Signed-off-by : Martin Storsjö <martin@martin.st>