Recherche avancée

Médias (0)

Mot : - Tags -/api

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

Autres articles (45)

  • 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

  • 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 (...)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

Sur d’autres sites (10308)

  • dyld[16458] : Library not loaded : @rpath/libavcodec.framework/libavcodec while running my flutter app on iOS

    31 janvier 2023, par Stéphane de Luca

    Compilation is successful. But When I run the code, I get this.

    


    Here is the full trace.

    


    Any idea ?

    


    dyld[16458]: Library not loaded: @rpath/libavcodec.framework/libavcodec
  Referenced from: <3500F5CF-B1D2-30EC-8D7F-1C29BD45D05E> /private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Runner
  Reason: tried: '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/preboot/Cryptexes/OS@rpath/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/System/Library/Frameworks/libavcodec.framework/libavcodec' (errno=2, not in dyld cache)
Library not loaded: @rpath/libavcodec.framework/libavcodec
  Referenced from: <3500F5CF-B1D2-30EC-8D7F-1C29BD45D05E> /private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Runner
  Reason: tried: '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swif
dyld config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/usr/lib/libBacktraceRecording.dylib:/usr/lib/libMainThreadChecker.dylib:/usr/lib/libRPAC.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
(lldb) 


    


    The pod is as follows :

    


    # Uncomment this line to define a global platform for your project
platform :ios, '14.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end


    


    The yaml :

    


    
environment:
  sdk: '>=2.18.2 <3.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  video_editor: ^1.5.2
  image_picker: ^0.8.6
  helpers: ^1.2.0
  intl: ^0.17.0
  i18n_extension: ^5.0.1
  optimized_cached_image: ^3.0.1
  youtube_player_flutter: ^8.1.1
  flutter_launcher_icons: ^0.11.0
  flutter_lorem: ^2.0.0
  advance_image_picker: ^0.1.7+1
  wechat_assets_picker: ^8.1.4
  lecle_flutter_absolute_path: ^0.0.2+1
  #ffmpeg_kit_flutter: 5.1.0-LTS
  path_provider: ^2.0.11
  video_thumbnail: ^0.5.3
  flutter_document_picker: ^5.1.0
  flutter_login: ^4.1.1
  #flutter_absolute_path: ^1.0.6
  # flutter_absolute_path:
  #     git:
  #       url: https://github.com/ValeriusGC/flutter_absolute_path.git
  uuid: ^3.0.6
  flutter_form_builder: ^7.7.0
  form_builder_validators: ^8.4.0
  state_persistence: ^0.1.0
  shared_preferences: ^2.0.15
  firebase_core: ^2.4.0
  firebase_storage: ^11.0.8
  video_compress: ^3.1.2
  connectivity_plus: ^3.0.2
  internet_connection_checker: ^1.0.0+1
  cached_video_player: ^2.0.3
  visibility_detector: ^0.3.3
  firebase_database: ^10.0.7
  firebase_auth: ^4.2.1
  firebase_dynamic_links: ^5.0.9
  cloud_firestore: ^4.2.0
  cloud_functions: ^4.0.6
  cached_network_image: ^3.2.3
  ffmpeg_kit_flutter_min_gpl: ^5.1.0
  video_player: ^2.4.10
  provider: ^6.0.5
  camera: ^0.9.8+1
  share_plus: ^6.3.0
  package_info_plus: ^3.0.2

dependency_overrides:
  ffmpeg_kit_flutter_min_gpl: ^5.1.0-LTS

dev_dependencies:
  flutter_test:
    sdk: flutter


  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0

``


    


  • How can I fix a segmentation fault in a C program ? [duplicate]

    31 mars 2023, par ipegasus
    


    Possible Duplicate :
    
Segmentation fault

    


    


    Currently I am upgrading an open source program used for HTTP streaming. It needs to support the latest FFmpeg.
The code compiles fine without any warnings, although I am getting a segmentation fault error.

    


    How can I fix the issue ? And / or, what is the best way to debug ? Please find attached a portion of the code due to size. I will try to add the project to GitHub :)

    


    Sample Usage

    


    # segmenter --i out.ts --l 10 --o stream.m3u8 --d segments --f stream


    


    Makefile

    


    FFLIBS=`pkg-config --libs libavformat libavcodec libavutil`
FFFLAGS=`pkg-config --cflags libavformat libavcodec libavutil`

all:
    gcc -Wall -g segmenter.c -o segmenter ${FFFLAGS} ${FFLIBS}


    


    segmenter.c

    


    /*&#xA; * Copyright (c) 2009 Chase Douglas&#xA; *&#xA; * This program is free software; you can redistribute it and/or&#xA; * modify it under the terms of the GNU General Public License version 2&#xA; * as published by the Free Software Foundation.&#xA; *&#xA; * This program is distributed in the hope that it will be useful,&#xA; * but WITHOUT ANY WARRANTY; without even the implied warranty of&#xA; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&#xA; * GNU General Public License for more details.&#xA; *&#xA; * You should have received a copy of the GNU General Public License&#xA; * along with this program; if not, write to the Free Software&#xA; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&#xA; */&#xA;#include &#xA;#include &#xA;#include &#xA;#include &#xA;#include &#xA;#include "libavformat/avformat.h"&#xA;&#xA;#include "libavformat/avio.h"&#xA;&#xA;#include <sys></sys>stat.h>&#xA;&#xA;#include "segmenter.h"&#xA;#include "libavformat/avformat.h"&#xA;&#xA;#define IMAGE_ID3_SIZE 9171&#xA;&#xA;void printUsage() {&#xA;    fprintf(stderr, "\nExample: segmenter --i infile --d baseDir --f baseFileName --o playListFile.m3u8 --l 10 \n");&#xA;    fprintf(stderr, "\nOptions: \n");&#xA;    fprintf(stderr, "--i <infile>.\n");&#xA;    fprintf(stderr, "--o <outfile>.\n");&#xA;    fprintf(stderr, "--d basedir, the base directory for files.\n");&#xA;    fprintf(stderr, "--f baseFileName, output files will be baseFileName-#.\n");&#xA;    fprintf(stderr, "--l segment length, the length of each segment.\n");&#xA;    fprintf(stderr, "--a,  audio only decode for &lt; 64k streams.\n");&#xA;    fprintf(stderr, "--v,  video only decode for &lt; 64k streams.\n");&#xA;    fprintf(stderr, "--version, print version details and exit.\n");&#xA;    fprintf(stderr, "\n\n");&#xA;}&#xA;&#xA;void ffmpeg_version() {&#xA;    // output build and version numbers&#xA;    fprintf(stderr, "  libavutil version:   %s\n", AV_STRINGIFY(LIBAVUTIL_VERSION));&#xA;    fprintf(stderr, "  libavutil build:     %d\n", LIBAVUTIL_BUILD);&#xA;    fprintf(stderr, "  libavcodec version:  %s\n", AV_STRINGIFY(LIBAVCODEC_VERSION));&#xA;    fprintf(stdout, "  libavcodec build:    %d\n", LIBAVCODEC_BUILD);&#xA;    fprintf(stderr, "  libavformat version: %s\n", AV_STRINGIFY(LIBAVFORMAT_VERSION));&#xA;    fprintf(stderr, "  libavformat build:   %d\n", LIBAVFORMAT_BUILD);&#xA;    fprintf(stderr, "  built on " __DATE__ " " __TIME__);&#xA;#ifdef __GNUC__&#xA;    fprintf(stderr, ", gcc: " __VERSION__ "\n");&#xA;#else&#xA;    fprintf(stderr, ", using a non-gcc compiler\n");&#xA;#endif&#xA;}&#xA;&#xA;&#xA;static AVStream *add_output_stream(AVFormatContext *output_format_context, AVStream *input_stream) {&#xA;    AVCodecContext *input_codec_context;&#xA;    AVCodecContext *output_codec_context;&#xA;    AVStream *output_stream;&#xA;&#xA;    output_stream = avformat_new_stream(output_format_context, 0);&#xA;    if (!output_stream) {&#xA;        fprintf(stderr, "Segmenter error: Could not allocate stream\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    input_codec_context = input_stream->codec;&#xA;    output_codec_context = output_stream->codec;&#xA;&#xA;    output_codec_context->codec_id = input_codec_context->codec_id;&#xA;    output_codec_context->codec_type = input_codec_context->codec_type;&#xA;    output_codec_context->codec_tag = input_codec_context->codec_tag;&#xA;    output_codec_context->bit_rate = input_codec_context->bit_rate;&#xA;    output_codec_context->extradata = input_codec_context->extradata;&#xA;    output_codec_context->extradata_size = input_codec_context->extradata_size;&#xA;&#xA;    if (av_q2d(input_codec_context->time_base) * input_codec_context->ticks_per_frame > av_q2d(input_stream->time_base) &amp;&amp; av_q2d(input_stream->time_base) &lt; 1.0 / 1000) {&#xA;        output_codec_context->time_base = input_codec_context->time_base;&#xA;        output_codec_context->time_base.num *= input_codec_context->ticks_per_frame;&#xA;    } else {&#xA;        output_codec_context->time_base = input_stream->time_base;&#xA;    }&#xA;&#xA;    switch (input_codec_context->codec_type) {&#xA;#ifdef USE_OLD_FFMPEG&#xA;        case CODEC_TYPE_AUDIO:&#xA;#else&#xA;        case AVMEDIA_TYPE_AUDIO:&#xA;#endif&#xA;            output_codec_context->channel_layout = input_codec_context->channel_layout;&#xA;            output_codec_context->sample_rate = input_codec_context->sample_rate;&#xA;            output_codec_context->channels = input_codec_context->channels;&#xA;            output_codec_context->frame_size = input_codec_context->frame_size;&#xA;            if ((input_codec_context->block_align == 1 &amp;&amp; input_codec_context->codec_id == CODEC_ID_MP3) || input_codec_context->codec_id == CODEC_ID_AC3) {&#xA;                output_codec_context->block_align = 0;&#xA;            } else {&#xA;                output_codec_context->block_align = input_codec_context->block_align;&#xA;            }&#xA;            break;&#xA;#ifdef USE_OLD_FFMPEG&#xA;        case CODEC_TYPE_VIDEO:&#xA;#else&#xA;        case AVMEDIA_TYPE_VIDEO:&#xA;#endif&#xA;            output_codec_context->pix_fmt = input_codec_context->pix_fmt;&#xA;            output_codec_context->width = input_codec_context->width;&#xA;            output_codec_context->height = input_codec_context->height;&#xA;            output_codec_context->has_b_frames = input_codec_context->has_b_frames;&#xA;&#xA;            if (output_format_context->oformat->flags &amp; AVFMT_GLOBALHEADER) {&#xA;                output_codec_context->flags |= CODEC_FLAG_GLOBAL_HEADER;&#xA;            }&#xA;            break;&#xA;        default:&#xA;            break;&#xA;    }&#xA;&#xA;    return output_stream;&#xA;}&#xA;&#xA;int write_index_file(const char index[], const char tmp_index[], const unsigned int planned_segment_duration, const unsigned int actual_segment_duration[],&#xA;        const char output_directory[], const char output_prefix[], const char output_file_extension[],&#xA;        const unsigned int first_segment, const unsigned int last_segment) {&#xA;    FILE *index_fp;&#xA;    char *write_buf;&#xA;    unsigned int i;&#xA;&#xA;    index_fp = fopen(tmp_index, "w");&#xA;    if (!index_fp) {&#xA;        fprintf(stderr, "Could not open temporary m3u8 index file (%s), no index file will be created\n", tmp_index);&#xA;        return -1;&#xA;    }&#xA;&#xA;    write_buf = malloc(sizeof (char) * 1024);&#xA;    if (!write_buf) {&#xA;        fprintf(stderr, "Could not allocate write buffer for index file, index file will be invalid\n");&#xA;        fclose(index_fp);&#xA;        return -1;&#xA;    }&#xA;&#xA;    unsigned int maxDuration = planned_segment_duration;&#xA;&#xA;    for (i = first_segment; i &lt;= last_segment; i&#x2B;&#x2B;)&#xA;        if (actual_segment_duration[i] > maxDuration)&#xA;            maxDuration = actual_segment_duration[i];&#xA;&#xA;&#xA;&#xA;    snprintf(write_buf, 1024, "#EXTM3U\n#EXT-X-TARGETDURATION:%u\n", maxDuration);&#xA;&#xA;    if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {&#xA;        fprintf(stderr, "Could not write to m3u8 index file, will not continue writing to index file\n");&#xA;        free(write_buf);&#xA;        fclose(index_fp);&#xA;        return -1;&#xA;    }&#xA;&#xA;    for (i = first_segment; i &lt;= last_segment; i&#x2B;&#x2B;) {&#xA;        snprintf(write_buf, 1024, "#EXTINF:%u,\n%s-%u%s\n", actual_segment_duration[i], output_prefix, i, output_file_extension);&#xA;        if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {&#xA;            fprintf(stderr, "Could not write to m3u8 index file, will not continue writing to index file\n");&#xA;            free(write_buf);&#xA;            fclose(index_fp);&#xA;            return -1;&#xA;        }&#xA;    }&#xA;&#xA;    snprintf(write_buf, 1024, "#EXT-X-ENDLIST\n");&#xA;    if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {&#xA;        fprintf(stderr, "Could not write last file and endlist tag to m3u8 index file\n");&#xA;        free(write_buf);&#xA;        fclose(index_fp);&#xA;        return -1;&#xA;    }&#xA;&#xA;    free(write_buf);&#xA;    fclose(index_fp);&#xA;&#xA;    return rename(tmp_index, index);&#xA;}&#xA;&#xA;int main(int argc, const char *argv[]) {&#xA;    //input parameters&#xA;    char inputFilename[MAX_FILENAME_LENGTH], playlistFilename[MAX_FILENAME_LENGTH], baseDirName[MAX_FILENAME_LENGTH], baseFileName[MAX_FILENAME_LENGTH];&#xA;    char baseFileExtension[5]; //either "ts", "aac" or "mp3"&#xA;    int segmentLength, outputStreams, verbosity, version;&#xA;&#xA;&#xA;&#xA;    char currentOutputFileName[MAX_FILENAME_LENGTH];&#xA;    char tempPlaylistName[MAX_FILENAME_LENGTH];&#xA;&#xA;&#xA;    //these are used to determine the exact length of the current segment&#xA;    double prev_segment_time = 0;&#xA;    double segment_time;&#xA;    unsigned int actual_segment_durations[2048];&#xA;    double packet_time = 0;&#xA;&#xA;    //new variables to keep track of output size&#xA;    double output_bytes = 0;&#xA;&#xA;    unsigned int output_index = 1;&#xA;    AVOutputFormat *ofmt;&#xA;    AVFormatContext *ic = NULL;&#xA;    AVFormatContext *oc;&#xA;    AVStream *video_st = NULL;&#xA;    AVStream *audio_st = NULL;&#xA;    AVCodec *codec;&#xA;    int video_index;&#xA;    int audio_index;&#xA;    unsigned int first_segment = 1;&#xA;    unsigned int last_segment = 0;&#xA;    int write_index = 1;&#xA;    int decode_done;&#xA;    int ret;&#xA;    int i;&#xA;&#xA;    unsigned char id3_tag[128];&#xA;    unsigned char * image_id3_tag;&#xA;&#xA;    size_t id3_tag_size = 73;&#xA;    int newFile = 1; //a boolean value to flag when a new file needs id3 tag info in it&#xA;&#xA;    if (parseCommandLine(inputFilename, playlistFilename, baseDirName, baseFileName, baseFileExtension, &amp;outputStreams, &amp;segmentLength, &amp;verbosity, &amp;version, argc, argv) != 0)&#xA;        return 0;&#xA;&#xA;    if (version) {&#xA;        ffmpeg_version();&#xA;        return 0;&#xA;    }&#xA;&#xA;&#xA;    fprintf(stderr, "%s %s\n", playlistFilename, tempPlaylistName);&#xA;&#xA;&#xA;    image_id3_tag = malloc(IMAGE_ID3_SIZE);&#xA;    if (outputStreams == OUTPUT_STREAM_AUDIO)&#xA;        build_image_id3_tag(image_id3_tag);&#xA;    build_id3_tag((char *) id3_tag, id3_tag_size);&#xA;&#xA;    snprintf(tempPlaylistName, strlen(playlistFilename) &#x2B; strlen(baseDirName) &#x2B; 1, "%s%s", baseDirName, playlistFilename);&#xA;    strncpy(playlistFilename, tempPlaylistName, strlen(tempPlaylistName));&#xA;    strncpy(tempPlaylistName, playlistFilename, MAX_FILENAME_LENGTH);&#xA;    strncat(tempPlaylistName, ".", 1);&#xA;&#xA;    //decide if this is an aac file or a mpegts file.&#xA;    //postpone deciding format until later&#xA;    /*    ifmt = av_find_input_format("mpegts");&#xA;    if (!ifmt)&#xA;    {&#xA;    fprintf(stderr, "Could not find MPEG-TS demuxer.\n");&#xA;    exit(1);&#xA;    } */&#xA;&#xA;    av_log_set_level(AV_LOG_DEBUG);&#xA;&#xA;    av_register_all();&#xA;    ret = avformat_open_input(&amp;ic, inputFilename, NULL, NULL);&#xA;    if (ret != 0) {&#xA;        fprintf(stderr, "Could not open input file %s. Error %d.\n", inputFilename, ret);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    if (avformat_find_stream_info(ic, NULL) &lt; 0) {&#xA;        fprintf(stderr, "Could not read stream information.\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    oc = avformat_alloc_context();&#xA;    if (!oc) {&#xA;        fprintf(stderr, "Could not allocate output context.");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    video_index = -1;&#xA;    audio_index = -1;&#xA;&#xA;    for (i = 0; i &lt; ic->nb_streams &amp;&amp; (video_index &lt; 0 || audio_index &lt; 0); i&#x2B;&#x2B;) {&#xA;        switch (ic->streams[i]->codec->codec_type) {&#xA;&#xA;#ifdef USE_OLD_FFMPEG&#xA;            case CODEC_TYPE_VIDEO:&#xA;#else&#xA;            case AVMEDIA_TYPE_VIDEO:&#xA;#endif&#xA;                video_index = i;&#xA;                ic->streams[i]->discard = AVDISCARD_NONE;&#xA;                if (outputStreams &amp; OUTPUT_STREAM_VIDEO)&#xA;                    video_st = add_output_stream(oc, ic->streams[i]);&#xA;                break;&#xA;#ifdef USE_OLD_FFMPEG&#xA;            case CODEC_TYPE_AUDIO:&#xA;#else&#xA;            case AVMEDIA_TYPE_AUDIO:&#xA;#endif&#xA;                audio_index = i;&#xA;                ic->streams[i]->discard = AVDISCARD_NONE;&#xA;                if (outputStreams &amp; OUTPUT_STREAM_AUDIO)&#xA;                    audio_st = add_output_stream(oc, ic->streams[i]);&#xA;                break;&#xA;            default:&#xA;                ic->streams[i]->discard = AVDISCARD_ALL;&#xA;                break;&#xA;        }&#xA;    }&#xA;&#xA;    if (video_index == -1) {&#xA;        fprintf(stderr, "Stream must have video component.\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    //now that we know the audio and video output streams&#xA;    //we can decide on an output format.&#xA;    if (outputStreams == OUTPUT_STREAM_AUDIO) {&#xA;        //the audio output format should be the same as the audio input format&#xA;        switch (ic->streams[audio_index]->codec->codec_id) {&#xA;            case CODEC_ID_MP3:&#xA;                fprintf(stderr, "Setting output audio to mp3.");&#xA;                strncpy(baseFileExtension, ".mp3", strlen(".mp3"));&#xA;                ofmt = av_guess_format("mp3", NULL, NULL);&#xA;                break;&#xA;            case CODEC_ID_AAC:&#xA;                fprintf(stderr, "Setting output audio to aac.");&#xA;                ofmt = av_guess_format("adts", NULL, NULL);&#xA;                break;&#xA;            default:&#xA;                fprintf(stderr, "Codec id %d not supported.\n", ic->streams[audio_index]->id);&#xA;        }&#xA;        if (!ofmt) {&#xA;            fprintf(stderr, "Could not find audio muxer.\n");&#xA;            exit(1);&#xA;        }&#xA;    } else {&#xA;        ofmt = av_guess_format("mpegts", NULL, NULL);&#xA;        if (!ofmt) {&#xA;            fprintf(stderr, "Could not find MPEG-TS muxer.\n");&#xA;            exit(1);&#xA;        }&#xA;    }&#xA;    oc->oformat = ofmt;&#xA;&#xA;    if (outputStreams &amp; OUTPUT_STREAM_VIDEO &amp;&amp; oc->oformat->flags &amp; AVFMT_GLOBALHEADER) {&#xA;        oc->flags |= CODEC_FLAG_GLOBAL_HEADER;&#xA;    }&#xA;&#xA;&#xA;    /*  Deprecated: pass the options to avformat_write_header directly.&#xA;        if (av_set_parameters(oc, NULL) &lt; 0) {&#xA;            fprintf(stderr, "Invalid output format parameters.\n");&#xA;            exit(1);&#xA;        }&#xA;     */&#xA;&#xA;    av_dump_format(oc, 0, baseFileName, 1);&#xA;&#xA;&#xA;    //open the video codec only if there is video data&#xA;    if (video_index != -1) {&#xA;        if (outputStreams &amp; OUTPUT_STREAM_VIDEO)&#xA;            codec = avcodec_find_decoder(video_st->codec->codec_id);&#xA;        else&#xA;            codec = avcodec_find_decoder(ic->streams[video_index]->codec->codec_id);&#xA;        if (!codec) {&#xA;            fprintf(stderr, "Could not find video decoder, key frames will not be honored.\n");&#xA;        }&#xA;&#xA;        if (outputStreams &amp; OUTPUT_STREAM_VIDEO)&#xA;            ret = avcodec_open2(video_st->codec, codec, NULL);&#xA;        else&#xA;            avcodec_open2(ic->streams[video_index]->codec, codec, NULL);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not open video decoder, key frames will not be honored.\n");&#xA;        }&#xA;    }&#xA;&#xA;    snprintf(currentOutputFileName, strlen(baseDirName) &#x2B; strlen(baseFileName) &#x2B; strlen(baseFileExtension) &#x2B; 10, "%s%s-%u%s", baseDirName, baseFileName, output_index&#x2B;&#x2B;, baseFileExtension);&#xA;&#xA;    if (avio_open(&amp;oc->pb, currentOutputFileName, URL_WRONLY) &lt; 0) {&#xA;        fprintf(stderr, "Could not open &#x27;%s&#x27;.\n", currentOutputFileName);&#xA;        exit(1);&#xA;    }&#xA;    newFile = 1;&#xA;&#xA;    int r = avformat_write_header(oc,NULL);&#xA;    if (r) {&#xA;        fprintf(stderr, "Could not write mpegts header to first output file.\n");&#xA;        debugReturnCode(r);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    //no segment info is written here. This just creates the shell of the playlist file&#xA;    write_index = !write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);&#xA;&#xA;    do {&#xA;        AVPacket packet;&#xA;&#xA;        decode_done = av_read_frame(ic, &amp;packet);&#xA;&#xA;        if (decode_done &lt; 0) {&#xA;            break;&#xA;        }&#xA;&#xA;        if (av_dup_packet(&amp;packet) &lt; 0) {&#xA;            fprintf(stderr, "Could not duplicate packet.");&#xA;            av_free_packet(&amp;packet);&#xA;            break;&#xA;        }&#xA;&#xA;        //this time is used to check for a break in the segments&#xA;        //    if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; PKT_FLAG_KEY))&#xA;        //    {&#xA;        //    segment_time = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;&#xA;        //    }&#xA;#if USE_OLD_FFMPEG&#xA;        if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; PKT_FLAG_KEY))&#xA;#else&#xA;        if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; AV_PKT_FLAG_KEY))&#xA;#endif&#xA;        {&#xA;            segment_time = (double) packet.pts * ic->streams[video_index]->time_base.num / ic->streams[video_index]->time_base.den;&#xA;        }&#xA;        //  else if (video_index &lt; 0)&#xA;        //    {&#xA;        //        segment_time = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;&#xA;        //    }&#xA;&#xA;        //get the most recent packet time&#xA;        //this time is used when the time for the final segment is printed. It may not be on the edge of&#xA;        //of a keyframe!&#xA;        if (packet.stream_index == video_index)&#xA;            packet_time = (double) packet.pts * ic->streams[video_index]->time_base.num / ic->streams[video_index]->time_base.den; //(double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;&#xA;        else if (outputStreams &amp; OUTPUT_STREAM_AUDIO)&#xA;            packet_time = (double) audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;&#xA;        else&#xA;            continue;&#xA;        //start looking for segment splits for videos one half second before segment duration expires. This is because the&#xA;        //segments are split on key frames so we cannot expect all segments to be split exactly equally.&#xA;        if (segment_time - prev_segment_time >= segmentLength - 0.5) {&#xA;            fprintf(stderr, "looking to print index file at time %lf\n", segment_time);&#xA;            avio_flush(oc->pb);&#xA;            avio_close(oc->pb);&#xA;&#xA;            if (write_index) {&#xA;                actual_segment_durations[&#x2B;&#x2B;last_segment] = (unsigned int) rint(segment_time - prev_segment_time);&#xA;                write_index = !write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);&#xA;                fprintf(stderr, "Writing index file at time %lf\n", packet_time);&#xA;            }&#xA;&#xA;            struct stat st;&#xA;            stat(currentOutputFileName, &amp;st);&#xA;            output_bytes &#x2B;= st.st_size;&#xA;&#xA;            snprintf(currentOutputFileName, strlen(baseDirName) &#x2B; strlen(baseFileName) &#x2B; strlen(baseFileExtension) &#x2B; 10, "%s%s-%u%s", baseDirName, baseFileName, output_index&#x2B;&#x2B;, baseFileExtension);&#xA;            if (avio_open(&amp;oc->pb, currentOutputFileName, URL_WRONLY) &lt; 0) {&#xA;                fprintf(stderr, "Could not open &#x27;%s&#x27;\n", currentOutputFileName);&#xA;                break;&#xA;            }&#xA;&#xA;            newFile = 1;&#xA;            prev_segment_time = segment_time;&#xA;        }&#xA;&#xA;        if (outputStreams == OUTPUT_STREAM_AUDIO &amp;&amp; packet.stream_index == audio_index) {&#xA;            if (newFile &amp;&amp; outputStreams == OUTPUT_STREAM_AUDIO) {&#xA;                //add id3 tag info&#xA;                //fprintf(stderr, "adding id3tag to file %s\n", currentOutputFileName);&#xA;                //printf("%lf %lld %lld %lld %lld %lld %lf\n", segment_time, audio_st->pts.val, audio_st->cur_dts, audio_st->cur_pkt.pts, packet.pts, packet.dts, packet.dts * av_q2d(ic->streams[audio_index]->time_base) );&#xA;                fill_id3_tag((char*) id3_tag, id3_tag_size, packet.dts);&#xA;                avio_write(oc->pb, id3_tag, id3_tag_size);&#xA;                avio_write(oc->pb, image_id3_tag, IMAGE_ID3_SIZE);&#xA;                avio_flush(oc->pb);&#xA;                newFile = 0;&#xA;            }&#xA;&#xA;            packet.stream_index = 0; //only one stream in audio only segments&#xA;            ret = av_interleaved_write_frame(oc, &amp;packet);&#xA;        } else if (outputStreams &amp; OUTPUT_STREAM_VIDEO) {&#xA;            if (newFile) {&#xA;                //fprintf(stderr, "New File: %lld %lld %lld\n", packet.pts, video_st->pts.val, audio_st->pts.val);&#xA;                //printf("%lf %lld %lld %lld %lld %lld %lf\n", segment_time, audio_st->pts.val, audio_st->cur_dts, audio_st->cur_pkt.pts, packet.pts, packet.dts, packet.dts * av_q2d(ic->streams[audio_index]->time_base) );&#xA;                newFile = 0;&#xA;            }&#xA;            if (outputStreams == OUTPUT_STREAM_VIDEO)&#xA;                ret = av_write_frame(oc, &amp;packet);&#xA;            else&#xA;                ret = av_interleaved_write_frame(oc, &amp;packet);&#xA;        }&#xA;&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Warning: Could not write frame of stream.\n");&#xA;        } else if (ret > 0) {&#xA;            fprintf(stderr, "End of stream requested.\n");&#xA;            av_free_packet(&amp;packet);&#xA;            break;&#xA;        }&#xA;&#xA;        av_free_packet(&amp;packet);&#xA;    } while (!decode_done);&#xA;&#xA;    //make sure all packets are written and then close the last file.&#xA;    avio_flush(oc->pb);&#xA;    av_write_trailer(oc);&#xA;&#xA;    if (video_st &amp;&amp; video_st->codec)&#xA;        avcodec_close(video_st->codec);&#xA;&#xA;    if (audio_st &amp;&amp; audio_st->codec)&#xA;        avcodec_close(audio_st->codec);&#xA;&#xA;    for (i = 0; i &lt; oc->nb_streams; i&#x2B;&#x2B;) {&#xA;        av_freep(&amp;oc->streams[i]->codec);&#xA;        av_freep(&amp;oc->streams[i]);&#xA;    }&#xA;&#xA;    avio_close(oc->pb);&#xA;    av_free(oc);&#xA;&#xA;    struct stat st;&#xA;    stat(currentOutputFileName, &amp;st);&#xA;    output_bytes &#x2B;= st.st_size;&#xA;&#xA;&#xA;    if (write_index) {&#xA;        actual_segment_durations[&#x2B;&#x2B;last_segment] = (unsigned int) rint(packet_time - prev_segment_time);&#xA;&#xA;        //make sure that the last segment length is not zero&#xA;        if (actual_segment_durations[last_segment] == 0)&#xA;            actual_segment_durations[last_segment] = 1;&#xA;&#xA;        write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);&#xA;&#xA;    }&#xA;&#xA;    write_stream_size_file(baseDirName, baseFileName, output_bytes * 8 / segment_time);&#xA;&#xA;    return 0;&#xA;}&#xA;</outfile></infile>

    &#xA;

  • Video encoding task not working with Django Celery Redis FFMPEG and GraphQL

    18 juin 2023, par phanio

    I'm having a hard time trying to understand how is this FFMPEG encoding works while using Django, Celery, Redis, GraphQL and Docker too.

    &#xA;

    I have this video / courses platform project and want I'm trying to do using FFMPEG, Celery and Redis is to create different video resolutions so I can display them the way Youtube does inside the videoplayer ( the videoplayer is handled in frontend by Nextjs and Apollo Client ), now on the backend I've just learned that in order to use properly the FFMPEG to resize the oridinal video size, I need to use Celery and Redis to perform asyncronus tasks. I've found a few older posts here on stackoverflow and google, but is not quite enough info for someone who is using the ffmpeg and clery and redis for the first time ( I've started already step by step and created that example that adds two numbers together with celery, that works well ). Now I'm not sure what is wrong with my code, because first of all I'm not really sure where should I trigger the task from, I mean from which file, because at the end of the task I want to send the data through api using GrapQL Strawberry.

    &#xA;

    This is what I've tried by now :

    &#xA;

    So first things first my project structure looks like this

    &#xA;

    - backend #root directory&#xA; --- backend&#xA;    -- __init__.py&#xA;    -- celery.py&#xA;    -- settings.py&#xA;    -- urls.py&#xA;      etc..&#xA;&#xA; --- static&#xA;   -- videos&#xA;&#xA; --- video&#xA;   -- models.py&#xA;   -- schema.py&#xA;   -- tasks.py&#xA;   -- types.py&#xA;   etc..&#xA;&#xA; --- .env&#xA;&#xA; --- db.sqlite3&#xA;&#xA; --- docker-compose.yml&#xA;&#xA; --- Dockerfile&#xA;&#xA; --- manage.py&#xA;&#xA; --- requirements.txt&#xA;

    &#xA;

    here is my settings.py file :

    &#xA;

    from pathlib import Path&#xA;import os&#xA;&#xA;# Build paths inside the project like this: BASE_DIR / &#x27;subdir&#x27;.&#xA;BASE_DIR = Path(__file__).resolve().parent.parent&#xA;&#xA;DEBUG = True&#xA;&#xA;ALLOWED_HOSTS=["localhost", "0.0.0.0", "127.0.0.1"]&#xA;&#xA;DEFAULT_AUTO_FIELD = &#x27;django.db.models.BigAutoField&#x27;&#xA;&#xA;&#xA;# Application definition&#xA;&#xA;INSTALLED_APPS = [&#xA;    "corsheaders",&#xA;    &#x27;django.contrib.admin&#x27;,&#xA;    &#x27;django.contrib.auth&#x27;,&#xA;    &#x27;django.contrib.contenttypes&#x27;,&#xA;    &#x27;django.contrib.sessions&#x27;,&#xA;    &#x27;django.contrib.messages&#x27;,&#xA;    &#x27;django.contrib.staticfiles&#x27;,&#xA;&#xA;    "strawberry.django",&#xA;    "video"&#xA;]&#xA;&#xA;etc...&#xA;&#xA;STATIC_URL = &#x27;/static/&#x27;&#xA;MEDIA_URL = &#x27;/videos/&#x27;&#xA;&#xA;STATICFILES_DIRS = [&#xA;    BASE_DIR / &#x27;static&#x27;,&#xA;    # BASE_DIR / &#x27;frontend/build/static&#x27;,&#xA;]&#xA;&#xA;MEDIA_ROOT = BASE_DIR / &#x27;static/videos&#x27;&#xA;&#xA;STATIC_ROOT = BASE_DIR / &#x27;staticfiles&#x27;&#xA;&#xA;STATICFILES_STORAGE = &#x27;whitenoise.storage.CompressedManifestStaticFilesStorage&#x27;&#xA;&#xA;CORS_ALLOW_ALL_ORIGINS = True&#xA;&#xA;&#xA;CELERY_BEAT_SCHEDULER = &#x27;django_celery_beat.schedulers:DatabaseScheduler&#x27;&#xA;&#xA;# REDIS CACHE&#xA;CACHES = {&#xA;    "default": {&#xA;        "BACKEND": "django_redis.cache.RedisCache",&#xA;        "LOCATION": f"redis://127.0.0.1:6379/1",&#xA;        "OPTIONS": {&#xA;            "CLIENT_CLASS": "django_redis.client.DefaultClient",&#xA;        },&#xA;    }&#xA;}&#xA;&#xA;# Docker&#xA;CELERY_BROKER_URL = os.environ.get("CELERY_BROKER", "redis://redis:6379/0")&#xA;CELERY_RESULT_BACKEND = os.environ.get("CELERY_BROKER", "redis://redis:6379/0")&#xA;

    &#xA;

    This is my main urls.py file :

    &#xA;

    from django.contrib import admin&#xA;from django.conf import settings&#xA;from django.conf.urls.static import static&#xA;from django.urls import path&#xA;from django.urls.conf import include&#xA;from strawberry.django.views import GraphQLView&#xA;&#xA;from video.schema import schema&#xA;&#xA;urlpatterns = [&#xA;    path(&#x27;admin/&#x27;, admin.site.urls),&#xA;    path("graphql", GraphQLView.as_view(schema=schema)),&#xA;]&#xA;&#xA;if settings.DEBUG:&#xA;    urlpatterns &#x2B;= static(settings.MEDIA_URL,&#xA;                          document_root=settings.MEDIA_ROOT)&#xA;    urlpatterns &#x2B;= static(settings.STATIC_URL,&#xA;                          document_root=settings.STATIC_ROOT)&#xA;

    &#xA;

    This is my celery.py file :

    &#xA;

    from __future__ import absolute_import, unicode_literals&#xA;import os&#xA;from celery import Celery&#xA;from django.conf import settings&#xA;&#xA;os.environ.setdefault(&#x27;DJANGO_SETTINGS_MODULE&#x27;, &#x27;backend.settings&#x27;)&#xA;&#xA;backend = Celery(&#x27;backend&#x27;)&#xA;&#xA;backend.config_from_object(&#x27;django.conf:settings&#x27;, namespace="CELERY")&#xA;&#xA;backend.autodiscover_tasks()&#xA;&#xA;@backend.task(bind=True)&#xA;def debug_task(self):&#xA;    print(&#x27;Request: {0!r}&#x27;.format(self.request))&#xA;

    &#xA;

    This is my init.py file :

    &#xA;

    from .celery import backend as celery_backend&#xA;&#xA;__all__ = (&#x27;celery_backend&#x27;,)&#xA;

    &#xA;

    This is my Dockerfile :

    &#xA;

    FROM python:3&#xA;ENV PYTHONUNBUFFERED=1&#xA;&#xA;WORKDIR /usr/src/backend&#xA;&#xA;RUN apt-get -y update&#xA;RUN apt-get -y upgrade&#xA;RUN apt-get install -y ffmpeg&#xA;&#xA;COPY requirements.txt ./&#xA;RUN pip install -r requirements.txt&#xA;

    &#xA;

    This is my docker-compose.yml file :

    &#xA;

    version: "3.8"&#xA;&#xA;services:&#xA;  django:&#xA;    build: .&#xA;    container_name: django&#xA;    command: python manage.py runserver 0.0.0.0:8000&#xA;    volumes:&#xA;      - .:/usr/src/backend/&#xA;    ports:&#xA;      - "8000:8000"&#xA;    environment:&#xA;      - DEBUG=1&#xA;      - DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]&#xA;      - CELERY_BROKER=redis://redis:6379/0&#xA;      - CELERY_BACKEND=redis://redis:6379/0&#xA;    depends_on:&#xA;      - pgdb&#xA;      - redis&#xA;&#xA;  celery:&#xA;    build: .&#xA;    command: celery -A backend worker -l INFO&#xA;    volumes:&#xA;      - .:/usr/src/backend&#xA;    depends_on:&#xA;      - django&#xA;      - redis&#xA;&#xA;  pgdb:&#xA;    image: postgres&#xA;    container_name: pgdb&#xA;    environment:&#xA;      - POSTGRES_DB=postgres&#xA;      - POSTGRES_USER=postgres&#xA;      - POSTGRES_PASSWORD=postgres&#xA;    volumes:&#xA;      - pgdata:/var/lib/postgresql/data/&#xA;&#xA;  redis:&#xA;    image: "redis:alpine"&#xA;&#xA;volumes:&#xA;  pgdata:&#xA;

    &#xA;

    And now inside my video app folder :

    &#xA;

    My models.py file :

    &#xA;

      &#xA;
    • here I've created separated fields for all resolution sizes, from video_file_2k to video_file_144, I was thinking that maybe after the process of the encoding this will populate those fields..
    • &#xA;

    &#xA;

    from django.db import models&#xA;from django.urls import reverse&#xA;&#xA;&#xA;class Video(models.Model):&#xA;    video_id = models.AutoField(primary_key=True, editable=False)&#xA;    slug = models.SlugField(max_length=255)&#xA;    title = models.CharField(max_length=150, blank=True, null=True)&#xA;    description = models.TextField(blank=True, null=True)&#xA;    video_file = models.FileField(null=False, blank=False)&#xA;    video_file_2k = models.FileField(null=True, blank=True)&#xA;    video_file_fullhd = models.FileField(null=True, blank=True)&#xA;    video_file_hd = models.FileField(null=True, blank=True)&#xA;    video_file_480 = models.FileField(null=True, blank=True)&#xA;    video_file_360 = models.FileField(null=True, blank=True)&#xA;    video_file_240 = models.FileField(null=True, blank=True)&#xA;    video_file_144 = models.FileField(null=True, blank=True)&#xA;    category = models.CharField(max_length=64, blank=False, null=False)&#xA;    created_at = models.DateTimeField(&#xA;        ("Created at"), auto_now_add=True, editable=False)&#xA;    updated_at = models.DateTimeField(("Updated at"), auto_now=True)&#xA;&#xA;    class Meta:&#xA;        ordering = ("-created_at",)&#xA;        verbose_name = ("Video")&#xA;        verbose_name_plural = ("Videos")&#xA;&#xA;    def get_absolute_url(self):&#xA;        return reverse("store:video_detail", args=[self.slug])&#xA;&#xA;    def __str__(self):&#xA;        return self.title&#xA;

    &#xA;

    This is my schema.py file :

    &#xA;

    import strawberry&#xA;from strawberry.file_uploads import Upload&#xA;from typing import List&#xA;from .types import VideoType&#xA;from .models import Video&#xA;from .tasks import task_video_encoding_1080p, task_video_encoding_720p&#xA;&#xA;&#xA;@strawberry.type&#xA;class Query:&#xA;    @strawberry.field&#xA;    def videos(self, category: str = None) -> List[VideoType]:&#xA;        if category:&#xA;            videos = Video.objects.filter(category=category)&#xA;            return videos&#xA;        return Video.objects.all()&#xA;&#xA;    @strawberry.field&#xA;    def video(self, slug: str) -> VideoType:&#xA;        if slug == slug:&#xA;            video = Video.objects.get(slug=slug)&#xA;            return video&#xA;&#xA;    @strawberry.field&#xA;    def video_by_id(self, video_id: int) -> VideoType:&#xA;        if video_id == video_id:&#xA;            video = Video.objects.get(pk=video_id)&#xA;&#xA;          # Here I&#x27;ve tried to trigger my tasks, when I visited 0.0.0.0:8000/graphql url&#xA;          # and I was querying for a video by it&#x27;s id , then I&#x27;ve got the error from celery &#xA;            task_video_encoding_1080p.delay(video_id)&#xA;            task_video_encoding_720p.delay(video_id)&#xA;&#xA;            return video&#xA;&#xA;&#xA;@strawberry.type&#xA;class Mutation:&#xA;    @strawberry.field&#xA;    def create_video(self, slug: str, title: str, description: str, video_file: Upload, video_file_2k: str, video_file_fullhd: str, video_file_hd: str, video_file_480: str, video_file_360: str, video_file_240: str, video_file_144: str, category: str) -> VideoType:&#xA;&#xA;        video = Video(slug=slug, title=title, description=description,&#xA;                      video_file=video_file, video_file_2k=video_file_2k, video_file_fullhd=video_file_fullhd, video_file_hd=video_file_hd, video_file_480=video_file_480, video_file_360=video_file_360, video_file_240=video_file_240, video_file_144=video_file_144,category=category)&#xA;        &#xA;        video.save()&#xA;        return video&#xA;&#xA;    @strawberry.field&#xA;    def update_video(self, video_id: int, slug: str, title: str, description: str, video_file: str, category: str) -> VideoType:&#xA;        video = Video.objects.get(video_id=video_id)&#xA;        video.slug = slug&#xA;        video.title = title&#xA;        video.description = description&#xA;        video.video_file = video_file&#xA;        video.category = category&#xA;        video.save()&#xA;        return video&#xA;&#xA;    @strawberry.field&#xA;    def delete_video(self, video_id: int) -> bool:&#xA;        video = Video.objects.get(video_id=video_id)&#xA;        video.delete&#xA;        return True&#xA;&#xA;&#xA;schema = strawberry.Schema(query=Query, mutation=Mutation)&#xA;

    &#xA;

    This is my types.py file ( strawberry graphql related ) :

    &#xA;

    import strawberry&#xA;&#xA;from .models import Video&#xA;&#xA;&#xA;@strawberry.django.type(Video)&#xA;class VideoType:&#xA;    video_id: int&#xA;    slug: str&#xA;    title: str&#xA;    description: str&#xA;    video_file: str&#xA;    video_file_2k: str&#xA;    video_file_fullhd: str&#xA;    video_file_hd: str&#xA;    video_file_480: str&#xA;    video_file_360: str&#xA;    video_file_240: str&#xA;    video_file_144: str&#xA;    category: str&#xA;

    &#xA;

    And this is my tasks.py file :

    &#xA;

    from __future__ import absolute_import, unicode_literals&#xA;import os, subprocess&#xA;from django.conf import settings&#xA;from django.core.exceptions import ValidationError&#xA;from celery import shared_task&#xA;from celery.utils.log import get_task_logger&#xA;from .models import Video&#xA;FFMPEG_PATH = os.environ["IMAGEIO_FFMPEG_EXE"] = "/opt/homebrew/Cellar/ffmpeg/6.0/bin/ffmpeg"&#xA;&#xA;logger = get_task_logger(__name__)&#xA;&#xA;&#xA;# CELERY TASKS&#xA;@shared_task&#xA;def add(x,y):&#xA;    return x &#x2B; y&#xA;&#xA;&#xA;@shared_task&#xA;def task_video_encoding_720p(video_id):&#xA;    logger.info(&#x27;Video Processing started&#x27;)&#xA;    try:&#xA;        video = Video.objects.get(video_id=video_id)&#xA;        input_file_path = video.video_file.path&#xA;        input_file_url = video.video_file.url&#xA;        input_file_name = video.video_file.name&#xA;&#xA;        # get the filename (without extension)&#xA;        filename = os.path.basename(input_file_url)&#xA;&#xA;        # path to the new file, change it according to where you want to put it&#xA;        output_file_name = os.path.join(&#x27;videos&#x27;, &#x27;mp4&#x27;, &#x27;{}.mp4&#x27;.format(filename))&#xA;        output_file_path = os.path.join(settings.MEDIA_ROOT, output_file_name)&#xA;&#xA;        # 2-pass encoding&#xA;        for i in range(1):&#xA;           new_video_720p = subprocess.call([FFMPEG_PATH, &#x27;-i&#x27;, input_file_path, &#x27;-s&#x27;, &#x27;1280x720&#x27;, &#x27;-vcodec&#x27;, &#x27;mpeg4&#x27;, &#x27;-acodec&#x27;, &#x27;libvo_aacenc&#x27;, &#x27;-b&#x27;, &#x27;10000k&#x27;, &#x27;-pass&#x27;, i, &#x27;-r&#x27;, &#x27;30&#x27;, output_file_path])&#xA;        #    new_video_720p = subprocess.call([FFMPEG_PATH, &#x27;-i&#x27;, input_file_path, &#x27;-s&#x27;, &#x27;{}x{}&#x27;.format(height * 16/9, height), &#x27;-vcodec&#x27;, &#x27;mpeg4&#x27;, &#x27;-acodec&#x27;, &#x27;libvo_aacenc&#x27;, &#x27;-b&#x27;, &#x27;10000k&#x27;, &#x27;-pass&#x27;, i, &#x27;-r&#x27;, &#x27;30&#x27;, output_file_path])&#xA;&#xA;        if new_video_720p == 0:&#xA;            # save the new file in the database&#xA;            # video.video_file_hd.name = output_file_name&#xA;            video.save(update_fields=[&#x27;video_file_hd&#x27;])&#xA;            logger.info(&#x27;Video Processing Finished&#x27;)&#xA;            return video&#xA;&#xA;        else:&#xA;            logger.info(&#x27;Proceesing Failed.&#x27;) # Just for now&#xA;&#xA;    except:&#xA;        raise ValidationError(&#x27;Something went wrong&#x27;)&#xA;&#xA;&#xA;@shared_task&#xA;# def task_video_encoding_1080p(video_id, height):&#xA;def task_video_encoding_1080p(video_id):&#xA;    logger.info(&#x27;Video Processing started&#x27;)&#xA;    try:&#xA;        video = Video.objects.get(video_id=video_id)&#xA;        input_file_path = video.video_file.url&#xA;        input_file_name = video.video_file.name&#xA;&#xA;        # get the filename (without extension)&#xA;        filename = os.path.basename(input_file_path)&#xA;&#xA;        # path to the new file, change it according to where you want to put it&#xA;        output_file_name = os.path.join(&#x27;videos&#x27;, &#x27;mp4&#x27;, &#x27;{}.mp4&#x27;.format(filename))&#xA;        output_file_path = os.path.join(settings.MEDIA_ROOT, output_file_name)&#xA;&#xA;        for i in range(1):&#xA;            new_video_1080p = subprocess.call([FFMPEG_PATH, &#x27;-i&#x27;, input_file_path, &#x27;-s&#x27;, &#x27;1920x1080&#x27;, &#x27;-vcodec&#x27;, &#x27;mpeg4&#x27;, &#x27;-acodec&#x27;, &#x27;libvo_aacenc&#x27;, &#x27;-b&#x27;, &#x27;10000k&#x27;, &#x27;-pass&#x27;, i, &#x27;-r&#x27;, &#x27;30&#x27;, output_file_path])&#xA;&#xA;        if new_video_1080p == 0:&#xA;            # save the new file in the database&#xA;            # video.video_file_hd.name = output_file_name&#xA;            video.save(update_fields=[&#x27;video_file_fullhd&#x27;])&#xA;            logger.info(&#x27;Video Processing Finished&#x27;)&#xA;            return video&#xA;        else:&#xA;            logger.info(&#x27;Proceesing Failed.&#x27;) # Just for now&#xA;&#xA;    except:&#xA;        raise ValidationError(&#x27;Something went wrong&#x27;)&#xA;

    &#xA;

    In my first attempt I wasn't triggering the tasks no where, then I've tried to trigger the task from the schema.py file from graphql inside the video_by_id, but there I've got this error :

    &#xA;

    backend-celery-1  | django.core.exceptions.ValidationError: [&#x27;Something went wrong&#x27;]&#xA;backend-celery-1  | [2023-06-18 16:38:52,859: ERROR/ForkPoolWorker-4] Task video.tasks.task_video_encoding_1080p[d33b1a42-5914-467c-ad5c-00565bc8be6f] raised unexpected: ValidationError([&#x27;Something went wrong&#x27;])&#xA;backend-celery-1  | Traceback (most recent call last):&#xA;backend-celery-1  |   File "/usr/src/backend/video/tasks.py", line 81, in task_video_encoding_1080p&#xA;backend-celery-1  |     new_video_1080p = subprocess.call([FFMPEG_PATH, &#x27;-i&#x27;, input_file_path, &#x27;-s&#x27;, &#x27;1920x1080&#x27;, &#x27;-vcodec&#x27;, &#x27;mpeg4&#x27;, &#x27;-acodec&#x27;, &#x27;libvo_aacenc&#x27;, &#x27;-b&#x27;, &#x27;10000k&#x27;, &#x27;-pass&#x27;, i, &#x27;-r&#x27;, &#x27;30&#x27;, output_file_path])&#xA;backend-celery-1  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&#xA;backend-celery-1  |   File "/usr/local/lib/python3.11/subprocess.py", line 389, in call&#xA;backend-celery-1  |     with Popen(*popenargs, **kwargs) as p:&#xA;backend-celery-1  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^&#xA;backend-celery-1  |   File "/usr/local/lib/python3.11/subprocess.py", line 1026, in __init__&#xA;backend-celery-1  |     self._execute_child(args, executable, preexec_fn, close_fds,&#xA;backend-celery-1  |   File "/usr/local/lib/python3.11/subprocess.py", line 1883, in _execute_child&#xA;backend-celery-1  |     self.pid = _fork_exec(&#xA;backend-celery-1  |                ^^^^^^^^^^^&#xA;backend-celery-1  | TypeError: expected str, bytes or os.PathLike object, not int&#xA;backend-celery-1  | &#xA;backend-celery-1  | During handling of the above exception, another exception occurred:&#xA;backend-celery-1  | &#xA;backend-celery-1  | Traceback (most recent call last):&#xA;backend-celery-1  |   File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 477, in trace_task&#xA;backend-celery-1  |     R = retval = fun(*args, **kwargs)&#xA;backend-celery-1  |                  ^^^^^^^^^^^^^^^^^^^^&#xA;backend-celery-1  |   File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 760, in __protected_call__&#xA;backend-celery-1  |     return self.run(*args, **kwargs)&#xA;backend-celery-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^&#xA;backend-celery-1  |   File "/usr/src/backend/video/tasks.py", line 93, in task_video_encoding_1080p&#xA;backend-celery-1  |     raise ValidationError(&#x27;Something went wrong&#x27;)&#xA;backend-celery-1  | django.core.exceptions.ValidationError: [&#x27;Something went wrong&#x27;]&#xA;

    &#xA;

    If anyone has done this kind of project or something like this please any suggestion or help is much appreciated.

    &#xA;

    Thank you in advance !

    &#xA;