Question

I am using ffmpeg on android, and I wanted to add audio and create a video in the same command.

This is the command I am using:

ffmpeg -f image2 -r duration_per_frame -i input_frame_path -i audio_path -s 640x640 -vcodec libx264 -c:a aac -strict experimental -b:a 192k -y out_video_path

Now I am a ffmpeg noob, so sorry if I made some stupid mistake..

BTW, The command doesn't work, It doesn't create the video file, when this following command works:

ffmpeg -f image2 -r duration_per_frame -i input_frame_path -s 640x640 -vcodec libx264 -y out_video_path

LOGCAT LOG Filter tag FFMPEG:

04-16 14:42:11.037: D/FFMPEG(10701): [C@42f2d778
04-16 14:42:11.037: D/FFMPEG(10701): [C@443bbaf0
04-16 14:42:11.037: D/FFMPEG(10701): [C@42d8ce38
04-16 14:42:11.037: D/FFMPEG(10701): [C@443a70d0
04-16 14:42:11.037: D/FFMPEG(10701): [C@443a3c00
04-16 14:42:11.037: D/FFMPEG(10701): [C@443822b0
04-16 14:42:11.037: D/FFMPEG(10701): [C@443665d0
04-16 14:42:11.042: D/FFMPEG(10701): [C@4433cab0
04-16 14:42:11.042: D/FFMPEG(10701): [C@42fa06f8
04-16 14:42:11.042: D/FFMPEG(10701): [C@42df9c28
04-16 14:42:11.042: D/FFMPEG(10701): [C@42db2e60
04-16 14:42:11.072: D/FFMPEG(10701): [C@44399300
04-16 14:42:11.072: D/FFMPEG(10701): [C@443b0360
04-16 14:42:11.072: D/FFMPEG(10701): [C@42fa1d08
04-16 14:42:11.072: D/FFMPEG(10701): [C@42d8c7f0
Was it helpful?

Solution

Let me explain you how this works
ffmpeg is complete, cross platform command line tool capable of recording, converting and streaming digital audio and video in various formats.

ffmpeg -f image2 -r duration_per_frame -i input_frame_path -i audio_path -s 640x640 -vcodec libx264 -c:a aac -strict experimental -b:a 192k -y out_video_path

-f is used to force a particular type of format for video conversion
-r is used to set the frame rate of video. i.e. no. of frames to be extracted into images per second.The default value is 25, using which, would have yielded a large number of images.
-i is used to specify the input file
-s is used to set the frame size of the final video
-vcodec is used to force the video codec for video conversion
-c is used to encode or decode with a particular codec, since you mentioned -c:a aac it means encoding the audio stream with aac.
-strict experimental Some encoders, such as the native FFmpeg AAC encoder (aac), are considered experimental and require the addition of -strict experimental
-b is used to set the audio/video bit rate. Since you used -b:a 192k the audio bit rate is set to 192k.
-y is used to overwrite output files.

Now let us come to your question of video file not being created. This could be because of you are using a still image or the image stream is just not getting populated, may be you can add -loop 1 to your command and check. This may not be a complete solution but it could be a start. we need to dig more deeper.

ffmpeg -f image2 -r duration_per_frame -loop 1 -i input_frame_path -i audio_path -s 640x640 -vcodec libx264 -c:a aac -strict experimental -b:a 192k -y out_video_path

I would still recommend you to provide us all the paths you are using in the command. And give more idea of what you are trying to do.

OTHER TIPS

ffmpeg -f image2 -r 25 -i /path/to/images/image%02d.jpg -i /path/to/audio.wav -s 640x640 -c:v libx264 -c:a aac -strict experimental -b:a 192k -y test.mp4

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top