Newest 'libx264' Questions - Stack Overflow
Les articles publiés sur le site
-
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(¶m,"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(¶m, "baseline"); x264_t *encoder = x264_encoder_open(¶m); //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
#include #include Network.h> #include in.h> #include inet.h> #include types.h> #include socket.h> #include #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; } FFMPEG -I output
Any help would be greatly appreciated.
-
How can i build x264 and fdk-aac for android with ndk ?
4 avril 2020, par Pradeep SimbaHow can i build x264 and fdk-aac for android with ndk?
I build x264 and fdk-aac with ndk. But, it not done.
I modified this build file and I build x264 and fdk-aac.But,it not done.
How can I solve this?
-
How to fix grainy recoding with ffmpeg mp4 x264 ?
21 mars 2020, par teenserieI recorded the audio and video stream from a streaming with ffmpeg. when I go to re-encode the file using libx264, the video in the movements looks bad and grainy as in the image. Where did I go wrong?
this is the code I used
ffmpeg -i input.mp4 -c:v libx264 -c:a aac output.mp4
and these are mediainfo of original file
Metadata: major_brand : isom minor_version : 1 compatible_brands: isom creation_time : 2020-03-19T22:43:32.000000Z Duration: 00:39:51.99, start: 0.000000, bitrate: 1300 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x1080 [SAR 3:2 DAR 16:9], Closed Captions, 1268 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(spa): Audio: aac (HE-AACv2) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 22 kb/s (default) Metadata: handler_name : SoundHandler
mediainfo of the file recoded
Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.29.100 Duration: 00:39:51.99, start: 0.000000, bitrate: 7924 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 7892 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(spa): Audio: aac (HE-AACv2) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 22 kb/s (default) Metadata: handler_name : SoundHandler
How can I recode the file without loss of quality? (sorry for my poor english)
-
How to benchmark x264 in ARM9 environment
8 mars 2020, par curious_beast1.How to benchmark x264 video encoder in Dual-core ARM Cortex™-A9?. 2.How to calculate the encoding speed with respect to the CPU clock frequency?.
-
what's that before first IDR in 264 (not sps pps)
6 mars 2020, par DJI_loverI used ffmpeg and libx264 to encode my video,when I print the AVPacket data,I found there is something only exist before the first IDR.Could someone tell me what's that,thanks.
0 0 1 6 5 ff ff 73 dc 45 e9 bd e6 d9 48 b7 96 2c d8 20 d9 23 ee ef 78 32 36 34 20 2d 20 63 6f 72 65 20 31 34 38 20 72 32 36 34 33 20 35 63 36 35 37 30 34 20 2d 20 48 2e 32 36 34 2f 4d 50 45 47 2d 34 20 41 56 43 20 63 6f 64 65 63 20 2d 20 43 6f 70 79 6c 65 66 74 20 32 30 30 33 2d 32 30 31 35 20 2d 20 68 74 74 70 3a 2f 2f 77 77 77 2e 76 69 64 65 6f 6c 61 6e 2e 6f 72 67 2f 78 32 36 34 2e 68 74 6d 6c 20 2d 20 6f 70 74 69 6f 6e 73 3a 20 63 61 62 61 63 3d 31 20 72 65 66 3d 31 20 64 65 62 6c 6f 63 6b 3d 31 3a 30 3a 30 20 61 6e 61 6c 79 73 65 3d 30 78 33 3a 30 78 31 31 33 20 6d 65 3d 68 65 78 20 73 75 62 6d 65 3d 32 20 70 73 79 3d 31 20 70 73 79 5f 72 64 3d 31 2e 30 30 3a 30 2e 30 30 20 6d 69 78 65 64 5f 72 65 66 3d 30 20 6d 65 5f 72 61 6e 67 65 3d 31 36 20 63 68 72 6f 6d 61 5f 6d 65 3d 31 20 74 72 65 6c 6c 69 73 3d 30 20 38 78 38 64 63 74 3d 31 20 63 71 6d 3d 30 20 64 65 61 64 7a 6f 6e 65 3d 32 31 2c 31 31 20 66 61 73 74 5f 70 73 6b 69 70 3d 31 20 63 68 72 6f 6d 61 5f 71 70 5f 6f 66 66 73 65 74 3d 30 20 74 68 72 65 61 64 73 3d 34 20 6c 6f 6f 6b 61 68 65 61 64 5f 74 68 72 65 61 64 73 3d 34 20 73 6c 69 63 65 64 5f 74 68 72 65 61 64 73 3d 31 20 73 6c 69 63 65 73 3d 34 20 6e 72 3d 30 20 64 65 63 69 6d 61 74 65 3d 31 20 69 6e 74 65 72 6c 61 63 65 64 3d 30 20 62 6c 75 72 61 79 5f 63 6f 6d 70 61 74 3d 30 20 63 6f 6e 73 74 72 61 69 6e 65 64 5f 69 6e 74 72 61 3d 30 20 62 66 72 61 6d 65 73 3d 30 20 77 65 69 67 68 74 70 3d 31 20 6b 65 79 69 6e 74 3d 31 32 20 6b 65 79 69 6e 74 5f 6d 69 6e 3d 31 20 73 63 65 6e 65 63 75 74 3d 34 30 20 69 6e 74 72 61 5f 72 65 66 72 65 73 68 3d 30 20 72 63 3d 61 62 72 20 6d 62 74 72 65 65 3d 30 20 62 69 74 72 61 74 65 3d 32 30 30 30 20 72 61 74 65 74 6f 6c 3d 31 2e 30 20 71 63 6f 6d 70 3d 30 2e 36 30 20 71 70 6d 69 6e 3d 30 20 71 70 6d 61 78 3d 36 39 20 71 70 73 74 65 70 3d 34 20 69 70 5f 72 61 74 69 6f 3d 31 2e 34 30 20 61 71 3d 31 3a 31 2e 30 30 0 80