Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
ffmpeg and boost::asio NULL pointer
9 avril 2015, par GeorgiI am trying to make a special video software which will run on multiple core machines.
I want many c++ object to stream video files and many other c++ objects to store the streamed data into file.
I have created some simple classes, but when I try to create 2 and more objects I got:
opening stream9079.sdp [udp @ 0xaef5380] bind failed: Address already in use Could not open input file stream9079.sdp Segmentation fault (core dumped)
When I use only one object everything is fine.
I use the following code
int main(int argc, char **argv) { boost::asio::io_service ios; boost::asio::io_service ios1; Channel *channels[100]; channels[0] = new Channel(ios, 9078, atoi(argv[1])); channels[0]->StartTimer(0); channels[1] = new Channel(ios1, 9079, atoi(argv[1])); channels[1]->StartTimer(0); boost::thread t(boost::bind(&worker, &ios)); boost::thread t1(boost::bind(&worker, &ios1)); t.join(); t1.join(); CEVLOG_MSG << "done" << std::endl; return 0; }
My
Channel
class implementation is:#include "channel.hpp" #include "utils.hpp" #include "boost/lexical_cast.hpp" Channel::Channel(boost::asio::io_service &ioP, int i, bool to_send): Runnable(ioP), work( new boost::asio::io_service::work(ioP) ), ofmt(NULL), ifmt_ctx(NULL), ofmt_ctx(NULL) { id = i; sender = to_send; if (sender) { input.assign("/home/georgi/Downloads/video/IMG_0019.MOV"); output.assign("rtp://10.101.3.60:"); output += boost::lexical_cast(id); } else { input.assign("stream"); input += boost::lexical_cast(id); input += ".sdp"; output.assign("test"); output += boost::lexical_cast(id); output += ".mp4"; } video_idx = audio_idx = sub_idx = -1; if (OpenInput()) { if (sender) OpenOutput(eStreamOutput); else OpenOutput(eFileOutput); } } Channel::~Channel() { av_write_trailer(ofmt_ctx); avformat_close_input(&ifmt_ctx); if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE)) avio_closep(&ofmt_ctx->pb); avformat_free_context(ofmt_ctx); work.reset(); } bool Channel::OpenInput() { CEVLOG_MSG << "opening " << input << std::endl; int ret; if ((ret = avformat_open_input(&ifmt_ctx, input.c_str(), 0, 0)) < 0) { CEVLOG_ERR << "Could not open input file " << input << std::endl; return false; } CEVLOG_MSG << " " << ifmt_ctx << std::endl; if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) { CEVLOG_ERR << "Failed to retrieve input stream information" << std::endl; return false; } ifmt_ctx->flags |= AVFMT_FLAG_GENPTS; //read and set timestamps to 0 av_read_frame(ifmt_ctx, &pkt); pkt.pts = pkt.dts = 0; return true; } bool Channel::OpenOutput(tOutputType WhatToOpen) { int SDP_size; switch (WhatToOpen) { case eFileOutput: avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, output.c_str()); break; case eStreamOutput: avformat_alloc_output_context2(&ofmt_ctx, NULL, "rtp", output.c_str()); char SDP[4096]; SDP_size = 4096; av_sdp_create(&ofmt_ctx, 1, SDP, SDP_size); CEVLOG_DBG << "SDP=" << SDP << std::endl; break; default: assert(false); break; } if (!ofmt_ctx) { CEVLOG_ERR << "Could not create output context" << std::endl; return false; } ofmt = ofmt_ctx->oformat; video_idx = FindIndex(AVMEDIA_TYPE_VIDEO); if (!(ofmt->flags & AVFMT_NOFILE)) { if (avio_open(&ofmt_ctx->pb, output.c_str(), AVIO_FLAG_WRITE) < 0) { CEVLOG_ERR << "Could not open output file " << output << std::endl; return false; } } if (avformat_write_header(ofmt_ctx, NULL) < 0) { CEVLOG_ERR << "Error occurred when opening output file " << output << std::endl; return false; } return true; } unsigned int Channel::FindIndex(AVMediaType Type) { int idx; for (idx = 0; idx < ifmt_ctx->nb_streams; idx++) { if (ifmt_ctx->streams[idx]->codec->codec_type == Type) { AVStream *in_stream = ifmt_ctx->streams[idx]; AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec); if (!out_stream) { CEVLOG_ERR << "Failed allocating output stream" << std::endl; break; } if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) { CEVLOG_ERR << "Failed to copy context from input to output stream codec context" << std::endl; break; } out_stream->codec->codec_tag = 0; if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) { out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; } break; } } return idx; } void Channel::Callback() { if (sender) SendVideo(); else RecvVideo(); } void Channel::SendVideo() { int ret = av_read_frame(ifmt_ctx, &pkt); int time_ms = 0; if (ret != 0) { av_write_trailer(ofmt_ctx); work.reset(); return; } if (pkt.stream_index == video_idx) { AVStream *in_stream = ifmt_ctx->streams[pkt.stream_index]; AVStream *out_stream = ofmt_ctx->streams[pkt.stream_index]; AVRational time_base = ifmt_ctx->streams[video_idx]->time_base; char timestamp[100]; time_ms = 1000 * 1000 * strtof(timestamp2char(timestamp, pkt.duration, &time_base), NULL); pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF); pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF); pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base); pkt.pos = -1; ret = av_interleaved_write_frame(ofmt_ctx, &pkt); if (ret < 0) { CEVLOG_ERR << "Error muxing packet" << std::endl; return; } } av_free_packet(&pkt); StartTimer(time_ms); } void Channel::RecvVideo() { int ret = av_read_frame(ifmt_ctx, &pkt); if (ret != 0) { //Some error or end of stream is detected. Write file trailer av_write_trailer(ofmt_ctx); work.reset(); return; } //if is NOT video just continue reading if (pkt.stream_index == video_idx) { AVStream *in_stream = ifmt_ctx->streams[pkt.stream_index]; AVStream *out_stream = ofmt_ctx->streams[pkt.stream_index]; AVRational time_base = ifmt_ctx->streams[video_idx]->time_base; pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF); pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF); pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base); pkt.pos = -1; ret = av_interleaved_write_frame(ofmt_ctx, &pkt); if (ret < 0) { CEVLOG_ERR << "Error muxing packet" << std::endl; return; } } av_free_packet(&pkt); StartTimer(0); }
-
Adding a color filter at specific intervals in ffmpeg
9 avril 2015, par JamieLI am looking to add the color filter to a rtmp stream in ffmpeg at specific time intervals, say for 10 seconds every 10 seconds. I have tried two approaches. The first:
-vf "color=#8EABB8@0.9:480x208,select='gte(t,10)*lte(t,20)' [color];[in][color] overlay [out]"
This streams only the 10 seconds indicated by the select and applies the color filter rather than playing the whole stream and applying the filter to just those 20 seconds.
I then learnt about split and fifo and tried this approach:
-vf "[in] split [no-color], fifo, [with-color] overlay [out]; [no-color] fifo, select='gte(t,10)*lte(t,20)' [with-color]"
I would expect this to play the entire stream, and then select the 10 seconds specified so that I can apply filters, but it does the same as first approach and just plays the 10 seconds selected rather than the entire stream.
Thanks in advance.
-
FFMpeg add text to actual video file after recording in Android
9 avril 2015, par MunchooAm recording a video in Android device using JavaCV and playing it using a videoview. Now want to show a text on video while playing, which is entered after recording video. This text must be seen in all video players while playing the video.
I have gone thro the link How to add text on video recording? too which is expected here too
This is the method called after the video is recorded.
private void playRecordedVideo(Uri videoUri, boolean playVideoInLoop) { RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); videoView.setLayoutParams(layoutParams); videoView.setVisibility(View.VISIBLE); videoView.setVideoURI(videoUri); if(playVideoInLoop) { MediaController mediaController = new MediaController(MainActivity.this); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController); videoView.setOnPreparedListener (new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.setLooping(true); } }); } else { videoView.setMediaController(null); } videoView.start(); btnStart.setText(getString(R.string.txt_finish)); }
-
Correct path to FFmpeg through ssh
9 avril 2015, par user2781361I have server with CentOS 5.x X86_64 Bit. On this server there is ffmpeg installed on /root/install/ffmpeg but when i'm trying to check version with ffmpeg -version it's writing: -bash: /usr/bin/ffmpeg: No such file or directory How can i to redefine the path to correct or move ffmpeg to correct folder? Thanks.
-
Convert a series of jpg into an mov file in Ruby (or using any language)
9 avril 2015, par xeroshogunI am making a site in Ruby in which I have a series of images, (almost like a powerpoint) and I need to automatically convert those images into one continuous video file (mov, mpeg) that shows each image for 5 seconds or so. Any one have any clues where to start.
I'm also open to using another language if there are tools to get the job done.