Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
[FFmpeg]Converting Jpeg to Motion Jpeg by using FFmpeg
12 avril 2016, par YJJI'm completely new in this field and trying to convert Jpeg image files to Motion Jpeg Video files by using a FFmpeg Library with C++.
I made one just using a ffmpeg bat file. but I want to make C++ code lines to do it.
I thought I have to encode the Jpeg files first, but I saw some references which said I don't need to encode in this case but just use a mux.
I am modifying example codes from FFmpeg public page but got really stuck now
could anyone help me with this please?
this is my example cpp code.
int main(int argc, char **argv) { const char *filename; AVOutputFormat *fmt; AVFormatContext *oc; AVStream *audio_st, *video_st; AVCodec *audio_codec, *video_codec; double audio_time, video_time; int ret; /* Initialize libavcodec, and register all codecs and formats. */ av_register_all(); if (argc != 2) { printf("usage: %s output_file\n" "API example program to output a media file with libavformat.\n" "This program generates a synthetic audio and video stream, encodes and\n" "muxes them into a file named output_file.\n" "The output format is automatically guessed according to the file extension.\n" "Raw images can also be output by using '%%d' in the filename.\n" "\n", argv[0]); return 1; } filename = argv[1]; /* allocate the output media context */ avformat_alloc_output_context2(&oc, NULL, NULL, filename); if (!oc) { printf("Could not deduce output format from file extension: using MPEG.\n"); avformat_alloc_output_context2(&oc, NULL, "mpeg", filename); } if (!oc) { return 1; } fmt = oc->oformat; /* Add the audio and video streams using the default format codecs * and initialize the codecs. */ video_st = NULL; audio_st = NULL; if (fmt->video_codec != AV_CODEC_ID_NONE) { video_st = add_stream(oc, &video_codec, fmt->video_codec); } if (fmt->audio_codec != AV_CODEC_ID_NONE) { audio_st = add_stream(oc, &audio_codec, fmt->audio_codec); } /* Now that all the parameters are set, we can open the audio and * video codecs and allocate the necessary encode buffers. */ if (video_st) open_video(oc, video_codec, video_st); if (audio_st) open_audio(oc, audio_codec, audio_st); av_dump_format(oc, 0, filename, 1); /* open the output file, if needed */ if (!(fmt->flags & AVFMT_NOFILE)) { ret = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE); if (ret < 0) { //fprintf(stderr, "Could not open '%s': %s\n", filename,av_err2str(ret)); char buf[256]; av_strerror(ret, buf, sizeof(buf)); printf("avcodec_decode_video2 error :%s,ret:%d\n", buf, ret); return 1; } } /* Write the stream header, if any. */ ret = avformat_write_header(oc, NULL); if (ret < 0) { //fprintf(stderr, "Error occurred when opening output file: %s\n",av_err2str(ret)); char buf[256]; av_strerror(ret, buf, sizeof(buf)); printf("avcodec_decode_video2 error :%s,ret:%d\n", buf, ret); return 1; } if (frame) frame->pts = 0; for (;;) { /* Compute current audio and video time. */ audio_time = audio_st ? audio_st->pts.val * av_q2d(audio_st->time_base) : 0.0; video_time = video_st ? video_st->pts.val * av_q2d(video_st->time_base) : 0.0; if ((!audio_st || audio_time >= STREAM_DURATION) && (!video_st || video_time >= STREAM_DURATION)) break; /* write interleaved audio and video frames */ if (!video_st || (video_st && audio_st && audio_time < video_time)) { write_audio_frame(oc, audio_st); } else { write_video_frame(oc, video_st); frame->pts += av_rescale_q(1, video_st->codec->time_base, video_st->time_base); } } /* Write the trailer, if any. The trailer must be written before you * close the CodecContexts open when you wrote the header; otherwise * av_write_trailer() may try to use memory that was freed on * av_codec_close(). */ av_write_trailer(oc); /* Close each codec. */ if (video_st) close_video(oc, video_st); if (audio_st) close_audio(oc, audio_st); if (!(fmt->flags & AVFMT_NOFILE)) /* Close the output file. */ avio_close(oc->pb); /* free the stream */ avformat_free_context(oc); return 0; }
-
[C/C++]Converting Jpeg to Motion Jpeg by using FFmpeg
12 avril 2016, par YJJI'm completely new in this field and trying to convert Jpeg image files to Motion Jpeg Video files by using a FFmpeg Library with C++.
I made one just using a ffmpeg bat file. but I want to make C++ code lines to do it.
I thought I have to encode the Jpeg files first, but I saw some references which said I don't need to encode in this case but just use a mux.
I am modifying example codes from FFmpeg public page but got really stuck now
could anyone help me with this please?
-
Ffmpeg vframes consumes lot of memory !! Am I doing it the correct way ?
12 avril 2016, par Lakshman Diwaakar- I have a folder containing videos and I want to take the snapshots of video to create thumbnail for them.
say there are 50 videos, and when running the below command, consumes lot of memory and makes the computer slow.
Ffmpeg -i video.mp4 -ss 00:00:8.18 - vframes 1 -o out.png
- pythons subprocess was used to run the above command. While running for a folder containing 50 videos, consumes lot of memory.
is there any way to make it better
-
Android Audio Mixing FMPEG, Mediarecorder file only merging to left channel, delayed
12 avril 2016, par Jeremyworking on an app that takes two sounds, and merges them together. I currently have two problems with it I cannot seem to figure out so would appreciate another set of eyes.
- File from MediaRecorder (voice file) merges into Left Channel Only. (I can only hear voice in left ear)
The two files seem like there is a slight delay in the position as they are not aligned perfectly with the merge. Here is the method I have written.
private void mixAudio(File mVoiceFile, File mBeatFile, File mRapFile){ String files = "-i " + mVoiceFile.getAbsolutePath() + " -i " + mBeatFile.getAbsolutePath(); String filter = " -filter_complex [0:a]volume=1.5[a1];[1:a]volume=0.6[a2];[a1][a2]amerge=inputs=2,volume=1.3,pan=stereo|c0code>
} `
and here is how I setup my MediaRecorder
public void setRecorderSource(){ mRapRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRapRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mRapRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mRapRecorder.setAudioEncodingBitRate(128000); mRapRecorder.setAudioSamplingRate(44100); mRapRecorder.setAudioChannels(2); mRapRecorder.setOutputFile(mVoiceFile.getAbsolutePath()); }`
-
Slow down video file to a set duration
11 avril 2016, par ProgramFastSay I have a video exactly 25.1 seconds long and a Windows computer with
ffmpeg.exe
. Is there a way to use ffmpeg to slow down or speed up a video based off a number I give to it? For example, I want the 25.1 second video to slow down to exactly 24.3 seconds. How would I do that?
Normally, I would use-filter:v "setpts=SPD*DURATION"
, but that only speeds up or slows down by a multiplier, and not by an absolute number.