
Recherche avancée
Médias (1)
-
Rennes Emotion Map 2010-11
19 octobre 2011, par
Mis à jour : Juillet 2013
Langue : français
Type : Texte
Autres articles (71)
-
Amélioration de la version de base
13 septembre 2013Jolie sélection multiple
Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...) -
Mise à jour de la version 0.1 vers 0.2
24 juin 2013, parExplications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...) -
De l’upload à la vidéo finale [version standalone]
31 janvier 2010, parLe chemin d’un document audio ou vidéo dans SPIPMotion est divisé en trois étapes distinctes.
Upload et récupération d’informations de la vidéo source
Dans un premier temps, il est nécessaire de créer un article SPIP et de lui joindre le document vidéo "source".
Au moment où ce document est joint à l’article, deux actions supplémentaires au comportement normal sont exécutées : La récupération des informations techniques des flux audio et video du fichier ; La génération d’une vignette : extraction d’une (...)
Sur d’autres sites (8900)
-
FFmpeg avcodec_open2 throws -22 ("Invalid Argument")
14 avril 2023, par stupidbutseekingI got stuck trying to write a simple video conversion using C++ and ffmpeg.


When trying to convert a video using FFmpeg, calling avcodec_open2 fails with the code "-22" which seems to be an "Invalid Argument"-error.


I can't figure out why it fails, nor what the invalid argument is. In the following snippet I create the output codec and pass its context the information from the source (code further down below).


The check for the "outputCodec" works and does not throw an error. As far as I know an "AVDictionary"-argument is optional. So I guess the reason for the error is the context.


const AVCodec* outputCodec = avcodec_find_encoder_by_name(codecName.c_str());

 if (!outputCodec)
 {
 std::cout << "Zielformat-Codec nicht gefunden" << std::endl;
 return -1;
 }

 AVCodecContext* outputCodecContext = avcodec_alloc_context3(outputCodec);
 outputCodecContext->bit_rate = bitRate;
 outputCodecContext->width = inputCodecContext->width;
 outputCodecContext->height = inputCodecContext->height;
 outputCodecContext->pix_fmt = outputCodec->pix_fmts[0];
 outputCodecContext->time_base = inputCodecContext->time_base;

 **int errorCode = avcodec_open2(outputCodecContext, outputCodec, NULL); //THIS RETURNS -22**
 if (errorCode != 0)
 {
 std::cout << "Fehler beim Öffnen des Zielformat-Codecs" << std::endl;
 return -1;
 }



Here is the code for getting the input file & context :


std::string inputFilename = "input_video.mp4";
 std::string outputFilename = "output.avi";
 std::string codecName = "mpeg4";
 int bitRate = 400000;

 AVFormatContext* inputFormatContext = NULL;
 if (avformat_open_input(&inputFormatContext, inputFilename.c_str(), NULL, NULL) != 0)
 {
 std::cout << "Fehler beim Öffnen der Eingabedatei" << std::endl;
 return -1;
 }

 [Do Video Stream Search)

 AVCodecParameters* inputCodecParameters = inputFormatContext->streams[videoStreamIndex]->codecpar;
 const AVCodec* inputCodec = avcodec_find_decoder(inputCodecParameters->codec_id);
 AVCodecContext* inputCodecContext = avcodec_alloc_context3(inputCodec);
 if (avcodec_parameters_to_context(inputCodecContext, inputCodecParameters) != 0)
 {
 std::cout << "Fehler beim Setzen des Eingabecodecs" << std::endl;
 return -1;
 }
 if (avcodec_open2(inputCodecContext, inputCodec, NULL) != 0)
 {
 std::cout << "Fehler beim Öffnen des Eingabecodecs" << std::endl;
 return -1;
 }



The purpose was simply to get started with ffmpeg in an own C++ project.


If it is of any need, I downloaded the ffmpeg libs from here. I used the gpl shared ones. The architecture is win x64. I referenced them through the project properties (additional libraries and so on).


I tried to convert a .mp4 video to an .avi video with an "mpeg4" compression.
I also tried other compressions like "libx264" but none worked.


I searched for the problem on stackoverflow but could not find the exact same problem. While its purpose is different this post is about the same error code when calling avcodec_open2. But its solution is not working for me. I inspected the watch for the "outputContext" while running the code and the codec_id, codec_type and format is set. I use the time_base from the input file. According to my understanding, this should be equal to the source. So I can not find out what I am missing.


Thanks in advance and sorry for my english.


And for completion, here is the whole method :


int TestConvert()
{
 std::string inputFilename = "input_video.mp4";
 std::string outputFilename = "output.avi";
 std::string codecName = "mpeg4";
 int bitRate = 400000;

 AVFormatContext* inputFormatContext = NULL;
 if (avformat_open_input(&inputFormatContext, inputFilename.c_str(), NULL, NULL) != 0)
 {
 std::cout << "Fehler beim Öffnen der Eingabedatei" << std::endl;
 return -1;
 }

 int videoStreamIndex = -1;
 for (unsigned int i = 0; i < inputFormatContext->nb_streams; i++)
 {
 if (inputFormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 {
 videoStreamIndex = i;
 break;
 }
 }

 AVCodecParameters* inputCodecParameters = inputFormatContext->streams[videoStreamIndex]->codecpar;
 const AVCodec* inputCodec = avcodec_find_decoder(inputCodecParameters->codec_id);
 AVCodecContext* inputCodecContext = avcodec_alloc_context3(inputCodec);
 if (avcodec_parameters_to_context(inputCodecContext, inputCodecParameters) != 0)
 {
 std::cout << "Fehler beim Setzen des Eingabecodecs" << std::endl;
 return -1;
 }
 if (avcodec_open2(inputCodecContext, inputCodec, NULL) != 0)
 {
 std::cout << "Fehler beim Öffnen des Eingabecodecs" << std::endl;
 return -1;
 }

 const AVCodec* outputCodec = avcodec_find_encoder_by_name(codecName.c_str());

 if (!outputCodec)
 {
 std::cout << "Zielformat-Codec nicht gefunden" << std::endl;
 return -1;
 }

 AVCodecContext* outputCodecContext = avcodec_alloc_context3(outputCodec);
 outputCodecContext->bit_rate = bitRate;
 outputCodecContext->width = inputCodecContext->width;
 outputCodecContext->height = inputCodecContext->height;
 outputCodecContext->pix_fmt = outputCodec->pix_fmts[0];
 outputCodecContext->time_base = inputCodecContext->time_base;

 int errorCode = avcodec_open2(outputCodecContext, outputCodec, NULL);
 if (errorCode != 0)
 {
 std::cout << "Fehler beim Öffnen des Zielformat-Codecs" << std::endl;
 return -1;
 }

 AVFormatContext* outputFormatContext = NULL;
 if (avformat_alloc_output_context2(&outputFormatContext, NULL, NULL, outputFilename.c_str()) != 0)
 {
 std::cout << "Fehler beim Erstellen des Ausgabe-Formats" << std::endl;
 return -1;
 }

 AVStream* outputVideoStream = avformat_new_stream(outputFormatContext, outputCodec);
 if (outputVideoStream == NULL)
 {
 std::cout << "Fehler beim Hinzufügen des Video-Streams zum Ausgabe-Format" << std::endl;
 return -1;
 }
 outputVideoStream->id = outputFormatContext->nb_streams - 1;
 AVCodecParameters* outputCodecParameters = outputVideoStream->codecpar;
 if (avcodec_parameters_from_context(outputCodecParameters, outputCodecContext) != 0)
 {
 std::cout << "Fehler beim Setzen des Ausgabe-Codecs" << std::endl;
 return -1;
 }

 if (!(outputFormatContext->oformat->flags & AVFMT_NOFILE))
 {
 if (avio_open(&outputFormatContext->pb, outputFilename.c_str(), AVIO_FLAG_WRITE) != 0)
 {
 std::cout << "Fehler beim Öffnen der Ausgabedatei" << std::endl;
 return -1;
 }
 }

 if (avformat_write_header(outputFormatContext, NULL) != 0)
 {
 std::cout << "Fehler beim Schreiben des Ausgabe-Formats in die Ausgabedatei" << std::endl;
 return -1;
 }

 AVPacket packet;
 int response;
 AVFrame* frame = av_frame_alloc();
 AVFrame* outputFrame = av_frame_alloc();
 while (av_read_frame(inputFormatContext, &packet) == 0)
 {
 if (packet.stream_index == videoStreamIndex)
 {
 response = avcodec_send_packet(inputCodecContext, &packet);
 while (response >= 0)
 {
 response = avcodec_receive_frame(inputCodecContext, frame);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
 {
 break;
 }
 else if (response < 0)
 {
 std::cout << "Fehler beim Dekodieren des Video-Pakets" << std::endl;
 return -1;
 }

 struct SwsContext* swsContext = sws_getContext(inputCodecContext->width, inputCodecContext->height, inputCodecContext->pix_fmt, outputCodecContext->width, outputCodecContext->height, outputCodecContext->pix_fmt, SWS_BILINEAR, NULL, NULL, NULL); if (!swsContext)
 {
 std::cout << "Fehler beim Erstellen des SwsContext" << std::endl;
 return -1;
 }
 sws_scale(swsContext, frame->data, frame->linesize, 0, inputCodecContext->height, outputFrame->data, outputFrame->linesize);
 sws_freeContext(swsContext);

 outputFrame->pts = frame->pts;
 outputFrame->pkt_dts = frame->pkt_dts;
 //outputFrame->pkt_duration = frame->pkt_duration;
 response = avcodec_send_frame(outputCodecContext, outputFrame);
 while (response >= 0)
 {
 response = avcodec_receive_packet(outputCodecContext, &packet);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
 {
 break;
 }
 else if (response < 0)
 {
 std::cout << "Fehler beim Kodieren des Ausgabe-Frames" << std::endl;
 return -1;
 }

 packet.stream_index = outputVideoStream->id;
 av_packet_rescale_ts(&packet, outputCodecContext->time_base, outputVideoStream->time_base);
 if (av_interleaved_write_frame(outputFormatContext, &packet) != 0)
 {
 std::cout << "Fehler beim Schreiben des Ausgabe-Pakets" << std::endl;
 return -1;
 }
 av_packet_unref(&packet);
 }
 }
 }
 av_packet_unref(&packet);
 }

 av_write_trailer(outputFormatContext);
 avcodec_free_context(&inputCodecContext);
 avcodec_free_context(&outputCodecContext);
 avformat_close_input(&inputFormatContext);
 avformat_free_context(inputFormatContext);
 avformat_free_context(outputFormatContext);
 av_frame_free(&frame);
 av_frame_free(&outputFrame);

 return 0;

}



-
10 Matomo Features You Possibly Didn’t Know About
28 octobre 2022, par Erin -
Android, AOSP tree, external project (ffmpeg) is built for AMD64
22 avril 2015, par kagali-sanI’m trying to build ffmpeg4android on current AOSP tree (from /external), which is lunch-configured to aosp_arm-eng and set to
PLATFORM_VERSION=4.2
.Resulting files are generated for
AMD64
(host native) architecture, even though the major rest of tree is built (as expected)ARM
:readelf -a android/aosp_arm-eng/ffplay|egrep "Class :|Machine :"
Class : ELF64 Machine :
Advanced Micro Devices X86-64versus
readelf -a
aosp/out/target/product/generic/symbols/system/lib/libril.so | egrep "Class :|Machine :"Class : ELF32
Machine : ARM
I will probably switch to other ways of getting
ffmpeg-arm
(presumably the one described here) ; the reason of asking this question is to understand, at which build stage does cross-compilation environment breaks.