Recherche avancée

Médias (1)

Mot : - Tags -/publicité

Autres articles (61)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire 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 (12115)

  • Build FFMPEG with libx264 Android

    4 juin 2015, par Biraj Zalavadia

    I was able to Build FFMPEG with libx264 Android successfully and was working well before 2 months.

    I uses halfninja for building.

    Today I take latest source of ffmpeg and libX264 from here.

    git clone git://git.videolan.org/x264.git

    git clone git://git.videolan.org/ffmpeg.git

    And try to rebuild whole project. But now it throws following errors.

    ffmpeg.c:2406: error: undefined reference to 'hwaccels'
    ffmpeg.c:3390: error: undefined reference to 'qp_hist'
    ffmpeg.c:3390: error: undefined reference to 'do_hex_dump'
    ffmpeg.c:3390: error: undefined reference to 'do_pkt_dump'
    ffmpeg.c:576: error: undefined reference to 'do_benchmark_all'
    ffmpeg.c:657: error: undefined reference to 'audio_sync_method'
    ffmpeg.c:1222: error: undefined reference to 'vstats_filename'
    ffmpeg.c:972: error: undefined reference to 'frame_drop_threshold'
    ffmpeg.c:1181: error: undefined reference to 'debug_ts'
    ffmpeg.c:2742: error: undefined reference to 'copy_tb'
    ffmpeg.c:2846: error: undefined reference to 'audio_volume'
    ffmpeg.c:2862: error: undefined reference to 'init_simple_filtergraph'
    ffmpeg.c:2863: error: undefined reference to 'configure_filtergraph'
    ffmpeg.c:2923: error: undefined reference to 'video_sync_method'
    ffmpeg.c:2538: error: undefined reference to 'frame_bits_per_raw_sample'
    ffmpeg.c:3258: error: undefined reference to 'sdp_filename'
    ffmpeg.c:2087: error: undefined reference to 'ist_in_filtergraph'
    ffmpeg.c:4069: error: undefined reference to 'ffmpeg_parse_options'
    ffmpeg.c:4074: error: undefined reference to 'show_usage'
    ffmpeg.c:3303: error: undefined reference to 'options'
    ffmpeg.c:3303: error: undefined reference to 'stdin_interaction'
    ffmpeg.c:2553: error: undefined reference to 'exit_on_error'
    ffmpeg.c:2553: error: undefined reference to 'do_pkt_dump'
    ffmpeg.c:2553: error: undefined reference to 'do_hex_dump'
    ffmpeg.c:3727: error: undefined reference to 'copy_ts'
    ffmpeg.c:3727: error: undefined reference to 'dts_delta_threshold'
    ffmpeg.c:268: error: undefined reference to 'dts_error_threshold'
    ffmpeg.c:3976: error: undefined reference to 'print_stats'
    ffmpeg.c:1694: error: undefined reference to 'do_benchmark'
    ffmpeg.c:1694: error: undefined reference to 'max_error_rate'

    Please help me out to resolve this.

    Please look at my script.

    build_android.sh

    #!/bin/bash
    #
    # build_android.sh
    # Copyright (c) 2012 Jacek Marchwicki
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.

    export NDK=/home/tasol/DEVELOPMENT/IJOOMER_DEVELOPMENT/NDK/android-ndk-r10d

    if [ "$NDK" = "" ]; then
       echo NDK variable not set, exiting
       echo "Use: export NDK=/your/path/to/android-ndk"
       exit 1
    fi

    OS=`uname -s | tr '[A-Z]' '[a-z]'`
    function build_x264
    {
       PLATFORM=$NDK/platforms/$PLATFORM_VERSION/arch-$ARCH/
       export PATH=${PATH}:$PREBUILT/bin/
       CROSS_COMPILE=$PREBUILT/bin/$EABIARCH-
       CFLAGS=$OPTIMIZE_CFLAGS
    #CFLAGS=" -I$ARM_INC -fpic -DANDROID -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID  -Wa,--noexecstack -MMD -MP "
       export CPPFLAGS="$CFLAGS"
       export CFLAGS="$CFLAGS"
       export CXXFLAGS="$CFLAGS"
       export CXX="${CROSS_COMPILE}g++ --sysroot=$PLATFORM"
       export AS="${CROSS_COMPILE}gcc --sysroot=$PLATFORM"
       export CC="${CROSS_COMPILE}gcc --sysroot=$PLATFORM"
       export NM="${CROSS_COMPILE}nm"
       export STRIP="${CROSS_COMPILE}strip"
       export RANLIB="${CROSS_COMPILE}ranlib"
       export AR="${CROSS_COMPILE}ar"
       #export LDFLAGS="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog"

       cd x264
       ./configure --disable-asm --prefix=$(pwd)/$PREFIX --host=$ARCH-linux --enable-static $ADDITIONAL_CONFIGURE_FLAG || exit 1

       make clean || exit 1
       make -j4 install || exit 1
       cd ..
    }

    function build_ffmpeg
    {
       PLATFORM=$NDK/platforms/$PLATFORM_VERSION/arch-$ARCH/
       CC=$PREBUILT/bin/$EABIARCH-gcc
       CROSS_PREFIX=$PREBUILT/bin/$EABIARCH-
       PKG_CONFIG=${CROSS_PREFIX}pkg-config
       if [ ! -f $PKG_CONFIG ];
       then
           cat > $PKG_CONFIG << EOF
    #!/bin/bash
    pkg-config \$*
    EOF
           chmod u+x $PKG_CONFIG
       fi
       NM=$PREBUILT/bin/$EABIARCH-nm
       cd ffmpeg
       export PKG_CONFIG_LIBDIR=$(pwd)/$PREFIX/lib/pkgconfig/
       export PKG_CONFIG_PATH=$(pwd)/$PREFIX/lib/pkgconfig/
       ./configure --target-os=linux \
           --prefix=$PREFIX \
           --enable-cross-compile \
           --extra-libs="-lgcc" \
           --arch=$ARCH \
           --cc=$CC \
           --cross-prefix=$CROSS_PREFIX \
           --nm=$NM \
           --sysroot=$PLATFORM \
           --extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums  -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS " \
           --disable-shared \
           --disable-stripping \
           --enable-static \
           --enable-runtime-cpudetect \
           --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -nostdlib -lc -lm -ldl -llog -L$PREFIX/lib" \
           --extra-cflags="-I$PREFIX/include" \
               --enable-gpl \
           --enable-encoder=libx264 \
           --enable-libx264 \
           --enable-parser=mjpeg \
           --enable-demuxer=image2 \
           --enable-hwaccel=h264_vaapi \
           --enable-hwaccel=h264_vaapi \
           --enable-hwaccel=h264_dxva2 \
           --enable-hwaccel=mpeg4_vaapi \
           --enable-demuxer=mov \
           --enable-demuxer=h264 \
           --enable-demuxer=mpegvideo \
           --enable-demuxer=h263 \
           --enable-demuxer=mpegps \
           --enable-demuxer=mjpeg \
           --enable-demuxer=rtsp \
           --enable-demuxer=rtp \
           --enable-demuxer=hls \
           --enable-demuxer=matroska \
           --enable-muxer=rtsp \
           --enable-muxer=mp4 \
           --enable-muxer=mov \
           --enable-muxer=mjpeg \
           --enable-muxer=matroska \
           --enable-protocol=crypto \
           --enable-protocol=jni \
           --enable-protocol=file \
           --disable-network \
               --enable-filter=buffer \
           --enable-filter=buffersink \
           --enable-filter=scale \
           --enable-protocol=rtp \
           --enable-protocol=tcp \
           --enable-protocol=udp \
           --enable-protocol=applehttp \
           --enable-protocol=hls \
           --enable-protocol=http \
           --enable-decoder=xsub \
           --enable-decoder=jacosub \
           --enable-decoder=dvdsub \
           --enable-decoder=dvbsub \
           --enable-decoder=subviewer \
           --enable-decoder=rawvideo \
           --enable-encoder=rawvideo \
           --enable-decoder=mjpeg \
           --enable-encoder=mjpeg \
           --enable-decoder=h263 \
           --enable-decoder=mpeg4 \
           --enable-encoder=mpeg4 \
           --enable-decoder=h264 \
           --enable-encoder=h264 \
           --enable-decoder=aac \
           --enable-encoder=aac \
           --enable-parser=h264 \
           --enable-encoder=mp2 \
           --enable-decoder=mp2 \
           --enable-encoder=libvo_amrwbenc \
           --enable-decoder=amrwb \
           --enable-muxer=mp2 \
           --enable-bsfs \
           --enable-decoders \
           --enable-encoders \
           --enable-parsers \
           --enable-hwaccels \
           --enable-muxers \
           --enable-avformat \
           --enable-avcodec \
           --disable-demuxer=v4l \
           --disable-demuxer=v4l2 \
           --disable-indev=v4l \
           --disable-indev=v4l2 \
           --disable-ffplay \
           --disable-ffmpeg \
           --disable-ffplay \
           --disable-ffprobe \
           --disable-ffserver \
           --enable-nonfree \
           --enable-version3 \
           --enable-memalign-hack \
           --disable-asm \
           $ADDITIONAL_CONFIGURE_FLAG \
           || exit 1
       make clean || exit 1
       make -j4 install || exit 1

       cd ..
    }

    function build_one {
       cd ffmpeg
       cd ..
    }

    #arm v5
    EABIARCH=arm-linux-androideabi
    ARCH=arm
    CPU=armv5
    OPTIMIZE_CFLAGS="-marm -march=$CPU"
    PREFIX=../ffmpeg-build/armeabi
    OUT_LIBRARY=$PREFIX/libffmpeg.so
    ADDITIONAL_CONFIGURE_FLAG=
    SONAME=libffmpeg.so
    PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/$OS-x86_64
    #PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/$OS-x86
    PLATFORM_VERSION=android-5
    build_x264
    build_ffmpeg
    build_one


    #arm v7vfpv3
    #EABIARCH=arm-linux-androideabi
    #ARCH=arm
    #CPU=armv7-a
    #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
    #PREFIX=../ffmpeg-build/armeabi-v7a
    #OUT_LIBRARY=$PREFIX/libffmpeg.so
    #ADDITIONAL_CONFIGURE_FLAG=
    #SONAME=libffmpeg.so
    #PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/$OS-x86_64
    #PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/$OS-x86
    #PLATFORM_VERSION=android-5
    #build_x264
    #build_ffmpeg
    #build_one

    #arm v7 + neon (neon also include vfpv3-32)
    EABIARCH=arm-linux-androideabi
    ARCH=arm
    CPU=armv7-a
    OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8 -mthumb -D__thumb__ "
    PREFIX=../ffmpeg-build/armeabi-v7a
    #PREFIX=../ffmpeg-build/armeabi-v7a-neon
    OUT_LIBRARY=../ffmpeg-build/armeabi-v7a/libffmpeg-neon.so
    ADDITIONAL_CONFIGURE_FLAG=--enable-neon
    SONAME=libffmpeg-neon.so
    PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/$OS-x86_64
    #PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/$OS-x86
    PLATFORM_VERSION=android-9
    build_x264
    build_ffmpeg
    build_one

    #x86
    EABIARCH=i686-linux-android
    ARCH=x86
    OPTIMIZE_CFLAGS="-m32"
    PREFIX=../ffmpeg-build/x86
    OUT_LIBRARY=$PREFIX/libffmpeg.so
    ADDITIONAL_CONFIGURE_FLAG=--disable-asm
    SONAME=libffmpeg.so
    PREBUILT=$NDK/toolchains/x86-4.8/prebuilt/$OS-x86_64
    #PREBUILT=$NDK/toolchains/x86-4.6/prebuilt/$OS-x86
    PLATFORM_VERSION=android-9
    build_x264
    build_ffmpeg
    build_one

    #mips
    EABIARCH=mipsel-linux-android
    ARCH=mips
    OPTIMIZE_CFLAGS="-EL -march=mips32 -mips32 -mhard-float"
    PREFIX=../ffmpeg-build/mips
    OUT_LIBRARY=$PREFIX/libffmpeg.so
    ADDITIONAL_CONFIGURE_FLAG=""
    SONAME=libffmpeg.so
    PREBUILT=$NDK/toolchains/mipsel-linux-android-4.8/prebuilt/$OS-x86_64
    #PREBUILT=$NDK/toolchains/mipsel-linux-android-4.6/prebuilt/$OS-x86
    PLATFORM_VERSION=android-9
    build_x264
    build_ffmpeg
    build_one

    build_all.sh

    #!/bin/bash
    #
    # build_all.sh

    export NDK=/home/tasol/DEVELOPMENT/IJOOMER_DEVELOPMENT/NDK/android-ndk-r10d
    sudo ./build_android.sh
    $NDK/ndk-build

    echo "Done Dona Done!!!"

    Android.mk

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)
    LOCAL_MODULE  := videokit
    # These need to be in the right order
    FFMPEG_LIBS := $(addprefix ffmpeg-build/$(TARGET_ARCH_ABI)/lib/, \
    libavdevice.a \
    libavformat.a \
    libavfilter.a \
    libavcodec.a \
    libswscale.a \
    libavutil.a \
    libswresample.a \
    libpostproc.a )
    # ffmpeg uses its own deprecated functions liberally, so turn off that annoying noise
    LOCAL_CFLAGS += -g -Iffmpeg -Ivideokit -Wno-deprecated-declarations
    LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) ffmpeg-build/$(TARGET_ARCH_ABI)/lib/libx264.a
    LOCAL_SRC_FILES := videokit/uk_co_halfninja_videokit_Videokit.c videokit/ffmpeg.c videokit/cmdutils.c
    include $(BUILD_SHARED_LIBRARY)


    include $(CLEAR_VARS)
    LOCAL_MODULE  := ffmpeg
    FFMPEG_LIBS := $(addprefix ffmpeg-build/$(TARGET_ARCH_ABI)/lib/, \
    libavdevice.a \
    libavformat.a \
    libavfilter.a \
    libavcodec.a \
    libswscale.a \
    libavutil.a \
    libswresample.a \
    libpostproc.a )
    LOCAL_CFLAGS += -g -Iffmpeg -Ivideokit -Wno-deprecated-declarations
    LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) ffmpeg-build/$(TARGET_ARCH_ABI)/lib/libx264.a
    LOCAL_SRC_FILES := ffmpeg/ffmpeg.c ffmpeg/cmdutils.c
    include $(BUILD_EXECUTABLE)

    Application.mk

    APP_ABI := armeabi,armeabi-v7a,x86,mips
    APP_PLATFORM := android-10
    APP_STL := gnustl_static
  • How to convert same audio twice using libswresamples's swr_convert

    25 juillet 2019, par JoshuaCWebDeveloper

    I’m working on an audio processing system that sometimes requires that the same audio be resampled twice. The first resampling of the audio from FFmpeg works fine, the second results in distorted audio. I’ve reproduced this problem by modifying the resampling_audio example provided by FFmpeg. How do I convert the same audio twice using swr_convert ?

    Below I’ve attached a modified version of the resampling_audio example. In order to reproduce the issue, follow these steps :

    1. Clone FFmepg project at https://github.com/FFmpeg/FFmpeg
    2. Run ./configure
    3. Run make -j4 examples (this will take awhile the first time)
    4. Run doc/examples/resampling_audio to produce expected output
    5. Replace doc/examples/resampling_audio.c with the version I’ve attached below
    6. Run make -j4 examples
    7. Run doc/examples/resampling_audio again (with new args) to output two new files (one for each conversion).
    8. Import each file into Audacity as raw data, the first file should be 44100 Hz, the second should be 32000 Hz.
    9. The first file will sound the same as the original, the second file will be distorted.

    The environment I ran this in was Ubuntu 16.04 ; I then copied the output files to a Windows PC to open them in Audacity.

    Here is my modified resampling_audio.c file. I’ve created some new variables and copied the blocks of code that do the conversion. The first conversion should be unchanged, the second conversion takes in data from the first conversion and attempts to convert it again.

    /*
    * Copyright (c) 2012 Stefano Sabatini
    *
    * Permission is hereby granted, free of charge, to any person obtaining a copy
    * of this software and associated documentation files (the "Software"), to deal
    * in the Software without restriction, including without limitation the rights
    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    * copies of the Software, and to permit persons to whom the Software is
    * furnished to do so, subject to the following conditions:
    *
    * The above copyright notice and this permission notice shall be included in
    * all copies or substantial portions of the Software.
    *
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    * THE SOFTWARE.
    */

    /**
    * @example resampling_audio.c
    * libswresample API use example.
    */

    #include <libavutil></libavutil>opt.h>
    #include <libavutil></libavutil>channel_layout.h>
    #include <libavutil></libavutil>samplefmt.h>
    #include <libswresample></libswresample>swresample.h>

    static int get_format_from_sample_fmt(const char **fmt,
                                         enum AVSampleFormat sample_fmt)
    {
       int i;
       struct sample_fmt_entry {
           enum AVSampleFormat sample_fmt; const char *fmt_be, *fmt_le;
       } sample_fmt_entries[] = {
           { AV_SAMPLE_FMT_U8,  "u8",    "u8"    },
           { AV_SAMPLE_FMT_S16, "s16be", "s16le" },
           { AV_SAMPLE_FMT_S32, "s32be", "s32le" },
           { AV_SAMPLE_FMT_FLT, "f32be", "f32le" },
           { AV_SAMPLE_FMT_DBL, "f64be", "f64le" },
       };
       *fmt = NULL;

       for (i = 0; i &lt; FF_ARRAY_ELEMS(sample_fmt_entries); i++) {
           struct sample_fmt_entry *entry = &amp;sample_fmt_entries[i];
           if (sample_fmt == entry->sample_fmt) {
               *fmt = AV_NE(entry->fmt_be, entry->fmt_le);
               return 0;
           }
       }

       fprintf(stderr,
               "Sample format %s not supported as output format\n",
               av_get_sample_fmt_name(sample_fmt));
       return AVERROR(EINVAL);
    }

    /**
    * Fill dst buffer with nb_samples, generated starting from t.
    */
    static void fill_samples(double *dst, int nb_samples, int nb_channels, int sample_rate, double *t)
    {
       int i, j;
       double tincr = 1.0 / sample_rate, *dstp = dst;
       const double c = 2 * M_PI * 440.0;

       /* generate sin tone with 440Hz frequency and duplicated channels */
       for (i = 0; i &lt; nb_samples; i++) {
           *dstp = sin(c * *t);
           for (j = 1; j &lt; nb_channels; j++)
               dstp[j] = dstp[0];
           dstp += nb_channels;
           *t += tincr;
       }
    }

    int main(int argc, char **argv)
    {
       int64_t src_ch_layout = AV_CH_LAYOUT_STEREO, dst_ch_layout = AV_CH_LAYOUT_SURROUND;
       int src_rate = 48000, dst_rate = 44100;
       uint8_t **src_data = NULL, **dst_data = NULL, **dst_data2 = NULL;
       int src_nb_channels = 0, dst_nb_channels = 0;
       int src_linesize, dst_linesize;
       int src_nb_samples = 1024, dst_nb_samples, max_dst_nb_samples, dst_nb_samples2, max_dst_nb_samples2;
       enum AVSampleFormat src_sample_fmt = AV_SAMPLE_FMT_DBL, dst_sample_fmt = AV_SAMPLE_FMT_S16;
       const char *dst_filename = NULL, *dst_filename2 = NULL;
       FILE *dst_file, *dst_file2;
       int dst_bufsize, dst_bufsize2;
       const char *fmt;
       struct SwrContext *swr_ctx;
       struct SwrContext *swr_ctx2;
       double t;
       int ret;

       if (argc != 3) {
           fprintf(stderr, "Usage: %s output_file_first output_file_second\n"
                   "API example program to show how to resample an audio stream with libswresample.\n"
                   "This program generates a series of audio frames, resamples them to a specified "
                   "output format and rate and saves them to an output file named output_file.\n",
               argv[0]);
           exit(1);
       }
       dst_filename = argv[1];
       dst_filename2 = argv[2];

       dst_file = fopen(dst_filename, "wb");
       if (!dst_file) {
           fprintf(stderr, "Could not open destination file %s\n", dst_filename);
           exit(1);
       }



       dst_file2 = fopen(dst_filename2, "wb");
       if (!dst_file2) {
           fprintf(stderr, "Could not open destination file 2 %s\n", dst_filename2);
           exit(1);
       }



       /* create resampler context */
       swr_ctx = swr_alloc();
       if (!swr_ctx) {
           fprintf(stderr, "Could not allocate resampler context\n");
           ret = AVERROR(ENOMEM);
           goto end;
       }

       /* set options */
       av_opt_set_int(swr_ctx, "in_channel_layout",    src_ch_layout, 0);
       av_opt_set_int(swr_ctx, "in_sample_rate",       src_rate, 0);
       av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", src_sample_fmt, 0);

       av_opt_set_int(swr_ctx, "out_channel_layout",    dst_ch_layout, 0);
       av_opt_set_int(swr_ctx, "out_sample_rate",       dst_rate, 0);
       av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", dst_sample_fmt, 0);

       /* initialize the resampling context */
       if ((ret = swr_init(swr_ctx)) &lt; 0) {
           fprintf(stderr, "Failed to initialize the resampling context\n");
           goto end;
       }


       /* create resampler context 2 */
       swr_ctx2 = swr_alloc();
       if (!swr_ctx2) {
           fprintf(stderr, "Could not allocate resampler context 2\n");
           ret = AVERROR(ENOMEM);
           goto end;
       }

       /* set options */
       av_opt_set_int(swr_ctx2, "in_channel_layout",    dst_ch_layout, 0);
       av_opt_set_int(swr_ctx2, "in_sample_rate",       dst_rate, 0);
       av_opt_set_sample_fmt(swr_ctx2, "in_sample_fmt", dst_sample_fmt, 0);

       av_opt_set_int(swr_ctx2, "out_channel_layout",    dst_ch_layout, 0);
       av_opt_set_int(swr_ctx2, "out_sample_rate",       32000, 0);
       av_opt_set_sample_fmt(swr_ctx2, "out_sample_fmt", dst_sample_fmt, 0);

       /* initialize the resampling context */
       if ((ret = swr_init(swr_ctx2)) &lt; 0) {
           fprintf(stderr, "Failed to initialize the resampling context 2\n");
           goto end;
       }

       /* allocate source and destination samples buffers */

       src_nb_channels = av_get_channel_layout_nb_channels(src_ch_layout);
       ret = av_samples_alloc_array_and_samples(&amp;src_data, &amp;src_linesize, src_nb_channels,
                                                src_nb_samples, src_sample_fmt, 0);
       if (ret &lt; 0) {
           fprintf(stderr, "Could not allocate source samples\n");
           goto end;
       }

       /* compute the number of converted samples: buffering is avoided
        * ensuring that the output buffer will contain at least all the
        * converted input samples */
       max_dst_nb_samples = dst_nb_samples =
           av_rescale_rnd(src_nb_samples, dst_rate, src_rate, AV_ROUND_UP);

       /* buffer is going to be directly written to a rawaudio file, no alignment */
       dst_nb_channels = av_get_channel_layout_nb_channels(dst_ch_layout);
       ret = av_samples_alloc_array_and_samples(&amp;dst_data, &amp;dst_linesize, dst_nb_channels,
                                                dst_nb_samples, dst_sample_fmt, 0);
       if (ret &lt; 0) {
           fprintf(stderr, "Could not allocate destination samples\n");
           goto end;
       }


       /* compute the number of converted samples: buffering is avoided
        * ensuring that the output buffer will contain at least all the
        * converted input samples */
       max_dst_nb_samples2 = dst_nb_samples2 =
           av_rescale_rnd(dst_nb_samples, 32000, dst_rate, AV_ROUND_UP);

       /* buffer is going to be directly written to a rawaudio file, no alignment */
       // dst_nb_channels2  = av_get_channel_layout_nb_channels(dst_ch_layout);
       ret = av_samples_alloc_array_and_samples(&amp;dst_data2, &amp;dst_linesize, dst_nb_channels,
                                                dst_nb_samples2, dst_sample_fmt, 0);
       if (ret &lt; 0) {
           fprintf(stderr, "Could not allocate destination samples 2\n");
           goto end;
       }

       t = 0;
       do {
           /* generate synthetic audio */
           fill_samples((double *)src_data[0], src_nb_samples, src_nb_channels, src_rate, &amp;t);

           /* compute destination number of samples */
           dst_nb_samples = av_rescale_rnd(swr_get_delay(swr_ctx, src_rate) +
                                           src_nb_samples, dst_rate, src_rate, AV_ROUND_UP);
           if (dst_nb_samples > max_dst_nb_samples) {
               av_freep(&amp;dst_data[0]);
               ret = av_samples_alloc(dst_data, &amp;dst_linesize, dst_nb_channels,
                                      dst_nb_samples, dst_sample_fmt, 1);
               if (ret &lt; 0)
                   break;
               max_dst_nb_samples = dst_nb_samples;
           }

           /* convert to destination format */
           ret = swr_convert(swr_ctx, dst_data, dst_nb_samples, (const uint8_t **)src_data, src_nb_samples);
           if (ret &lt; 0) {
               fprintf(stderr, "Error while converting\n");
               goto end;
           }

           dst_bufsize = av_samples_get_buffer_size(&amp;dst_linesize, dst_nb_channels,
                                                    ret, dst_sample_fmt, 1);
           if (dst_bufsize &lt; 0) {
               fprintf(stderr, "Could not get sample buffer size\n");
               goto end;
           }

           printf("t:%f in:%d out:%d\n", t, src_nb_samples, ret);
           fwrite(dst_data[0], 1, dst_bufsize, dst_file);

           /* compute destination number of samples 2 */
           dst_nb_samples2 = av_rescale_rnd(swr_get_delay(swr_ctx2, dst_rate) +
                                           dst_nb_samples2, 32000, dst_rate, AV_ROUND_UP);
           if (dst_nb_samples2 > max_dst_nb_samples2) {
               av_freep(&amp;dst_data2[0]);
               ret = av_samples_alloc(dst_data2, &amp;dst_linesize, dst_nb_channels,
                                      dst_nb_samples2, dst_sample_fmt, 1);
               if (ret &lt; 0)
                   break;
               max_dst_nb_samples2 = dst_nb_samples2;
           }

           /* convert to destination format */
           ret = swr_convert(swr_ctx2, dst_data2, dst_nb_samples2, (const uint8_t **)dst_data, dst_nb_samples);
           if (ret &lt; 0) {
               fprintf(stderr, "Error while converting 2\n");
               goto end;
           }

           dst_bufsize2 = av_samples_get_buffer_size(&amp;dst_linesize, dst_nb_channels,
                                                    ret, dst_sample_fmt, 1);
           if (dst_bufsize2 &lt; 0) {
               fprintf(stderr, "Could not get sample buffer size 2\n");
               goto end;
           }

           printf("t:%f in:%d out:%d\n", t, dst_nb_samples, ret);
           fwrite(dst_data2[0], 1, dst_bufsize2, dst_file2);
       } while (t &lt; 10);

       if ((ret = get_format_from_sample_fmt(&amp;fmt, dst_sample_fmt)) &lt; 0)
           goto end;
       fprintf(stderr, "Resampling succeeded. Play the output file with the command:\n"
               "ffplay -f %s -channel_layout %"PRId64" -channels %d -ar %d %s\n",
               fmt, dst_ch_layout, dst_nb_channels, dst_rate, dst_filename);

    end:
       fclose(dst_file);

       if (src_data)
           av_freep(&amp;src_data[0]);
       av_freep(&amp;src_data);

       if (dst_data)
           av_freep(&amp;dst_data[0]);
       av_freep(&amp;dst_data);

       swr_free(&amp;swr_ctx);
       return ret &lt; 0;
    }
  • Raspberry Pi 4 live streaming with ffmpeg [closed]

    12 décembre 2019, par Berri

    So speedify created a blog post and youtube video about making an IRL streaming backpack using the Elgato Cam Link 4k, Raspberry Pi 4, and ffmpeg.

    They gave pretty detailed instructions, and included downloads to prebuilt scripts/commands to get it all running once put together.
    Blog post :
    https://speedify.com/blog/how-to/build-irl-streaming-backpack-complete-guide/

    ffmpeg command from post :

    ffmpeg_command = “/home/pi/bin/ffmpeg -nostdin -re -f v4l2 -s ‘1280×720’ -framerate 24 -i /dev/video0 -f alsa -ac 2 -i hw:CARD=Link,DEV=0 -vcodec libx264 -framerate 24 -rtbufsize 1500k -s 1280×720 -preset ultrafast -pix_fmt yuv420p -crf 17 -force_key_frames ‘expr:gte(t,n_forced*2)’ -minrate 850k -maxrate 1000k -b:v 1000k -bufsize 1000k -acodec libmp3lame -rtbufsize 1500k -b 96k -ar 44100 -f flv – | ffmpeg -f flv -i – -c copy -f flv -drop_pkts_on_overflow 1 -attempt_recovery 1 -recovery_wait_time 1 rtmp://live.twitch.tv/app/live_” + streamKey + “‘\n”

    I replaced -i hw:card=link,dev=0 in that command with -i hw:2,0 because -i hw:card=link,dev=0 gave me "file does not exist" errors in the log. "streamkey" is filled with the appropriate key for my twitch.

    Github Resources + Instructions used :
    https://github.com/speedify/rpi-streaming-experiment

    I’m using all the exact same hardware as outlined in the post, and have gotten everything installed correctly as far as I can tell.
    But when I go to run the ffmpeg command, it seems like nothing actually gets sent over to twitch correctly.

    The log after trying to run it looks like this.
    If anybody has any insight as to what may be going wrong, it would be greatly appreciated.

    Starting ffmpeg
    ffmpeg version N-95970-gd5274f8 Copyright (c) 2000-2019 the FFmpeg developers
    built with gcc 8 (Raspbian 8.3.0-6+rpi1)  
    configuration: --prefix=/home/pi/ffmpeg_build --pkg-config-flags=--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-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree  
    libavutil 56. 36.101 / 56. 36.101  
    libavcodec 58. 64.101 / 58. 64.101  
    ffmpeg version N-95970-gd5274f8 libavformat 58. 35.101 / 58. 35.101  
    Copyright (c) 2000-2019 the FFmpeg developers libavdevice 58. 9.101 / 58. 9.101  
    libavfilter 7. 67.100 / 7. 67.100  
    built with gcc 8 (Raspbian 8.3.0-6+rpi1)  
    libswscale 5. 6.100 / 5. 6.100  
    configuration: --prefix=/home/pi/ffmpeg_build --pkg-config-flags=--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-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree  
    libswresample 3. 6.100 / 3. 6.100  
    libpostproc 55. 6.100 / 55. 6.100  
    libavutil 56. 36.101 / 56. 36.101  
    libavcodec 58. 64.101 / 58. 64.101  
    libavformat 58. 35.101 / 58. 35.101  
    libavdevice 58. 9.101 / 58. 9.101  
    libavfilter 7. 67.100 / 7. 67.100  
    libswscale 5. 6.100 / 5. 6.100  
    libswresample 3. 6.100 / 3. 6.100  
    libpostproc 55. 6.100 / 55. 6.100  
    [video4linux2,v4l2 @ 0x2aac5e0] The V4L2 driver changed the video from 1280x720 to 1920x1080  
    [video4linux2,v4l2 @ 0x2aac5e0] The driver changed the time per frame from 1/24 to 117/7013  
    [video4linux2,v4l2 @ 0x2aac5e0] Dequeued v4l2 buffer contains 4147200 bytes, but 3110400 were expected. Flags: 0x00012001.  
    Input #0, video4linux2,v4l2, from '/dev/video0':  
    Duration: N/A, start: 4683.201589, bitrate: 1491503 kb/s  
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, 1491503 kb/s, 59.94 fps, 59.94 tbr, 1000k tbn, 1000k tbc  
    Guessed Channel Layout for Input Stream #1.0 : stereo  
    Input #1, alsa, from 'hw:2,0':  
    Duration: N/A, start: 1576099663.557438, bitrate: 1536 kb/s  
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s  
    Please use -b:a or -b:v, -b is ambiguous  
    Stream mapping:  
    Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))  
    Stream #1:0 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))  
    [video4linux2,v4l2 @ 0x2aac5e0] Dequeued v4l2 buffer contains 4147200 bytes, but 3110400 were expected. Flags: 0x00012001.  
    Last message repeated 9 times
    [video4linux2,v4l2 @ 0x2aac5e0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)  
    [video4linux2,v4l2 @ 0x2aac5e0] Dequeued v4l2 buffer contains 4147200 bytes, but 3110400 were expected. Flags: 0x00012001.  
    Last message repeated 28 times  
    terminated script  
    pipe:: could not find codec parameters  
    Exiting normally, received signal 15.  
    Last message repeated 15 times  
    [alsa @ 0x2aaf2c0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)  
    Finishing stream 0:0 without any data written to it.  
    [libx264 @ 0x2abee40] using cpu capabilities: ARMv6 NEON  
    [libx264 @ 0x2abee40] profile Constrained Baseline, level 3.2, 4:2:0, 8-bit  
    [libx264 @ 0x2abee40] 264 - core 158 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc_lookahead=0 rc=crf mbtree=0 crf=17.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=1000 vbv_bufsize=1000 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=0  
    Finishing stream 0:1 without any data written to it.  
    Output #0, flv, to 'pipe:':  
    Metadata:  
    encoder : Lavf58.35.101  
    Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 1280x720, q=-1--1, 96 kb/s, 59.94 fps, 1k tbn, 59.94 tbc  
    Metadata:  
    encoder : Lavc58.64.101 libx264  
    Side data:  
    cpb: bitrate max/min/avg: 1000000/0/96000 buffer size: 1000000 vbv_delay: N/A  
    Stream #0:1: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 44100 Hz, stereo, s16p  
    Metadata:  
    encoder : Lavc58.64.101 libmp3lame  
    [flv @ 0x2abda90] Failed to update header with correct duration.  
    [flv @ 0x2abda90] Failed to update header with correct filesize.  
    Error writing trailer of pipe:: Broken pipe  
    frame= 0 fps=0.0 q=0.0 Lsize= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
    video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown  
    Exiting normally, received signal 15.        

    This message repeats until script is terminated with the Circuit Express button. For length, many instances of this line were cut out.

    [video4linux2,v4l2 @ 0x2aac5e0] Dequeued v4l2 buffer contains 4147200
    bytes, but 3110400 were expected. Flags: 0x00012001.
    Last message repeated xx times

    Output from v4l2-ctl --list-formats-ext

    ioctl: VIDIOC_ENUM_FMT
       Type: Video Capture

       [0]: 'YUYV' (YUYV 4:2:2)
           Size: Discrete 1920x1080
               Interval: Discrete 0.017s (59.940 fps)
       [1]: 'NV12' (Y/CbCr 4:2:0)
           Size: Discrete 1920x1080
               Interval: Discrete 0.017s (59.940 fps)
       [2]: 'YU12' (Planar YUV 4:2:0)
           Size: Discrete 1920x1080
               Interval: Discrete 0.017s (59.940 fps)

    Log output after ffmpeg command modification.

    Starting ffmpeg
    ffmpeg version N-95970-gd5274f8 Copyright (c) 2000-2019 the FFmpeg developers
     built with gcc 8 (Raspbian 8.3.0-6+rpi1)
     configuration: --prefix=/home/pi/ffmpeg_build --pkg-config-flags=--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-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
     libavutil      56. 36.101 / 56. 36.101
     libavcodec     58. 64.101 / 58. 64.101
     libavformat    58. 35.101 / 58. 35.101
     libavdevice    58.  9.101 / 58.  9.101
     libavfilter     7. 67.100 /  7. 67.100
     libswscale      5.  6.100 /  5.  6.100
     libswresample   3.  6.100 /  3.  6.100
     libpostproc    55.  6.100 / 55.  6.100
    terminated script
    Input #0, video4linux2,v4l2, from '/dev/video0':
     Duration: N/A, bitrate: 1491503 kb/s
       Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, 1491503 kb/s, 59.94 fps, 59.94 tbr, 1000k tbn, 1000k tbc
    Guessed Channel Layout for Input Stream #1.0 : stereo
    Input #1, alsa, from 'hw:1,0':
     Duration: N/A, bitrate: 1536 kb/s
       Stream #1:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    [rtmp @ 0x2605cd0] Cannot open connection tcp://live.twitch.tv:1935
    rtmp://live.twitch.tv/app/live: Immediate exit requested
    Exiting normally, received signal 15.