
Recherche avancée
Autres articles (44)
-
HTML5 audio and video support
13 avril 2011, parMediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
For older browsers the Flowplayer flash fallback is used.
MediaSPIP allows for media playback on major mobile platforms with the above (...) -
Support audio et vidéo HTML5
10 avril 2011MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...) -
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 (8094)
-
How would I send x264 encoded frames correctly over a network using UDP ?
5 avril 2020, par Eoin McBennettI'm trying to send the encoded h264 frames I have over a network as I get them, currently I'm only streaming the nal units I get from each frame as it is encoded, is this the correct approach ?



I wrote a receiver application on a different computer to get the nals and wrote them all to a file sequentially, when played with vlc I didn't get any video and instead just got a screeching noise. I'm not sure exactly where the problem would lie here. I have included the result of the FFmpeg -I command on the file created.



Encoder and sender code




 //Udp initialisation
 struct sockaddr_in broadcastAddr;
 int sock;
 int yes = 1;
 int addr_len;
 int count;
 fd_set readfd;
 char buffer[1024];
 int i;

 sock = socket(AF_INET, SOCK_DGRAM,0);

 if(sock < 0){
 std::cout << "Failed to initialise socket!" << std::endl;
 }

 int ret = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*)&yes, sizeof(yes));
 if(ret < 0){
 std::cout << "setsockopt error!" </ the size of the address

 memset((void*)&broadcastAddr,0,addr_len); //0 out the address bits

 broadcastAddr.sin_family = AF_INET;
 broadcastAddr.sin_addr.s_addr = INADDR_BROADCAST;
 broadcastAddr.sin_port = PORT;



 //Set the encoder parameters
 x264_param_t param;
 x264_param_default_preset(&param,"veryfast","zerolatency");
 param.i_threads = 1;
 param.i_width = camera.getWidth();
 param.i_height = camera.getHeight();
 param.i_fps_num = 30;
 param.i_fps_den = 1;
// Intra refres:
 param.i_keyint_max = 30;
 param.b_intra_refresh = 1;
//Rate control:
 param.rc.i_rc_method = X264_RC_CRF;
 param.rc.f_rf_constant = 25;
 param.rc.f_rf_constant_max = 35;
//For streaming:
 param.b_repeat_headers = 1;
 param.b_annexb = 1;
 x264_param_apply_profile(&param, "baseline");

 x264_t *encoder = x264_encoder_open(&param); //H.264 encoder object
 x264_picture_t pic_in, pic_out;
 x264_picture_alloc(&pic_in, X264_CSP_I420,camera.getWidth(), camera.getHeight());

 //Network abstraction layer units for broadcast
 x264_nal_t *nals;
 int i_nals;

 while(true){

 //If there is valid data in the processing queue
 if(!encoderQueue.empty()){

 //File the x264 input data structure with the file data
 fillImage(encoderQueue.front(),camera.getWidth(),camera.getHeight(),&pic_in);

 //Encode and send
 int frame_size = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out);
 if (frame_size >= 0) {
 //The frame is ready to be sent over UDP!
 for(int i = 0; i < i_nals; i++){
 ret = sendto(sock, &nals[0].p_payload, frame_size,0,(struct sockaddr*)&broadcastAddr,addr_len);
 if(ret > 0){
 std::cout << "Streamed frame nal unit " << i << std::endl;
 } else{
 std::cout << "Failed to stream nal unit " << i << std::endl;
 }
 }
 }
 else{
 std::cout<<"Failed to encode h264 frame!" << std::endl;
 }
 //Finsihed with the current frame, pop it off the queue and remove any nals to do with it
 encoderQueue.pop();
 frame_size = 0;
 nals = nullptr;
 i_nals = 0;
 }


 }




Receiver application



#include <iostream>
#include 
#include <network></network>Network.h>
#include <netinet></netinet>in.h>
#include <arpa></arpa>inet.h>
#include <sys></sys>types.h>
#include <sys></sys>socket.h>
#include <queue>


#define BUFFER_LEN 10000
#define PORT_NO 3879



int main(int argc, const char * argv[]) {


 FILE *file; //File to write the h264 nals too

 //Declare the address memory space
 struct sockaddr_in sockAddr , bcAddr;
 socklen_t bcAddr_len = sizeof(&bcAddr); //Store the length of the broadcast address structure
 //0 out the assigned memory
 memset(&sockAddr, 0, sizeof(sockAddr));
 memset(&bcAddr, 0 ,sizeof(bcAddr));

 //Set the address parameters to look for incoming IpV4/UDP data
 sockAddr.sin_family = AF_INET;
 sockAddr.sin_port = htons(PORT_NO);
 sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);

 bcAddr.sin_family = AF_INET;
 bcAddr.sin_port = PORT_NO;
 inet_aton("255.255.255.255",&bcAddr.sin_addr);

 //Initialise a udp socket to read broadcast bytes
 int soc = socket(AF_INET, SOCK_DGRAM,0);

 //Check socket init
 if(soc < 0){
 std::cout << "Failed to initialise UDP socket!" << std::endl;
 return -1;
 }

 //Bind the address details to the socket, check for errors
 if(bind(soc, (struct sockaddr*)&sockAddr, sizeof(sockAddr)) < 0){
 std::cout << "Failed to bind address structure to socket!" << std::endl;
 return -2;
 }

 file = fopen("stream.h264","wb"); // Open the file for writing

 unsigned char buffer[BUFFER_LEN];

 while(true){


 memset(&buffer, 0, sizeof(unsigned char) * BUFFER_LEN);

 int recv_len = recvfrom(soc, buffer, BUFFER_LEN, 0, (struct sockaddr *)&bcAddr, &bcAddr_len);

 std::cout<< "Received " << recv_len << "bytes on broadcast address" << std::endl;

 fwrite(&buffer, sizeof(unsigned char), recv_len, file);
 }

 return 0;
}
</queue></iostream>



FFMPEG -I output






Any help would be greatly appreciated.


-
Flash player seek not working when ffmpeg encoded with gop(-g) = 1 [migrated]
3 mars 2015, par BrianI am trying to deliver video content with frame-by-frame viewing via the SMP Flash player. For encoding, I am using FFMPEG with the x264 video codec for files with .mp4 containers. I am using the latest ffmpeg build and using the OSMF SMP flash video player.
I am taking a series of png files and creating a .mp4 file :
ffmpeg -nostdin -loglevel warning -i out.%d.png -g 1 -crf 15 -c:v libx264 -movflags faststart -pix_fmt yuv420p -r 24 out.mp4
By encoding with the
gop(-g) flag = 1
, I am encoding to make each frame a keyframe. When I seek using the scrub bar of the SMP flash player, it always seeks to the start of the video. If I play and scrub/seek the video using the default HTML player, it works perfectly.When I encode with the
gop(-g) flag = 2
, the SMP Flash player scrubs/seeks and plays correctly.It looks like there may be some kind of bug or incompatibility with the Flash player. I have found this problem mentioned back in 2009. I think my only hope is to find a work around. Any suggestions ?
-
libx264 encoded video lags by few seconds in comparison to audio
18 septembre 2017, par Herdesh VermaBelow is the code i am using for reading a .3gp file encoding it using libx264 and writing it to .mp4 container. Code is working but when i play .mp4 file then video is not in sync with audio. Video is few second slow in comparison to audio.
// Read all packet from context
while( av_read_frame( fmt_ctx , pAVPacket ) >= 0 )
{
int decoded = pAVPacket->size;
if(pAVPacket->stream_index == video_stream_idx)
{
//decode packet
value = avcodec_decode_video2(video_dec_ctx , pAVFrame ,
&frameFinished , pAVPacket );
if( value < 0)
{
av_free_packet(pAVPacket);
return -1;
}
if(frameFinished)// Frame successfully decoded :)
{
sws_scale(swsCtx_, (const uint8_t *const *) pAVFrame->data,
pAVFrame->linesize, 0, video_dec_ctx->height, outFrame->data,
outFrame->linesize);
av_init_packet(&outPacket);
outPacket.data = NULL; // packet data will be allocated by
the encoder
outPacket.size = 0;
outFrame->pts=z;
//encode frame
avcodec_encode_video2(outAVCodecContext , &outPacket ,outFrame ,
&got_picture);
if(got_picture)
{
if(outPacket.pts != AV_NOPTS_VALUE)
outPacket.pts = av_rescale_q(outPacket.pts, video_st-
>codec->time_base, video_st->time_base);
if(outPacket.dts != AV_NOPTS_VALUE)
outPacket.dts = av_rescale_q(outPacket.dts, video_st-
>codec->time_base, video_st->time_base);
//Write encoded packet to file.
if(av_write_frame(outAVFormatContext , &outPacket) != 0)
{
av_free_packet(pAVPacket);
av_free_packet(&outPacket);
return -1;
}
z++;
av_free_packet(&outPacket);
} // got_picture
} // got_picture
}
// If packet is from audio stream
else if (pAVPacket->stream_index == audio_stream_idx)
{
//Write to file without decoding and encoding it
if(av_write_frame(outAVFormatContext , pAVPacket) != 0)
{
}
}
av_free_packet(pAVPacket);
//z++;
}// End of while-loop
value = av_write_trailer(outAVFormatContext);
if( value < 0)
{
return -1;
}I am using below settings :
outAVCodecContext->codec_id = AV_CODEC_ID_H264;// AV_CODEC_ID_MPEG4; // AV_CODEC_ID_H264 // AV_CODEC_ID_MPEG1VIDEO
outAVCodecContext->bit_rate_tolerance = BIT_RATE_TOLERANT;
outAVCodecContext->rc_max_rate = RC_MAX_RATE;
outAVCodecContext->rc_buffer_size = RC_BUFFER_SIZE;
outAVCodecContext->gop_size = GOP_SIZE;
outAVCodecContext->b_frame_strategy = B_FRAME_STRATEGY;
outAVCodecContext->coder_type = CODER_TYPE;
outAVCodecContext->me_cmp = ME_CMP;
outAVCodecContext->me_range = ME_RANGE; //16
outAVCodecContext->qmin = QMIN; //10
outAVCodecContext->qmax = QMAX; //51
outAVCodecContext->scenechange_threshold = SCENECHANGE_THRESHOLD; //40
outAVCodecContext->flags |= CODEC_FLAG_LOOP_FILTER;
outAVCodecContext->me_method = ME_METHOD;
outAVCodecContext->me_subpel_quality = ME_SUBPEL_QUALITY;
outAVCodecContext->i_quant_factor = I_QUANT_FACTOR; //0.71
outAVCodecContext->qcompress = QCOMPRESS;
outAVCodecContext->max_qdiff = MAX_QDIFF;
av_dict_set( &codec_options, "preset", "superfast", 0 );And values are defined as below :
#define VAVLON_VALUES_H
#define BIT_RATE_TOLERANT 0;
#define RC_MAX_RATE 0;
#define RC_BUFFER_SIZE 0;
#define GOP_SIZE 40;
#define B_FRAME_STRATEGY 0;
#define CODER_TYPE 1;
#define ME_CMP 1;
#define ME_RANGE 16; //16
#define QMIN 30; //37
#define QMAX 40; //70
#define SCENECHANGE_THRESHOLD 40; //40
#define ME_METHOD ME_HEX;
#define ME_SUBPEL_QUALITY 40;
#define I_QUANT_FACTOR 0.71;
#define QCOMPRESS 0.3;
#define MAX_QDIFF 4;
#define BIT_RATE 500000;
#define CODEC_TYPE AVMEDIA_TYPE_VIDEO;
#define PIX_FMT AV_PIX_FMT_YUV420P;
#define MAX_B_FRAMES 0;
#define NUM 1;
#define DEN 30;Above code works as expected when i am encoding .mp4 file but i notice lag in video when i try to encode .3gp file.
Can you please help in finding out what i am doing wrong ?