
Recherche avancée
Autres articles (112)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Websites made with MediaSPIP
2 mai 2011, parThis page lists some websites based on MediaSPIP.
-
Creating farms of unique websites
13 avril 2011, parMediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)
Sur d’autres sites (15305)
-
AVPacket->Data is empty "0/0" but has size
24 juin 2024, par CottonBudsI am using libAV* to encode frames(unsigned char*) from my streaming application. I encoded my initialized frames but when I tried to get the avpacket. it returns an avpacket with a size but without data inside it "0/0"


here is my code


StreamCodec.h



class StreamCodec : public QObject 
{
 Q_OBJECT
public:
 StreamCodec(int height, int width, int fps);

public slots:
 void encodeFrame(std::shared_ptr<uchar> pData);
 void run();

signals:
 void encodeFinish(AVPacket* packet);

private:
 void initializeSWS();
 void initializeCodec();

 AVPacket* allocatepacket(AVFrame* frame);
 AVFrame* allocateFrame(std::shared_ptr<uchar> pData);
 AVFrame* formatFrame(AVFrame* frame);

 const AVCodec* codec;
 AVCodecContext* context;
 SwsContext *swsContext;
 int bytesPerPixel;
 int width;
 int height;
 int fps;
 int pts = 0;
};

</uchar></uchar>


StreamCodec.cpp


StreamCodec::StreamCodec(int height, int width, int fps)
{
 this->height = height;
 this->width = width;
 this->fps = fps;
}

void StreamCodec::initializeCodec()
{
 codec = avcodec_find_encoder(AV_CODEC_ID_H264);
 if (!codec) {
 qDebug() << "Codec not found";
 exit(1);
 }
 
 context = avcodec_alloc_context3(codec);
 if (!context) {
 qDebug() << "Could not allocate codec context";
 exit(1);
 }

 context->height = height;
 context->width = width;
 context->time_base.num = 1;
 context->time_base.den = fps;
 context->framerate.num = fps;
 context->framerate.den = 1;
 context->pix_fmt = AV_PIX_FMT_YUV420P;

 context->gop_size = 0;

 av_opt_set(context->priv_data, "preset", "ultrafast", 0);
 av_opt_set(context->priv_data, "crf", "35", 0);
 av_opt_set(context->priv_data, "tune", "zerolatency", 0);

 auto desc = av_pix_fmt_desc_get(AV_PIX_FMT_BGRA);
 if (!desc){
 qDebug() << "Can't get descriptor for pixel format";
 exit(1);
 }
 bytesPerPixel = av_get_bits_per_pixel(desc) / 8;
 if(av_get_bits_per_pixel(desc) % 8 != 0){
 qDebug() << "Unhandled bits per pixel, bad in pix fmt";
 exit(1);
 }

 int err = avcodec_open2(context, codec, nullptr);
 if (err < 0) {
 qDebug() << "Could not open codec";
 exit(1);
 }
}
void StreamCodec::initializeSWS()
{
 swsContext = sws_getContext(width, height, AV_PIX_FMT_BGRA, width, height, AV_PIX_FMT_YUV420P, SWS_BILINEAR, NULL, NULL, NULL);
 if (!swsContext) {
 qDebug() << "Could not allocate SWS Context";
 exit(1);
 }
}

void StreamCodec::encodeFrame(std::shared_ptr<uchar> pData)
{
 int err = 0;
 AVFrame* frame1 = allocateFrame(pData);
 AVFrame* frame = formatFrame(frame1);

 err = avcodec_send_frame(context, frame);
 if (err < 0) {
 qDebug() << "Error sending frame to codec";
 char* errStr = new char;
 av_make_error_string(errStr, 255, err);
 qDebug() << errStr;
 av_frame_free(&frame);
 exit(1);
 }

 while (true) {
 AVPacket* packet = allocatepacket(frame);
 err = avcodec_receive_packet(context, packet);
 if (err == AVERROR_EOF || err == AVERROR(EAGAIN) ) {
 av_packet_unref(packet);
 av_packet_free(&packet);
 break;
 }
 if (err < 0) {
 qDebug() << "Error recieving to codec";
 char* errStr = new char;
 av_make_error_string(errStr, 255, err);
 qDebug() << errStr;
 av_frame_free(&frame);
 av_frame_free(&frame1);
 av_packet_free(&packet);
 exit(1);
 }
 emit encodeFinish(packet);
 }

 av_frame_free(&frame);
 av_frame_free(&frame1);
}

void StreamCodec::run()
{
 initializeCodec();
 initializeSWS();
}

AVPacket* StreamCodec::allocatepacket(AVFrame* frame)
{
 AVPacket* packet = av_packet_alloc();
 if (!packet) {
 qDebug() << "Could not allocate memory for packet";
 av_frame_free(&frame);
 exit(1);
 }
 return packet;
}

AVFrame* StreamCodec::allocateFrame(std::shared_ptr<uchar> pData)
{
 AVFrame* frame = av_frame_alloc();
 if (!frame) {
 qDebug() << "Could not allocate memory for frame";
 exit(1);
 }

 frame->format = AV_PIX_FMT_BGRA;
 frame->width = width;
 frame->height = height;
 frame->pts = pts;

 if (av_frame_get_buffer(frame, 0) < 0) {
 qDebug() << "Failed to get frame buffer";
 exit(1);
 }

 if (av_frame_make_writable(frame) < 0) {
 qDebug() << "Failed to make frame writable";
 exit(1);
 }

 frame->data[0] = pData.get();

 return frame;
}

AVFrame* StreamCodec::formatFrame(AVFrame* frame)
{
 AVFrame* yuvFrame = av_frame_alloc();
 if (!yuvFrame) {
 qDebug() << "Unable to allocate memory for yuv frame";
 av_frame_free(&frame);
 exit(1);
 }

 yuvFrame->format = context->pix_fmt;
 yuvFrame->width = width;
 yuvFrame->height = height;
 yuvFrame->pts = pts;
 pts += 1;
 
 if (av_frame_get_buffer(yuvFrame, 0) < 0) {
 qDebug() << "Failed to get frame buffer";
 exit(1);
 }

 if (av_frame_make_writable(yuvFrame) < 0) {
 qDebug() << "Failed to make frame writable";
 exit(1);
 }

 int err = sws_scale(swsContext, (const uint8_t* const*)frame->data, frame->linesize, 0, height, (uint8_t* const*)yuvFrame->data, yuvFrame->linesize);
 if (err < 0) {
 qDebug() << "Could not format frame to yuv420p";
 exit(1);
 }
 return yuvFrame;
}


</uchar></uchar>


I tried checking for the frames and I'm pretty sure the data is there. I just dont know what to do at this point.


edit 1


I tried viewing the data using visual studio code "view" button it showed me this




Thank you so much to all that commented and pointed me to the right direction.


-
ffmpeg - data is being "removed" while h264 is being processed by ffmpeg
21 mai 2024, par LakiI got a file which is created based on messages coming from streaming, all of the "messages" are ending with b'h264\x00'
I got a need to


- 

- load the data into ffmpeg
- perform some processing of the data
- re-attach the data to same "messages"








Data is loaded with ffmpeg and saved with ffmpeg - however - ffmpeg removes "part" of the data
I have simplified the process and currently I am only loading and saving the data, without any processing, but still - part of the data is being removed


I have used several commands - but always, part of my data is being removed


ffmpeg -i sthg3.h264 -c copy st3.h264
ffmpeg -err_detect ignore_err -i sthg3.h264 -c copy st3.h264
ffmpeg -fflags +genpts -i sthg3.h264 -c copy st3.h264 



I have created the script for calculating that


file_out = 'sthg3.h264'
def split_file(input_file,chunki):
 output_files = []
 with open(input_file, 'rb') as f:
 file_number = 0
 while True:
 chunk = f.read(504096) # Read a chunk of data
 if not chunk: # End of file
 break
 index = chunk.find(chunki) # Find the delimiter
 while index != -1:
 chunk = chunk[index+len(chunki):]
 file_number += 1
 index = chunk.find(chunki) # Find the next delimiter
 return file_number

chunki = b'h264\x00'
print(split_file(file_out,chunki))
chunki = b'\x00\x01\x00'
print(split_file(file_out,chunki))
 
chunki = b'h264\x00'
#chunki = b'\x00\x00\xdc\x9e'
print(split_file('st3.h264',chunki))
chunki = b'\x00\x01\x00'
print(split_file('st3.h264',chunki))



and here is the question, how to push data through ffmpeg to avoid removing data, or replace it with something that would not be removed ?


-
java.io.IOException : Cannot run program "/data/user/0/com.voi.myapplication8/files/ffmpeg" : error=13, Permission denied
1er avril 2024, par Harsha

java.io.IOException : Cannot run program
"/data/user/0/com.voi.myapplication8/files/ffmpeg" : error=13,
Permission denied




I am using this dependencies
implementation 'com.writingminds:FFmpegAndroid:0.3.2'




2024-03-31 21:40:31.045 15937-16762 FFmpeg

com.voi.myapplication8 E Exception while trying to run :
[Ljava.lang.String ;@71d4c0f
java.io.IOException : Cannot run program
"/data/user/0/com.voi.myapplication8/files/ffmpeg" : error=13,
Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
at java.lang.Runtime.exec(Runtime.java:712)
at java.lang.Runtime.exec(Runtime.java:571)
at
com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10)
at
com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38)
at
com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10)
at android.os.AsyncTask$3.call(AsyncTask.java:394)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
Caused by : java.io.IOException : error=13, Permission denied
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(UNIXProcess.java:133)
at java.lang.ProcessImpl.start(ProcessImpl.java:141)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:712) 
at java.lang.Runtime.exec(Runtime.java:571) 
at
com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10) 
at
com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38) 
at
com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10) 
at android.os.AsyncTask$3.call(AsyncTask.java:394) 
at java.util.concurrent.FutureTask.run(FutureTask.java:264) 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) 
at java.lang.Thread.run(Thread.java:1012) 2024-03-31 21:40:31.045
15937-15937 FFmpeg com.voi.myapplication8

E Video cropping failed :