Recherche avancée

Médias (0)

Mot : - Tags -/xmlrpc

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (52)

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

  • Des sites réalisés avec MediaSPIP

    2 mai 2011, par

    Cette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
    Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

Sur d’autres sites (8382)

  • FFmpeg avcodec C++ implementation producing distorted frames while converting YUV frame to jpg

    23 juin 2023, par CodeRhyno

    I have a YUV frame that I need to convert to jpg. For the frames with resolution 1920x1080 or 2560x1080 or 2560x880 or 640x360, I'm easily able to encode and create a jpg using the following code. The frames with a resolution of 1512x982 with 12 bit per pixel I am getting a distorted image using the same code. Using the following ffmpeg command, I am able to get perfect looking jpg image from the same 1512x982 resolution YUV file :

    


    fmpeg -y -s:v 1512x982 -pix_fmt yuv420p -i 0.yuv 0.jpg


    


    Please help with the code part, as in what I may be missing here.

    


    Distorted jpg

    


    #include "ffmpeg-helper.h"

AVFrame * FFmpegHelper::allocPicture(enum AVPixelFormat pix_fmt, int width, int height)
{
    // Allocate a frame
    AVFrame * frame = av_frame_alloc();

    if (frame == NULL) {
        return NULL;
    }

    frame -> width = width;
    frame -> height = height;
    frame -> format = pix_fmt;
    int ret = av_frame_get_buffer(frame, 0);

    if (ret < 0) {
        return NULL;
    }
    ret = av_frame_make_writable(frame);
    if (ret < 0) {
        return NULL;
    }
    return frame;
}

void FFmpegHelper::frameConversion(char * y, char * u, char * v,
    int srcWidth, int srcHeight, string filePath)
{
    avcodec_register_all();
    AVFrame * src = allocPicture(AVPixelFormat::AV_PIX_FMT_YUV420P, srcWidth, srcHeight);
    src -> data[0] = (uint8_t * ) y;
    src -> data[1] = (uint8_t * ) u;
    src -> data[2] = (uint8_t * ) v;
    src -> pts = 1;

    auto encoderContext = getEncoderContext(AV_CODEC_ID_MJPEG, srcWidth, srcHeight);
    if (encoderContext == NULL) return;

    FILE * frameFile = fopen(filePath.c_str(), "ab+");

    auto pkt = av_packet_alloc();
    encode(encoderContext, src, pkt, frameFile);
    encode(encoderContext, NULL, pkt, frameFile);

    // memory cleanup
    avcodec_free_context( & encoderContext);
    av_packet_unref(pkt);
    av_frame_free( & src);
    fclose(frameFile);
}

void FFmpegHelper::encode(AVCodecContext * enc_ctx, AVFrame * frame, AVPacket * pkt, FILE * outfile)
{
    /* send the frame to the encoder */
    if (frame == NULL) {
        return;
    }
    int ret = avcodec_send_frame(enc_ctx, frame);
    if (ret < 0) {
        return;
    }
    ret = avcodec_receive_packet(enc_ctx, pkt);
    if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) return;
    if (ret < 0) return;
    fwrite(pkt -> data, pkt -> size, 1, outfile);

}

AVCodecContext * FFmpegHelper::getEncoderContext(AVCodecID extension, int width, int height)
{
    auto codec = avcodec_find_encoder(extension);
    if (!codec) {
        return NULL;
    }
    auto encoderContext = avcodec_alloc_context3(codec);
    encoderContext -> width = width;
    encoderContext -> height = height;
    encoderContext -> pix_fmt = AVPixelFormat::AV_PIX_FMT_YUVJ420P;
    AVRational frameRate = {
        1,
        1
    };
    encoderContext -> time_base = frameRate;
    if (avcodec_open2(encoderContext, codec, NULL) < 0) {
        return;
    }

    return encoderContext;
}


    


    The code starts from the function 'frameConversion' where I am providing data for Y, U, and V along with frame dimensions and file path to write.

    


  • FFmpeg : concatenate video files (containing audio) without filter_complex

    28 décembre 2016, par DSalenga

    I have a problem when trying to concatenate multiple files in FFmpeg ; my goal is to create a video presentation by concatenating different types of slides :

    (a) Image slides, which are converted into videos by looping the frame for a while. These type of slides do not have audio, so I add a silent audio track to them :

    ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -loop 1 -i inputFile.png -c:v libx264 -shortest -c:a aac -pix_fmt yuv420p -movflags faststart -profile:v high -r 30 -t 3 -level 4.0 -preset veryfast -crf 23 outputA.mp4

    (b) Video slides, which have an overlaid watermark and last until the video is over. If the file does not contain audio, this is added in the same way as in the previous case :

    -y -i inputFile.mp4 -i Watermark.jpg -filter_complex "[0]scale=1280:720,setsar=sar=1/1[0b]; [1]scale=1280:720[1b]; [0b][1b]overlay=0:0[ov]"  -c:v libx264 -shortest -c:a aac -pix_fmt yuv420p -movflags faststart -profile:v high -r 30 -t 2.8400055 -level 4.0 -preset veryfast -crf 23 outputB.mp4

    -y -i inputFile.mp4 -i Watermark.jpg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -filter_complex "[0]scale=1280:720,setsar=sar=1/1[0b]; [1]scale=1280:720[1b]; [0b][1b]overlay=0:0[ov]"  -c:v libx264 -shortest -c:a aac -pix_fmt yuv420p -movflags faststart -profile:v high -r 30 -t 2.8400055 -level 4.0 -preset veryfast -crf 23 outputC.mp4

    So, once I have all the generated files and a .txt file with all filenames, I want to concatenate using the simple command :

    -y -f concat -safe 0 -i textfile.txt -c copy  outputConcat.mp4

    Unfortunately, the result I obtain is far from perfect, as the audio screw everything up ; I know that audio is the problem because calling the same instruction without taking audio into account (that is, with -c:v copy -an instead of -c copy) works fine.

    One solution I’ve been testing is to use the concat filter inside filter_complex (transcoding both audio and video again), but I am concerned about speed, and this process is slow enough to be discarded.

    -y  -i Slide1.mp4 -i Slide2.mp4 -i Slide3.mp4 -filter_complex " [0:v:0][0:a:0] [1:v:0][1:a:0] [2:v:0][2:a:0] concat=n=3:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -c:a aac -pix_fmt yuv420p -movflags faststart -profile:v high -r 30 -level 4.0 -preset veryfast -crf 23 Report.mp4

    Another idea I had was to : (1) concatenate only audio tracks inside the filter_complex (much faster), (2) concatenate only video without using filter_complex (using a .txt file and -c:v copy -an), (3) add the audio obtained in (1) in the result obtained in (2). However, the duration of the resulting audio obtained in (1) is shorter than duration of the video obtained in (2).
    Knowing that all audio tracks are encoded with aac and have the same sampling frequency, the only parameter that changes from one to another is the number of kb/s.

    Can you please help me finding out a way to concatenate these video slides without having to use filter_complex ?

    Thank you very much !

  • ffmpeg / Audacity channel splitting differences

    14 mars 2018, par Adrian Chromenko

    So I’m working on a speech to text project using Python and Google Cloud Services (for phone calls). The mp3s I receive have one voice playing in the left speaker, the other voice in the right speaker.

    So during testing, I manually split the original mp3 file into two WAV files (one for each channel, converted to mono). I did this splitting through Audacity. The accuracy was about 80-90%, which was perfect for my purposes.

    However, once I tried to automate the splitting using ffmpeg (more specifically : ffmpeg -i input_filename.mp3 -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav), the accuracy dropped drastically.

    I’ve been experimenting for about a week now but I can’t get the accuracy up. For what it’s worth, the audio files sound identical to the human ear. I found that when I increase the volume of the output files, the accuracy gets better, but never as good as when I did the splitting with Audacity.

    I guess what I’m trying to ask is, what does Audacity do differently ?

    here are the sox -n stat results for each file :

    **Split with ffmpeg( 20-30% accuracy) : **

    Samples read:           1690560
    Length (seconds):    211.320000
    Scaled by:         2147483647.0
    Maximum amplitude:     0.433350
    Minimum amplitude:    -0.475739
    Midline amplitude:    -0.021194
    Mean    norm:          0.014808
    Mean    amplitude:    -0.000037
    RMS     amplitude:     0.028947
    Maximum delta:         0.333557
    Minimum delta:         0.000000
    Mean    delta:         0.009001
    RMS     delta:         0.017949
    Rough   frequency:          789
    Volume adjustment:        2.102

    Split with Audacity : (80-90% accuracy)

    Samples read:           1689984
    Length (seconds):    211.248000
    Scaled by:         2147483647.0
    Maximum amplitude:     0.217194
    Minimum amplitude:    -0.238373
    Midline amplitude:    -0.010590
    Mean    norm:          0.007423
    Mean    amplitude:    -0.000018
    RMS     amplitude:     0.014510
    Maximum delta:         0.167175
    Minimum delta:         0.000000
    Mean    delta:         0.004515
    RMS     delta:         0.008998
    Rough   frequency:          789
    Volume adjustment:        4.195

    original mp3 :

    Samples read:           3379968
    Length (seconds):    211.248000
    Scaled by:         2147483647.0
    Maximum amplitude:     1.000000
    Minimum amplitude:    -1.000000
    Midline amplitude:    -0.000000
    Mean    norm:          0.014124
    Mean    amplitude:    -0.000030
    RMS     amplitude:     0.047924
    Maximum delta:         1.015332
    Minimum delta:         0.000000
    Mean    delta:         0.027046
    RMS     delta:         0.067775
    Rough   frequency:         1800
    Volume adjustment:        1.000

    One thing that stands out to me is that the duration isn’t the same. Also the amplitudes. Can I instruct ffmpeg what the duration is when it is doing the splitting ? And can I change all the amplitudes to match the audacity file ? I’m not sure what to do to get to the 80% accuracy rate, but increasing volume seems to be the most promising solution so far.

    Any help would be greatly appreciated. I don’t have to use ffmpeg, but it seems like my only option, as Audacity isn’t scriptable.