
Recherche avancée
Médias (1)
-
Bug de détection d’ogg
22 mars 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Video
Autres articles (65)
-
La file d’attente de SPIPmotion
28 novembre 2010, parUne file d’attente stockée dans la base de donnée
Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...) -
MediaSPIP v0.2
21 juin 2013, parMediaSPIP 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, parMediaSPIP 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 (...)
Sur d’autres sites (12219)
-
ffmpeg avcodec_send_packet fail after several frames
8 janvier 2024, par XingdiI am trying to use ffmpeg to decode a video stream and convert to Opencv
cv::Mat
.

I found this piece of code and made it compiled. Howerver, the decoding process will always fail after several frames. The call to
avcodec_send_packet
return error code-11
.

I do now know what the problem is. I am sure the video stream and my FFmpeg is ok. I can transcode the stream video using ffmpeg command line.


The error always happen on


error = avcodec_send_packet(videoCodecContext, &packet);



#include <iostream>
#include <string>
#include <vector>

extern "C" {
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>imgutils.h>
#include <libswscale></libswscale>swscale.h>
#include <libavcodec></libavcodec>avcodec.h>
}


#include <opencv2></opencv2>opencv.hpp>

// helper function to check for FFmpeg errors
inline void checkError(int error, const std::string& message) {
 if (error < 0) {
 //std::cerr << message << ": " << av_err2str(error) << std::endl; //error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conv>
 std::cerr << message << ": " << std::to_string(error) << std::endl;
 exit(EXIT_FAILURE);
 }
}

int main() {
 // initialize FFmpeg
 av_log_set_level(AV_LOG_ERROR);
 avformat_network_init();

 // open the input file
 std::string fileName = "rtsp://xyz@192.168.15.112:554//Streaming/Channels/101";
 AVFormatContext* formatContext = nullptr;
 int error = avformat_open_input(&formatContext, fileName.c_str(), nullptr, nullptr);
 checkError(error, "Error opening input file");

 //Read packets of a media file to get stream information.
 ////////////////////////////////////////////////////////////////////////////
 error = avformat_find_stream_info(formatContext, nullptr);
 checkError(error, "Error avformat find stream info");
 ////////////////////////////////////////////////////////////////////////////


 // find the video stream
 AVStream* videoStream = nullptr;
 for (unsigned int i = 0; i < formatContext->nb_streams; i++) {
 if (formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && !videoStream) {
 videoStream = formatContext->streams[i];
 }
 }
 if (!videoStream) {
 std::cerr << "Error: input file does not contain a video stream" << std::endl;
 exit(EXIT_FAILURE);
 }

 // create the video codec context
 const AVCodec* videoCodec = avcodec_find_decoder(videoStream->codecpar->codec_id);
 AVCodecContext* videoCodecContext = avcodec_alloc_context3(videoCodec);
 if (!videoCodecContext) {
 std::cerr << "Error allocating video codec context" << std::endl;
 exit(EXIT_FAILURE);
 }
 error = avcodec_parameters_to_context(videoCodecContext, videoStream->codecpar);
 checkError(error, "Error setting video codec context parameters");
 error = avcodec_open2(videoCodecContext, videoCodec, nullptr);
 checkError(error, "Error opening video codec");

 // create the frame scaler
 int width = videoCodecContext->width;
 int height = videoCodecContext->height;

 std::cout<<"frame width:" << width << std::endl;
 std::cout<<"frame height:" << height << std::endl;
 std::cout<<"frame pix fmt:" << videoCodecContext->pix_fmt << std::endl;

 struct SwsContext* frameScaler = sws_getContext(width, height, videoCodecContext->pix_fmt, width, height, AV_PIX_FMT_BGR24, SWS_BICUBIC, nullptr, nullptr, nullptr);

 // read the packets and decode the video frames
 std::vector videoFrames;
 AVPacket packet;
 int i=0;
 while (av_read_frame(formatContext, &packet) == 0) {
 std::cout<<"frame number:"<< i++ <index) {
 // decode the video frame
 AVFrame* frame = av_frame_alloc();
 int gotFrame = 0;
 error = avcodec_send_packet(videoCodecContext, &packet);
 checkError(error, "Error sending packet to video codec");
 if (error<0) {
 continue;
 }
 error = avcodec_receive_frame(videoCodecContext, frame);

 //There is not enough data for decoding the frame, have to free and get more data
 ////////////////////////////////////////////////////////////////////////////
 if (error == AVERROR(EAGAIN))
 {
 av_frame_unref(frame);
 av_freep(frame);
 continue;
 }

 if (error == AVERROR_EOF)
 {
 std::cerr << "AVERROR_EOF" << std::endl;
 break;
 }
 ////////////////////////////////////////////////////////////////////////////

 checkError(error, "Error receiving frame from video codec");


 if (error == 0) {
 gotFrame = 1;
 }
 if (gotFrame) {
 // scale the frame to the desired format
 AVFrame* scaledFrame = av_frame_alloc();
 av_image_alloc(scaledFrame->data, scaledFrame->linesize, width, height, AV_PIX_FMT_BGR24, 32);
 sws_scale(frameScaler, frame->data, frame->linesize, 0, height, scaledFrame->data, scaledFrame->linesize);
 // copy the frame data to a cv::Mat object
 cv::Mat mat(height, width, CV_8UC3, scaledFrame->data[0], scaledFrame->linesize[0]);

 //Show mat image for testing
 ////////////////////////////////////////////////////////////////////////////
 //cv::imshow("mat", mat);
 //cv::waitKey(100); //Wait 100msec (relativly long time - for testing).
 ////////////////////////////////////////////////////////////////////////////


 videoFrames.push_back(mat.clone());

 // clean up
 av_freep(&scaledFrame->data[0]);
 av_frame_free(&scaledFrame);
 }
 av_frame_free(&frame);
 }
 av_packet_unref(&packet);
 }

 // clean up
 sws_freeContext(frameScaler);
 avcodec_free_context(&videoCodecContext);
 avformat_close_input(&formatContext);

 return 0;
}
</vector></string></iostream>


-
Android Merging two video with different (sizes,codec,frames,aspect raito) using FFMPEG
6 septembre 2017, par Alok Kumar VermaI’m making an app which merges two or more than two video files which I’m getting from another activity. After choosing the files we pass the files to another activity where the merging happens. I’ve followed this link to do the same : AndroidWarZone FFMPEG
Here I found the way on how to merge the two files only with different qualities. The command is given below :
String[] complexCommand = {"ffmpeg","-y","-i","/storage/emulated/0/videokit/sample.mp4",
"-i","/storage/emulated/0/videokit/in.mp4","-strict","experimental",
"-filter_complex",
"[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
"-ab","48000","-ac","2","-ar","22050","-s","640x480","-r","30","-vcodec","mpeg4","-b","2097k","/storage/emulated/0/vk2_out/out.mp4"}Since I have a list of selected videos inside my array which I’m passing to the next page, I’ve done some changes in my command, like this :
private void mergeVideos() {
String savingPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/video.mp4";
ArrayList<file> fileList = mList;
List<string> filenames = new ArrayList<string>();
for (int i = 0; i < fileList.size(); i++) {
filenames.add("-i");
filenames.add(fileList.get(i).toString());
}
Log.e("Log===",filenames.toString());
String joined = TextUtils.join(", ",filenames);
Log.e("Joined====",joined);
String complexCommand[] = {"-y", joined,
"-filter_complex",
"[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
"-ab","48000","-ac","2","-ar","22050","-s","640x480","-r","30","-vcodec","mpeg4","-b","2097k", savingPath};
Log.e("RESULT====",Arrays.toString(complexCommand));
execFFmpegBinary(complexCommand); }
</string></string></file>In the log this is the the output I’m getting :
This one is for received data which I have added in the mList
E/RECEIVED DATA=====: [/mnt/m_external_sd/DCIM/Camera/VID_31610130_011933_454.mp4, /mnt/m_external_sd/DCIM/Camera/VID_23120824_054526_878.mp4]
E/RESULT====: [-y, -i, /mnt/m_external_sd/DCIM/Camera/VID_31610130_011933_454.mp4, -i, /mnt/m_external_sd/DCIM/Camera/VID_23120824_054526_878.mp4, -filter_complex, [0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1, -ab, 48000, -ac, 2, -ar, 22050, -s, 640x480, -r, 30, -vcodec, mpeg4, -b, 2097k, /storage/emulated/0/video.mp4]Here result is the complexCommand that is going inside the exeFFMPEGBinary() but not working.
This is my exceFFMPEGBinary()
private void execFFmpegBinary(final String[] combine) {
try{
fFmpeg.execute(combine, new ExecuteBinaryResponseHandler() {
@Override
public void onFailure(String s) {
Log.d("", "FAILED with output : " + s);
}
@Override
public void onSuccess(String s) {
Log.d("", "SUCCESS with output : " + s);
Toast.makeText(getApplicationContext(),"Success!",Toast.LENGTH_SHORT)
.show();
}
@Override
public void onProgress(String s) {
Log.d("", "progress : " + s);
}
@Override
public void onStart() {
progressDialog.setMessage("Processing...");
progressDialog.show();
}
@Override
public void onFinish() {
progressDialog.dismiss();
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
}
}I’ve done this and run my project, now the problem is it is not merging/concatenating anything, just a progressDialog comes up for a fraction of second and all I’m getting is this in my log :
E/FFMPEG====: ffmpef : coorect loaded
This means that ffmpeg is loading and nothing is getting implemented. I don’t get any log for onFailur, onSuccess(), onStart().
Any suggestions would help me achieve my goal. Thanks.
Note : I have done this merging with the use of Mp4Parser but there is a glitch inside it, it requires the file with same specification. So this is not my requirement.
EDITS
I did some more research and got this to concatenate, but this is not working either, here is the link : Concatenating two files
I’ve found this stuff also from a link : FFMPEG Merging/Concatenating
and found that his piece of code is working fine. But not mine.I’ve used that command also but it is not working nor giving me any log results. Except the FFMPEG Loading.
Here is the command :
complexCommand = new String[]{"-y", "-i", file1.toString(), "-i", file2.toString(), "-strict", "experimental", "-filter_complex",
"[0:v]scale=1920x1080,setsar=1:1[v0];[1:v] scale=iw*min(1920/iw\\,1080/ih):ih*min(1920/iw\\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\\,1080/ih))/2:(1080-ih*min(1920/iw\\,1080/ih))/2,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1","-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "1920x1080", "-vcodec", "libx264","-crf","27","-q","4","-preset", "ultrafast", rootPath + "/output.mp4"}; -
Revision 35436 : Petites pétouilles en passant par là (écriture aux dernières normes ...
22 février 2010, par marcimat@… — LogPetites pétouilles en passant par là (écriture aux dernières normes ISO)…