Recherche avancée

Médias (91)

Autres articles (103)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

Sur d’autres sites (9700)

  • How to transcode MP3 files in django by using FFMPEG, Celery and RabbitMQ ?

    12 janvier 2017, par Srinivas 25

    I am trying to transcode user uploaded MP3 audio files into ogg, ac3 wav or other formats by using django, celery, rabbitMQ and FFMPEG. But i am getting the error with [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call

    OS-Window 10-64bit
    Python 3.0
    Django - 1.10

    here is the code I followed :

    models.py
    import uuid
    from django.db import models

      # Create your models here.

       def unique_file_path(instance, filename):
       new_file_name = uuid.uuid4()
       return str(new_file_name)

       class AudioFile(models.Model):
       name = models.CharField(max_length=100, blank=True)
       mp3_file = models.FileField(upload_to=unique_file_path)
       ogg_file = models.FileField(blank=True, upload_to=unique_file_path)
       wav_file = models.FileField(blank=True, upload_to=unique_file_path)
       ac3_file = models.FileField(blank=True, upload_to=unique_file_path)

       def __str__(self):
           return self.name

       views.py
       from django.shortcuts import render

       # Create your views here.

       from django.views.generic.edit import FormView
       from django.http import HttpResponseRedirect
       from django.core.urlresolvers import reverse

       from django.views.generic import FormView
       from audio_transcoder.taskapp.tasks import transcode_mp3

       from .forms import AudioFileFrom
       from .models import AudioFile

       class UploadAudioFileView(FormView):
       template_name = 'upload/upload.html'
       form_class = AudioFileFrom


       def form_valid(self, form):
           audio_file = AudioFile(
               name=self.get_form_kwargs().get('data')['name'],
               mp3_file=self.get_form_kwargs().get('files')['mp3_file']
           )
           audio_file.save()
           transcode_mp3.delay(audio_file.id)

           return HttpResponseRedirect(self.get_success_url())

       def get_success_url(self):
           return reverse('/')


       tasks.py
       import os
       import os.path
       import subprocess

       from audio_transcoder.taskapp.celery import app




       from celery import Celery

       app = Celery('fftest',
                broker='amqp://guest@localhost//',
                include=['taskapp.tasks'])

       if __name__ == '__main__':
       app.start()

       from audio_transcoder.models import AudioFile
       import fftest.settings as settings

       @app.task
       def transcode_mp3(mp3_id):
       audio_file = AudioFile.objects.get(id=mp3_id)
       input_file_path = audio_file.mp3_file.path
       filename = os.path.basename(input_file_path)

       ogg_output_file_name = os.path.join('transcoded', '{}.ogg'.format(filename))
       ogg_output_file_path = os.path.join(settings.MEDIA_ROOT, ogg_`enter code    
       here`output_file_name)
       enter code here
       ac3_output_file_name = os.path.join('transcoded', '{}.ac3'.format(filename))
       ac3_output_file_path = os.path.join(settings.MEDIA_ROOT,  
       ac3_output_file_name)

       wav_output_file_name = os.path.join('transcoded', '{}.wav'.format(filename))
       wav_output_file_path = os.path.join(settings.MEDIA_ROOT,
       wav_output_file_name)

       if not os.path.isdir(os.path.dirname(ogg_output_file_path)):
           os.makedirs(os.path.dirname(ogg_output_file_path))

       subprocess.call([
               settings.FFMPEG_PATH,
               '-i',
               input_file_path,
               ogg_output_file_path,
               ac3_output_file_path,
               wav_output_file_path
           ]
       )

       audio_file.ogg_file = ogg_output_file_name
       audio_file.ac3_file = ac3_output_file_name
       audio_file.wav_file = wav_output_file_name
       audio_file.save()

    Not sure where the mistake is happening. While uploading video it is showing below :

    OperationalError at /new/
    [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
    Request Method: POST
    Request URL:  http://127.0.0.1:8000/new/
    Django Version: 1.10.4
    Exception Type: OperationalError`enter code here`
    Exception Value:  
    [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
    Exception Location: C:\Users\RAMa2r3e4s5h6\fftest\lib\site-packages\amqp\transport.py in _set_socket_options, line 204
  • FFMpeg C# wrapper "MediaToolkit 1.0.4.11". How can I do a conversion in memory ?

    8 décembre 2016, par Quantum_Kernel

    I am currently using the MediaToolkit 1.0.4.11 C# wrapper for FFMPEG to extract wav audio from a range of video files.

    Instead of creating a wav file on disk, I would like to create it in memory (as a MemoryStream). This will save me from creating temp files which I need to delete and should speed up the various analyses that I am doing on the audio data.

    Because of the way the call to the library works, I’m not sure how to ’trick’ it into doing this. Is there a way to do it or will I have to obtain and edit the wrapper source code ?

    Here is what I have for doing the conversion on disk :

    var inputFile = new MediaToolkit.Model.MediaFile { Filename = mediaFilePath };
               var outputFile = new MediaToolkit.Model.MediaFile { Filename = @"C:\Temp\audio.wav" };

               var conversionOptions = new MediaToolkit.Options.ConversionOptions
               {
                   MaxVideoDuration = TimeSpan.FromSeconds(30),
                   VideoAspectRatio = MediaToolkit.Options.VideoAspectRatio.R16_9,
                   VideoSize = MediaToolkit.Options.VideoSize.Hd1080,
                   AudioSampleRate = MediaToolkit.Options.AudioSampleRate.Hz48000
               };

               using (var engine = new Engine())
               {
                   engine.Convert(inputFile, outputFile, conversionOptions);
               }
  • FFMPEG RTSP stream to MPEG4/H264 file using libx264

    4 décembre 2016, par Phi

    Heyo folks,

    I’m attempting to transcode/remux an RTSP stream in H264 format into a MPEG4 container, containing just the H264 video stream. Basically, webcam output into a MP4 container.

    I can get a poorly coded MP4 produced, using this code :

    // Variables here for demo
    AVFormatContext * video_file_output_format = nullptr;
    AVFormatContext * rtsp_format_context = nullptr;
    AVCodecContext * video_file_codec_context = nullptr;
    AVCodecContext * rtsp_vidstream_codec_context = nullptr;
    AVPacket packet = {0};
    AVStream * video_file_stream = nullptr;
    AVCodec * rtsp_decoder_codec = nullptr;
    int errorNum = 0, video_stream_index = 0;
    std::string outputMP4file = "D:\\somemp4file.mp4";

    // begin
    AVDictionary * opts = nullptr;
    av_dict_set(&opts, "rtsp_transport", "tcp", 0);

    if ((errorNum = avformat_open_input(&rtsp_format_context, uriANSI.c_str(), NULL, &opts)) < 0) {
       errOut << "Connection failed: avformat_open_input failed with error " << errorNum << ":\r\n" << ErrorRead(errorNum);
       TacticalAbort();
       return;
    }

    rtsp_format_context->max_analyze_duration = 50000;
    if ((errorNum = avformat_find_stream_info(rtsp_format_context, NULL)) < 0) {
       errOut << "Connection failed: avformat_find_stream_info failed with error " << errorNum << ":\r\n" << ErrorRead(errorNum);
       TacticalAbort();
       return;
    }

    video_stream_index = errorNum = av_find_best_stream(rtsp_format_context, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);

    if (video_stream_index < 0) {
       errOut << "Connection in unexpected state; made a connection, but there was no video stream.\r\n"
           "Attempts to find a video stream resulted in error " << errorNum << ": " << ErrorRead(errorNum);
       TacticalAbort();
       return;
    }

    rtsp_vidstream_codec_context = rtsp_format_context->streams[video_stream_index]->codec;

    av_init_packet(&packet);

    if (!(video_file_output_format = av_guess_format(NULL, outputMP4file.c_str(),  NULL))) {
       TacticalAbort();
       throw std::exception("av_guess_format");
    }

    if (!(rtsp_decoder_codec = avcodec_find_decoder(rtsp_vidstream_codec_context->codec_id))) {
       errOut << "Connection failed: connected, but avcodec_find_decoder returned null.\r\n"
           "Couldn't find codec with an AV_CODEC_ID value of " << rtsp_vidstream_codec_context->codec_id << ".";
       TacticalAbort();
       return;
    }

    video_file_format_context = avformat_alloc_context();
    video_file_format_context->oformat = video_file_output_format;

    if (strcpy_s(video_file_format_context->filename, sizeof(video_file_format_context->filename), outputMP4file.c_str())) {
       errOut << "Couldn't open video file: strcpy_s failed with error " << errno << ".";
       std::string log = errOut.str();
       TacticalAbort();
       throw std::exception("strcpy_s");
    }

    if (!(video_file_encoder_codec = avcodec_find_encoder(video_file_output_format->video_codec))) {
       TacticalAbort();
       throw std::exception("avcodec_find_encoder");
    }

    // MARKER ONE

    if (!outputMP4file.empty() &&
       !(video_file_output_format->flags & AVFMT_NOFILE) &&
       (errorNum = avio_open2(&video_file_format_context->pb, outputMP4file.c_str(), AVIO_FLAG_WRITE, nullptr, &opts)) < 0) {
       errOut << "Couldn't open video file \"" << outputMP4file << "\" for writing : avio_open2 failed with error " << errorNum << ": " << ErrorRead(errorNum);
       TacticalAbort();
       return;
    }

    // Create stream in MP4 file
    if (!(video_file_stream = avformat_new_stream(video_file_format_context, video_file_encoder_codec))) {
       TacticalAbort();
       return;
    }

    AVCodecContext * video_file_codec_context = video_file_stream->codec;

    // MARKER TWO

    // error -22/-21 in avio_open2 if this is skipped
    if ((errorNum = avcodec_copy_context(video_file_codec_context, rtsp_vidstream_codec_context)) != 0) {
       TacticalAbort();
       throw std::exception("avcodec_copy_context");
    }

    //video_file_codec_context->codec_tag = 0;

    /*
    // MARKER 3 - is this not needed? Examples suggest not.
    if ((errorNum = avcodec_open2(video_file_codec_context, video_file_encoder_codec, &opts)) < 0)
    {
       errOut << "Couldn't open video file codec context: avcodec_open2 failed with error " << errorNum << ": " << ErrorRead(errorNum);
       std::string log = errOut.str();
       TacticalAbort();
       throw std::exception("avcodec_open2, video file");
    }*/

    //video_file_format_context->flags |= AVFMT_FLAG_GENPTS;
    if (video_file_format_context->oformat->flags & AVFMT_GLOBALHEADER)
    {
       video_file_codec_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
    }

    if ((errorNum = avformat_write_header(video_file_format_context, &opts)) < 0) {
       errOut << "Couldn't open video file: avformat_write_header failed with error " << errorNum << ":\r\n" << ErrorRead(errorNum);
       std::string log = errOut.str();
       TacticalAbort();
       return;
    }

    However, there are several issues :

    1. I can’t pass any x264 options to the output file. The output H264 matches the input H264’s profile/level - switching cameras to a different model switches H264 level.
    2. The timing of the output file is off, noticeably.
    3. The duration of the output file is off, massively. A few seconds of footage becomes hours, although playtime doesn’t match. (FWIW, I’m using VLC to play them.)

    Passing x264 options

    If I manually increment PTS per packet, and set DTS equal to PTS, it plays too fast, 2-3 seconds’ worth of footage in one second playtime, and duration is hours long. The footage also blurs past several seconds, about 10 seconds’ footage in a second.

    If I let FFMPEG decide (with or without GENPTS flag), the file has a variable frame rate (probably as expected), but it plays the whole file in an instant and has a long duration too (over forty hours for a few seconds). The duration isn’t "real", as the file plays in an instant.

    At Marker One, I try to set the profile by passing options to avio_open2. The options are simply ignored by libx264. I’ve tried :

    av_dict_set(&opts, "vprofile", "main", 0);
    av_dict_set(&opts, "profile", "main", 0); // error, missing '('
    // FF_PROFILE_H264_MAIN equals 77, so I also tried
    av_dict_set(&opts, "vprofile", "77", 0);
    av_dict_set(&opts, "profile", "77", 0);

    It does seem to read the profile setting, but it doesn’t use them. At Marker Two, I tried to set it after the avio_open2, before avformat_write_header .

    // I tried all 4 av_dict_set from earlier, passing it to avformat_write_header.
    // None had any effect, they weren't consumed.
    av_opt_set(video_file_codec_context, "profile", "77", 0);
    av_opt_set(video_file_codec_context, "profile", "main", 0);
    video_file_codec_context->profile = FF_PROFILE_H264_MAIN;
    av_opt_set(video_file_codec_context->priv_data, "profile", "77", 0);
    av_opt_set(video_file_codec_context->priv_data, "profile", "main", 0);

    Messing with privdata made the program unstable, but I was trying anything at that point.
    I’d like to solve issue 1 with passing settings, since I imagine it’d bottleneck any attempt to solve issues 2 or 3.

    I’ve been fiddling with this for the better part of a month now. I’ve been through dozens of documentation, Q&As, examples. It doesn’t help that quite a few are outdated.

    Any help would be appreciated.

    Cheers