Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
How do I cute a last 10 seconds from mpeg using ffmpeg
4 décembre 2015, par EvGeniy Ilyini have many different mpeg files. in every mpeg file are credits at the end of the video. i need cut it. How i can do it for bath(list)? for example:
ffmpeg -i my.mp4 -vcodec copy -acodec copy -ss 00:10:10 my_cute.mp4
but every mpeg file has different duration... we heve is a way to specify the indent from the end?
-
Streaming protocol relay without involving codec
4 décembre 2015, par kiran_gI am trying to use libav to relay an RTSP stream. It involves PULLing the stream from an IP camera and then PUSHing to wowza.
The video encoding in the IP camera stream is h264. To enable h264 in my libav application I need to enable x264. But as x264 is GPL, it will not work with my business plan.
My questions is whether libav (ffmpeg) can be made to work like a dumb relay which is encoding-agnostic? so that I dont need to integrate x264 with ffmpeg.
This SO post says that I can use the "copy" argument, but does that allow me to exclude x264?
BTW, is x264 actually needed by ffmpeg for decoding h264? Is x264 only used in encoding?
See here for my current code.
-
could anybody help me with php synatax of execution of ffmpeg to draw text ? [on hold]
4 décembre 2015, par Manveer Brari have use folllwing code i gives me a error in php
exec("ffmpeg -i input.mp4 -vf drawtext="fontfile=/usr/share/fonts/TTF/Vera.ttf: text='hello': fontcolor=white: fontsize=30: x=15: y=15" -codec:a copy output.mp4");
-
Ffmpeg decoder yuv420p
4 décembre 2015, par user2466514I work on a video player yuv420p with ffmpeg but it's not working and i can't find out why. I spend the whole week on it...
So i have a test which just decode some frame and read it, but the output always differ, and it's really weird.
I use a video (mp4 yuv420p) which color one black pixel in more each frame :
For the video, put http://sendvid.com/b1sgf8r1 on a website like http://www.telechargerunevideo.com/en/
VideoContext is just a little struct:
struct VideoContext { unsigned int currentFrame; std::size_t size; int width; int height; bool pause; AVFormatContext* formatCtx; AVCodecContext* codecCtxOrig; AVCodecContext* codecCtx; int streamIndex; };
So i have a function to count the number of black pixels:
std::size_t checkFrameNb(const AVFrame* frame) { std::size_t nb = 0; for (int y = 0; y < frame->height; ++y) { for (int x = 0 ; x < frame->width; ++x) { if (frame->data[0][(y * frame->linesize[0]) + x] == BLACK_FRAME.y && frame->data[1][(y / 2 * frame->linesize[1]) + x / 2] == BLACK_FRAME.u && frame->data[2][(y / 2 * frame->linesize[2]) + x / 2] == BLACK_FRAME.v) ++nb; } } return nb; }
And this is how i decode one frame:
const AVFrame* VideoDecoder::nextFrame(entities::VideoContext& context) { int frameFinished; AVPacket packet; // Allocate video frame AVFrame* frame = av_frame_alloc(); if(frame == nullptr) throw; // Initialize frame->linesize avpicture_fill((AVPicture*)frame, nullptr, AV_PIX_FMT_YUV420P, context.width, context.height); while(av_read_frame(context.formatCtx, &packet) >= 0) { // Is this a packet from the video stream? if(packet.stream_index == context.streamIndex) { // Decode video frame avcodec_decode_video2(context.codecCtx, frame, &frameFinished, &packet); // Did we get a video frame? if(frameFinished) { // Free the packet that was allocated by av_read_frame av_free_packet(&packet); ++context.currentFrame; return frame; } } } // Free the packet that was allocated by av_read_frame av_free_packet(&packet); throw core::GlobalException("nextFrame", "Frame decode failed"); }
There is already something wrong?
Maybe the context initialization will be useful:
entities::VideoContext VideoLoader::loadVideoContext(const char* file, const int width, const int height) { entities::VideoContext context; // Register all formats and codecs av_register_all(); context.formatCtx = avformat_alloc_context(); // Open video file if(avformat_open_input(&context.formatCtx, file, nullptr, 0) != 0) throw; // Couldn't open file // Retrieve stream information if(avformat_find_stream_info(context.formatCtx, nullptr) > 0) throw; // Couldn't find stream information // Dump information about file onto standard error //av_dump_format(m_formatCtx, 0, file, 1); // Find the first video stream because we don't need more for(unsigned int i = 0; i < context.formatCtx->nb_streams; ++i) if(context.formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { context.streamIndex = i; context.codecCtx = context.formatCtx->streams[i]->codec; break; } if(context.codecCtx == nullptr) throw; // Didn't find a video stream // Find the decoder for the video stream AVCodec* codec = avcodec_find_decoder(context.codecCtx->codec_id); if(codec == nullptr) throw; // Codec not found // Copy context if ((context.codecCtxOrig = avcodec_alloc_context3(codec)) == nullptr) throw; if(avcodec_copy_context(context.codecCtxOrig, context.codecCtx) != 0) throw; // Error copying codec context // Open codec if(avcodec_open2(context.codecCtx, codec, nullptr) < 0) throw; // Could not open codec context.currentFrame = 0; decoder::VideoDecoder::setVideoSize(context); context.pause = false; context.width = width; context.height = height; return std::move(context); }
I know it's not a little piece of code, if you have any idea too make an exemple more brief, go on.
And if someone have an idea about this issue, there is my output:
9 - 10 - 12 - 4 - 10 - 14 - 11 - 8 - 9 - 10
But i want :
1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10
PS: get fps and video size are copy paste code of opencv
-
Transmit video over internet using ffmpeg
4 décembre 2015, par miladrasooliI'm working on a project and I need to send (stream) video over TCP or UDP protocol to a client application. I ended up using ffmpeg c++ source code and now I have managed to encode video using h264 codec. Now I want to send video byte by byte to other PC and here is my problem. I have the following code which loops through video packets and makes a video frame. Here is my question : should I send packets or frames to other PC?
while (av_read_frame(pFormatCtx, &packet) >= 0) { if (packet.stream_index == videoStream) { sumPackets += packet.size; PacketCount++; avcodec_decode_video2(pCodecCtx,pFrame,&frameFinished, &packet); if (frameFinished) { len += pFrame->pkt_size; Framecount++; ... } } }
P.S : I don't want to user streaming protocols like RTSP , RTMP , etc.
Thanks.