Newest 'x264' Questions - Stack Overflow
Les articles publiés sur le site
-
HLS Streaming on IPad with IOS 7 / 8 causes 10 seconds freezed frame - no clue why
25 juin 2014, par user3747636We have a problem with HLS h.264 mp4 on IPad devices using HLS streaming on IOS 7 and 8:
The first 9-15 seconds (the length of the first TS segment) only shows the first key frame (IDR) of the second TS segment, while the sound plays normally. When the second segment begins to play, the video continues as it should.
HLS segmenter is a wowza with 10 seconds segment length. The encoding software we use is TMPG, latest version (uses x264). The funny thing is, that handbrake, xmedia recode, adobe me deliver videos which work. I am aware of the fact, that this hints to a bug within our encoding software, but if someone already had that problem with another software / segmenter combination and fixed it, I would like to know what the source of the problem was.
What we already tried:
- changing almost every setting so that it sticks as close as possible to apple's recommendations
- changing GOP structure, GOP length, encoding parameters which influence efficiency of encoding
- analysis of the TS segments created by wowza, they are fine and begin all with keyframes
- contact TMPG/Apple/Wowza support
So, did anyone stumble upon this problem before? Has anyone solved it?
EDIT:
It seems that TMPGEnc uses a defective x264 implementation. The mediastreamvalidator tool from Apple returned an error stating that our TS segment "does not contain any IDR access unit with a SPS and a PPS" - which it does actually, but obviously in the wrong places if that somehow matters.
-
openCV VideoCapture doesn't work with gstreamer x264
18 juin 2014, par nschoeI'd like to display a rtp / vp8 video stream that comes from gstreamer, in openCV.
I have already a working solution which is implemented like this :
gst-launch-0.10 udpsrc port=6666 ! "application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)VP8-DRAFT-IETF-01,payload=(int)120" ! rtpvp8depay ! vp8dec ! ffmpegcolorspace ! ffenc_mpeg4 ! filesink location=videoStream
Basically it grabs incoming data from a UDP socket, depacketize rtp, decode vp8, pass to ffmpegcolorspace (I still don't understand what this is for, I see it everywhere in gstreamer).
The
videoStream
is a pipe I created withmkfifo
. On the side, I have my openCV code that does :VideoCapture cap("videoStream");
and uses
cap.read()
to push into aMat
.My main concern is that I use
ffenc_mpeg4
here and I believe this alters my video quality. I tried usingx264enc
in place offfenc_mpeg4
but I have no output : openCV doesn't react, neither does gstreamer, and after a couple of seconds, gst-launch just stops.Any idea what I could use instead of
ffenc_mpeg4
? I looked for "lossless codec" on the net, but it seems I am confusing things such as codec, contains, format, compression and encoding ; so any help would be (greatly) appreciated !Thanks in advance !
-
h264 encoder other than x264
2 juin 2014, par TMMDevi want to encode H264 packets and send them as RTP. x264 is great, but it is under GPL license, and requires me to open source my project
is there an equivalent library to x264 which does not require to publish my source code?
Thank you.
-
ffmpeg mono8/rgb24 images to yuv420p to x264 conversion
30 mai 2014, par 3xpothis is probably a trivial question but I'm going crazy with this (ffmpeg) framework. Based on this post (sws_scale YUV --> RGB distorted image) (and much more searches) I've written the following code to take a char* pointer to a buffer image (Mono8 or RGB24) and I convert to YUV420P to encode in x264. I have to create a streaming of this images between two PC.
This is the code:
bool compressImageX264(Frame *f, int size, char* image){ codec = avcodec_find_encoder(AV_CODEC_ID_H264); if (!codec) { std::cout << "Codec not found" << std::endl; return false; } c = avcodec_alloc_context3(codec); if (!c) { std::cout << "Could not allocate video codec context" << std::endl; return false; } av_opt_set(c->priv_data, "preset", "veryfast", 0); av_opt_set(c->priv_data, "tune", "zerolatency", 0); c->width = std::stoi(f->width); c->height = std::stoi(f->height); c->gop_size = 10; c->max_b_frames = 1; EDIT: c->pix_fmt = AV_PIX_FMT_YUV420P; /* open it */ if (avcodec_open2(c, codec, NULL) < 0) { std::cout << "Could not open codec" << std::endl; return false; } AVFrame *avFrameRGB = av_frame_alloc(); if (!avFrameRGB) { std::cout << "Could not allocate video frame" << std::endl; return false; } avFrameRGB->format = std::stoi(f->channels) > 1 ? AV_PIX_FMT_RGB24 : AV_PIX_FMT_GRAY8; avFrameRGB->width = c->width; avFrameRGB->height = c->height; int ret = av_image_alloc( avFrameRGB->data, avFrameRGB->linesize, avFrameRGB->width, avFrameRGB->height, AVPixelFormat(avFrameRGB->format), 32); if (ret < 0) { std::cout << "Could not allocate raw picture buffer" << std::endl; return false; } uint8_t *p = avFrameRGB->data[0]; for (int i = 0; i < size; i++){ *p++ = image[i]; } AVFrame* avFrameYUV = av_frame_alloc(); avFrameYUV->format = AV_PIX_FMT_YUV420P; avFrameYUV->width = c->width; avFrameYUV->height = c->height; ret = av_image_alloc( avFrameYUV->data, avFrameYUV->linesize, avFrameYUV->width, avFrameYUV->height, AVPixelFormat(avFrameYUV->format), 32); SwsContext *img_convert_ctx = sws_getContext(c->width, c->height, AVPixelFormat(avFrameRGB->format), c->width, c->height, AV_PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL); ret = sws_scale(img_convert_ctx, avFrameRGB->data, avFrameRGB->linesize, 0, c->height, avFrameYUV->data, avFrameYUV->linesize); sws_freeContext(img_convert_ctx); AVPacket pkt; av_init_packet(&pkt); pkt.data = NULL; // packet data will be allocated by the encoder pkt.size = 0; avFrameYUV->pts = frameCount; frameCount++; //GLOBAL VARIABLE int got_output; ret = avcodec_encode_video2(c, &pkt, avFrameYUV, &got_output); if (ret < 0) { //<-- Where the code broke std::cout << "Error encoding frame" << std::endl; return false; } if (got_output) { std::cout << "Write frame " << frameCount - 1 << "(size = " << pkt.size << ")" << std::endl; char* buffer = new char[pkt.size]; for (int i = 0; i < pkt.size; i++){ buffer[i] = pkt.data[i]; } f->buffer = buffer; f->size = std::to_string(pkt.size); f->compression = std::string("x264"); av_free_packet(&pkt); } return true; }
I know that maybe this is a lot inefficient but for now I'm worried to make it work. I failed when I call avcodec_encode_video2. On console it's printed this message: "Input picture width (640) is greater than stride (320)". I think that conversion is the assassin. But I don't fully know the parameters meanings Thanks for all your help.
EDIT: Ok, I have founded the "first" error. Now the conversion work properly and avcodec_encode_video2 return 0. The problem now is that got_output is always equal zero and on the console nothing is available.
-
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet), the frameFinished is 0 most of the time why ?
26 mai 2014, par WhoamiI received a packet from rtsp by av_read_frame and decode it through
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet)
After decoding i am checking the value of frameFinished.
Most of the time i get the value of frameFinished is zero. May be around 50% of the packet.
Could you kindly hint me what could be the reason ?
is this issue in any way related to 'I', 'P', 'B' packet types ?