
Recherche avancée
Autres articles (70)
-
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 (...) -
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Selection of projects using MediaSPIP
2 mai 2011, parThe examples below are representative elements of MediaSPIP specific uses for specific projects.
MediaSPIP farm @ Infini
The non profit organizationInfini develops hospitality activities, internet access point, training, realizing innovative projects in the field of information and communication technologies and Communication, and hosting of websites. It plays a unique and prominent role in the Brest (France) area, at the national level, among the half-dozen such association. Its members (...)
Sur d’autres sites (8544)
-
Error finding watermark path using ffmpeg in asp.net application
27 août 2013, par irfanmcsdI am using .net ffmpeg wrapper to post watermark on videos. Posting watermark works fine if i execute ffmpeg command directly but failed to find suitable watermark png file location if command executed via asp.net application.
here is sample ffmpeg command
string RootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath);
_mhandler.FFMPEGPath = RootPath + "/ffmpeg_aug_2013/bin/ffmpeg.exe";
_mhandler.InputPath = RootPath + "/contents/original";
_mhandler.OutputPath = RootPath + "/contents/mp4";
_mhandler.BackgroundProcessing = false;
_mhandler.FileName = "wildlife.wmv";
_mhandler.OutputFileName = "wildlife_ddd";
string presetpath = RootPath + "/ffmpeg_aug_2013/presets/libx264-ipod640.ffpreset";
_mhandler.OutputExtension = ".mp4";
_mhandler.Parameters = "-s 640x380 -b:v 500k -bufsize 500k -b:a 128k -ar 44100 -c:v libx264 -vf \"movie = watermark.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]\"";
_mhandler.Parameters = _mhandler.Parameters + " -fpre \"" + presetpath + "\"";
VideoInfo info = _mhandler.Process();i tried direct code too
string _out = "";
Process _process = new Process();
_process.StartInfo.UseShellExecute = false;
_process.StartInfo.RedirectStandardInput = true;
//_process.StartInfo.RedirectStandardOutput = true;
_process.StartInfo.RedirectStandardError = true;
_process.StartInfo.CreateNoWindow = true;
_process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_process.StartInfo.FileName = _ffmpegpath;
_process.StartInfo.Arguments = cmd;
if (_process.Start())
{
_process.WaitForExit(ExitProcess);
_out = _process.StandardError.ReadToEnd();
if (!_process.HasExited)
_process.Kill();
return _out;
}ffmpeg error output as
FFMPEG Output:ffmpeg version N-55753-g88909be Copyright (c) 2000-2013
the FFmpeg developers built on Aug 24 2013 21:40:51 with gcc 4.7.3
(GCC) configuration : —enable-gpl —enable-version3
—disable-w32threads —enable-avisynth —enable-bzlib —enable-fontconfig —enable-frei0r —enable-gnutls —enable-iconv —enable-libass —enable-libbluray —enable-libcaca —enable-libfreetype —enable-libgsm —enable-libilbc —enable-libmodplug —enable-libmp3lame —enable-libopencore-amrnb —enable-libopencore-amrwb —enable-libopenjpeg —enable-libopus —enable-librtmp —enable-libschroedinger —enable-libsoxr —enable-libspeex —enable-libtheora —enable-libtwolame —enable-libvo-aacenc —enable-libvo-amrwbenc —enable-libvorbis —enable-libvpx —enable-libx264 —enable-libxavs —enable-libxvid —enable-zlib libavutil 52. 42.100 / 52. 42.100 libavcodec 55. 29.100 / 55. 29.100 libavformat 55. 14.102 / 55. 14.102 libavdevice 55. 3.100
/ 55. 3.100 libavfilter 3. 82.102 / 3. 82.102 libswscale 2. 5.100 / 2.
5.100 libswresample 0. 17.103 / 0. 17.103 libpostproc 52. 3.100 / 52. 3.100 [asf @ 024c9960] Stream #0 : not enough frames to estimate rate ; consider increasing probesize Guessed Channel Layout for Input Stream0.0 : stereo Input #0, asf, from 'F :\own\mhp_new/contents/original\wildlife.wmv' : Metadata :
SfOriginalFPS : 299700 WMFSDKVersion : 11.0.6001.7000 WMFSDKNeeded :
0.0.0.0000 comment : Footage : Small World Productions, Inc ; Tourism New Zealand | Producer : Gary F. Spradling | Music : Steve Ball title :
Wildlife in HD copyright : © 2008 Microsoft Corporation IsVBR : 0
DeviceConformanceTemplate : AP@L3 Duration : 00:00:30.09, start :
0.000000, bitrate : 6977 kb/s Stream #0:0(eng) : Audio : wmav2 (a1[0][0] / 0x0161), 44100 Hz, stereo, fltp, 192 kb/s Stream0:1(eng) : Video : vc1 (Advanced) (WVC1 / 0x31435657), yuv420p, 1280x720, 5942 kb/s, 29.97 tbr, 1k tbn, 1k tbc [image2 @ 024c76e0]
Could find no file with path 'watermark.png' and index in the range
0-4 [Parsed_movie_0 @ 024c0540] Failed to avformat_open_input
'watermark.png' [AVFilterGraph @ 024ca100] Error initializing filter
'movie' with args 'watermark.png' Error opening filters ! Error Code= 0Error on point ( Could find no file with path 'watermark.png' ) shows watermark.png file not found.
I place watermark.png file in the following locations but still can't foundi : application root
ii : root where actual aspx page located
iii : ffmpeg root
iv : ffmpeg/bin/
I also used complete path but still can't detected.
Note : if i use same ffmpeg command in php and place watermark.png on location where actual php page exist watermark properly detected and command executed properly, but same approach not working in asp.net
Can any one help me where should i place watermark.png file so that script can access it.
-
FFMPEG audio transcoding using libav* libraries
25 mai 2022, par vinvinodI am writing an audio transcoding application using ffmpeg libraries. 
Here is my code



/*
 * File: main.cpp
 * Author: vinod
 * Compile with "g++ -std=c++11 -o audiotranscode main.cpp -lavformat -lavcodec -lavutil -lavfilter"
 * 
 */


 #if !defined PRId64 || PRI_MACROS_BROKEN
 #undef PRId64
 #define PRId64 "lld"
 #endif

 #define __STDC_FORMAT_MACROS

 #ifdef __cplusplus
 extern "C" {
 #endif

 #include 
 #include 
 #include <sys></sys>types.h>
 #include 
 #include <libavutil></libavutil>imgutils.h>
 #include <libavutil></libavutil>samplefmt.h>
 #include <libavutil></libavutil>frame.h>
 #include <libavutil></libavutil>timestamp.h>
 #include <libavformat></libavformat>avformat.h>
 #include <libavfilter></libavfilter>avfilter.h>
 #include <libavfilter></libavfilter>buffersrc.h>
 #include <libavfilter></libavfilter>buffersink.h>
 #include <libswscale></libswscale>swscale.h>
 #include <libavutil></libavutil>opt.h>

 #ifdef __cplusplus
 }
 #endif

 #include <iostream>
 using namespace std;

 int select_stream, got_frame, got_packet;

 AVFormatContext *in_fmt_ctx = NULL, *out_fmt_ctx = NULL;
 AVCodec *dec_codec = NULL, * enc_codec = NULL;
 AVStream *audio_st = NULL;
 AVCodecContext *enc_ctx = NULL, *dec_ctx = NULL;

 AVFrame *pFrame = NULL, * pFrameFiltered = NULL;

 AVFilterGraph *filter_graph = NULL;
 AVFilterContext *buffersrc_ctx = NULL;
 AVFilterContext *buffersink_ctx = NULL;

 AVPacket packet;

 string inFileName = "/home/vinod/vinod/Media/univac.webm";
 string outFileName = "audio_extracted.m4a";

 int target_bit_rate = 128000,
 sample_rate = 22050,
 channels = 1;
 AVSampleFormat sample_fmt = AV_SAMPLE_FMT_S16;
 string filter_description = "aresample=22050,aformat=sample_fmts=s16:channel_layouts=mono";

 int log_averror(int errcode)
 {
 char *errbuf = (char *) calloc(AV_ERROR_MAX_STRING_SIZE, sizeof(char));
 av_strerror(errcode, errbuf, AV_ERROR_MAX_STRING_SIZE);
 std::cout << "Error - " << errbuf << std::endl;
 delete [] errbuf;
 return -1;
 }

 /**
 * Initialize conversion filter */
 int initialize_audio_filter()
 {
 char args[512];
 int ret;
 AVFilter *buffersrc = avfilter_get_by_name("abuffer");
 AVFilter *buffersink = avfilter_get_by_name("abuffersink");
 AVFilterInOut *outputs = avfilter_inout_alloc();
 AVFilterInOut *inputs = avfilter_inout_alloc();
 filter_graph = avfilter_graph_alloc();
 const enum AVSampleFormat out_sample_fmts[] = {sample_fmt, AV_SAMPLE_FMT_NONE};
 const int64_t out_channel_layouts[] = {av_get_default_channel_layout(out_fmt_ctx -> streams[0] -> codec -> channels), -1};
 const int out_sample_rates[] = {out_fmt_ctx -> streams[0] -> codec -> sample_rate, -1};

 if (!dec_ctx->channel_layout)
 dec_ctx->channel_layout = av_get_default_channel_layout(dec_ctx->channels);

 snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%" PRIx64,
 in_fmt_ctx -> streams[select_stream] -> time_base.num, in_fmt_ctx -> streams[select_stream] -> time_base.den,
 dec_ctx->sample_rate,
 av_get_sample_fmt_name(dec_ctx->sample_fmt),
 dec_ctx->channel_layout);
 ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, filter_graph);

 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
 return -1;
 }

 ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, NULL, filter_graph);

 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
 return ret;
 }

 ret = av_opt_set_int_list(buffersink_ctx, "sample_fmts", out_sample_fmts, -1,
 AV_OPT_SEARCH_CHILDREN);

 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot set output sample format\n");
 return ret;
 }

 ret = av_opt_set_int_list(buffersink_ctx, "channel_layouts", out_channel_layouts, -1,
 AV_OPT_SEARCH_CHILDREN);

 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot set output channel layout\n");
 return ret;
 }

 ret = av_opt_set_int_list(buffersink_ctx, "sample_rates", out_sample_rates, -1,
 AV_OPT_SEARCH_CHILDREN);

 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot set output sample rate\n");
 return ret;
 }

 /* Endpoints for the filter graph. */
 outputs -> name = av_strdup("in");
 outputs -> filter_ctx = buffersrc_ctx;
 outputs -> pad_idx = 0;
 outputs -> next = NULL;
 /* Endpoints for the filter graph. */
 inputs -> name = av_strdup("out");
 inputs -> filter_ctx = buffersink_ctx;
 inputs -> pad_idx = 0;
 inputs -> next = NULL;
 string filter_desc = filter_description;

 if ((ret = avfilter_graph_parse_ptr(filter_graph, filter_desc.c_str(), &inputs, &outputs, NULL)) < 0) {
 log_averror(ret);
 exit(1);
 }

 if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0) {
 log_averror(ret);
 exit(1);
 }

 /* Print summary of the sink buffer
 * Note: args buffer is reused to store channel layout string */
 AVFilterLink *outlink = buffersink_ctx->inputs[0];
 av_get_channel_layout_string(args, sizeof(args), -1, outlink->channel_layout);
 av_log(NULL, AV_LOG_INFO, "Output: srate:%dHz fmt:%s chlayout:%s\n",
 (int) outlink->sample_rate,
 (char *) av_x_if_null(av_get_sample_fmt_name((AVSampleFormat) outlink->format), "?"),
 args);
 return 0;
 }

 /*
 *
 */
 int main(int argc, char **argv)
 {
 int ret;
 cout << "Hello World" << endl;
 printf("abcd");
 avcodec_register_all();
 av_register_all();
 avfilter_register_all();

 /* open input file, and allocate format context */
 if (avformat_open_input(&in_fmt_ctx, inFileName.c_str(), NULL, NULL) < 0) {
 std::cout << "error opening input file - " << inFileName << std::endl;
 return -1;
 }

 /* retrieve stream information */
 if (avformat_find_stream_info(in_fmt_ctx, NULL) < 0) {
 std::cerr << "Could not find stream information in the input file " << inFileName << std::endl;
 }

 /* Dump format details */
 printf("\n ---------------------------------------------------------------------- \n");
 av_dump_format(in_fmt_ctx, 0, inFileName.c_str(), 0);
 printf("\n ---------------------------------------------------------------------- \n");
 /* Choose a audio stream */
 select_stream = av_find_best_stream(in_fmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, &dec_codec, 0);

 if (select_stream == AVERROR_STREAM_NOT_FOUND) {
 std::cerr << "No audio stream found" << std::endl;
 return -1;
 }

 if (select_stream == AVERROR_DECODER_NOT_FOUND) {
 std::cerr << "No suitable decoder found" << std::endl;
 return -1;
 }

 dec_ctx = in_fmt_ctx -> streams[ select_stream] -> codec;
 av_opt_set_int(dec_ctx, "refcounted_frames", 1, 0);

 /* init the audio decoder */
 if ((ret = avcodec_open2(dec_ctx, dec_codec, NULL)) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot open audio decoder\n");
 return ret;
 }

 /* allocate output context */
 ret = avformat_alloc_output_context2(&out_fmt_ctx, NULL, NULL,
 outFileName.c_str());

 if (ret < 0) {
 std::cerr << "Could not create output context for the file " << outFileName << std::endl;
 return -1;
 }

 /* find the encoder */
 enum AVCodecID codec_id = out_fmt_ctx -> oformat -> audio_codec;
 enc_codec = avcodec_find_encoder(codec_id);

 if (!(enc_codec)) {
 std::cerr << "Could not find encoder for - " << avcodec_get_name(codec_id) << std::endl;
 return -1;
 }

 /* add a new stream */
 audio_st = avformat_new_stream(out_fmt_ctx, enc_codec);

 if (!audio_st) {
 std::cerr << "Could not add audio stream - " << std::endl;
 }

 /* Initialise audio codec */
 audio_st -> id = out_fmt_ctx -> nb_streams - 1;
 enc_ctx = audio_st -> codec;
 enc_ctx -> codec_id = codec_id;
 enc_ctx -> codec_type = AVMEDIA_TYPE_AUDIO;
 enc_ctx -> bit_rate = target_bit_rate;
 enc_ctx -> sample_rate = sample_rate;
 enc_ctx -> sample_fmt = sample_fmt;
 enc_ctx -> channels = channels;
 enc_ctx -> channel_layout = av_get_default_channel_layout(enc_ctx -> channels);

 /* Some formats want stream headers to be separate. */
 if (out_fmt_ctx -> oformat -> flags & AVFMT_GLOBALHEADER) {
 enc_ctx -> flags |= CODEC_FLAG_GLOBAL_HEADER;
 }

 ret = avcodec_open2(out_fmt_ctx -> streams[0] -> codec, enc_codec, NULL);

 if (ret < 0) {
 std::cerr << "Could not create codec context for the file " << outFileName << std::endl;
 return -1;
 }

 /* Initialize filter */
 initialize_audio_filter();

 if (!(out_fmt_ctx -> oformat -> flags & AVFMT_NOFILE)) {
 int ret = avio_open(& out_fmt_ctx -> pb, outFileName.c_str(),
 AVIO_FLAG_WRITE);

 if (ret < 0) {
 log_averror(ret);
 return -1;
 }
 }

 /* Write header */
 if (avformat_write_header(out_fmt_ctx, NULL) < 0) {
 if (ret < 0) {
 log_averror(ret);
 return -1;
 }
 }

 /* Allocate frame */
 pFrame = av_frame_alloc();

 if (!pFrame) {
 std::cerr << "Could not allocate frame\n";
 return -1;
 }

 pFrameFiltered = av_frame_alloc();

 if (!pFrameFiltered) {
 std::cerr << "Could not allocate frame\n";
 return -1;
 }

 av_init_packet(&packet);
 packet.data = NULL;
 packet.size = 0;

 /* Read packet from the stream */
 while (av_read_frame(in_fmt_ctx, &packet) >= 0) {
 if (packet.stream_index == select_stream) {
 avcodec_get_frame_defaults(pFrame);
 ret = avcodec_decode_audio4(dec_ctx, pFrame, &got_frame, &packet);

 if (ret < 0) {
 log_averror(ret);
 return ret;
 }

 printf("Decoded packet pts : %ld ", packet.pts);
 printf("Frame Best Effor pts : %ld \n", pFrame->best_effort_timestamp);
 /* Set frame pts */
 pFrame -> pts = av_frame_get_best_effort_timestamp(pFrame);

 if (got_frame) {
 /* push the decoded frame into the filtergraph */
 ret = av_buffersrc_add_frame_flags(buffersrc_ctx, pFrame, AV_BUFFERSRC_FLAG_KEEP_REF);

 if (ret < 0) {
 log_averror(ret);
 return ret;
 }

 /* pull filtered frames from the filtergraph */
 while (1) {
 ret = av_buffersink_get_frame(buffersink_ctx, pFrameFiltered);

 if ((ret == AVERROR(EAGAIN)) || (ret == AVERROR_EOF)) {
 break;
 }

 if (ret < 0) {
 printf("Error while getting filtered frames from filtergraph\n");
 log_averror(ret);
 return -1;
 }

 /* Initialize the packets */
 AVPacket encodedPacket = {0};
 av_init_packet(&encodedPacket);
 ret = avcodec_encode_audio2(out_fmt_ctx -> streams[0] -> codec, &encodedPacket, pFrameFiltered, &got_packet);

 if (!ret && got_packet && encodedPacket.size) {
 /* Set correct pts and dts */
 if (encodedPacket.pts != AV_NOPTS_VALUE) {
 encodedPacket.pts = av_rescale_q(encodedPacket.pts, buffersink_ctx -> inputs[0] -> time_base,
 out_fmt_ctx -> streams[0] -> time_base);
 }

 if (encodedPacket.dts != AV_NOPTS_VALUE) {
 encodedPacket.dts = av_rescale_q(encodedPacket.dts, buffersink_ctx -> inputs[0] -> time_base,
 out_fmt_ctx -> streams[0] -> time_base);
 }

 printf("Encoded packet pts %ld\n", encodedPacket.pts);
 /* Write the compressed frame to the media file. */
 ret = av_interleaved_write_frame(out_fmt_ctx, &encodedPacket);

 if (ret < 0) {
 log_averror(ret);
 return -1;
 }
 } else if (ret < 0) {
 log_averror(ret);
 return -1;
 }

 av_frame_unref(pFrameFiltered);
 }

 av_frame_unref(pFrame);
 }
 }
 }

 /* Flush delayed frames from encoder*/
 got_packet=1;
 while (got_packet) {
 AVPacket encodedPacket = {0};
 av_init_packet(&encodedPacket);
 ret = avcodec_encode_audio2(out_fmt_ctx -> streams[0] -> codec, &encodedPacket, NULL, &got_packet);

 if (!ret && got_packet && encodedPacket.size) {
 /* Set correct pts and dts */
 if (encodedPacket.pts != AV_NOPTS_VALUE) {
 encodedPacket.pts = av_rescale_q(encodedPacket.pts, buffersink_ctx -> inputs[0] -> time_base,
 out_fmt_ctx -> streams[0] -> time_base);
 }

 if (encodedPacket.dts != AV_NOPTS_VALUE) {
 encodedPacket.dts = av_rescale_q(encodedPacket.dts, buffersink_ctx -> inputs[0] -> time_base,
 out_fmt_ctx -> streams[0] -> time_base);
 }

 printf("Encoded packet pts %ld\n", encodedPacket.pts);
 /* Write the compressed frame to the media file. */
 ret = av_interleaved_write_frame(out_fmt_ctx, &encodedPacket);

 if (ret < 0) {
 log_averror(ret);
 return -1;
 }
 } else if (ret < 0) {
 log_averror(ret);
 return -1;
 }
 }

 /* Write Trailer */
 av_write_trailer(out_fmt_ctx);
 avfilter_graph_free(&filter_graph);

 if (dec_ctx)
 avcodec_close(dec_ctx);

 avformat_close_input(&in_fmt_ctx);
 av_frame_free(&pFrame);
 av_frame_free(&pFrameFiltered);

 if (!(out_fmt_ctx -> oformat -> flags & AVFMT_NOFILE))
 avio_close(out_fmt_ctx -> pb);
 avcodec_close(out_fmt_ctx->streams[0]->codec);
 avformat_free_context(out_fmt_ctx);
 return 0;
 }
</iostream>



The audio file after transcoding is same duration as the input. But its completely noisy. Can somebody tell me what I am doing wrong here !


-
10 Key Google Analytics Limitations You Should Be Aware Of
9 mai 2022, par Erin