5

I am using FFmpeg to concat videos in my android application.I have followed some of the steps to merge videos of different formats. For mp4 videos, i have to convert all input files to MPEG-2 TS files and then merge all the .ts files to get an output mp4 file.

  • I have a problem in merging the videos if they are of different resolutions(say one is 640*480 and the other is 1280*720).The output video does not merge properly(sometimes it throws an error in Streams). Is there any way to handle this without losing the quality of videos?

  • Lets say i am merging two videos one with audio and the other without audio.When i try to merge these two i am getting errors in Audio Streams.Is there any way to handle this also(videos should be merged with or without audio)?

I am facing problems in above two things and spent more time without success. Any idea is greatly appreciated.

3
  • Are you using the ffmpeg command line tool or the API? You mention "errors", but you do not show them. Commented Jul 11, 2013 at 18:13
  • I am using ffmpeg API and the parameters are passed from android. Commented Jul 12, 2013 at 4:17
  • superuser.com/a/1136854/101823 Commented Apr 1, 2017 at 4:05

1 Answer 1

0

For merging videos you need to work with the same resolution, you should scale the 640x480 video or compress the 1280x720, it is up to you. I would recommend you compress the bigger one it is faster.

Moreover, for merging videos you need a media file with audio and video part. You can create a silence audio with the same duration of your video and after you can add it to your video. Videos should be merged with audio.

ffmpeg -ar 48000 -t 60 -f s16le -acodec pcm_s16le -i /dev/zero -ab 128K -f mp2 -acodec mp2 -y silence.mp2

ffmpeg -i video_without_audio.mpg -i silence.mp2 video_to_merge.mpg 
Sign up to request clarification or add additional context in comments.

3 Comments

Alvaro, Thanks for the reply. /dev/zero is the input video file, right? Also how do we know if there is audio or not? Can these be done automatically by FFmpeg because it takes so much of time for conversions which is making the app bad.
/dev/zero is not a video file, this command is to create a dummy audio to join in your video, without audio you can not merge videos. To know if there is an audio stream, use ffmpeg output, with option -i you can check the streams, stream #0.0 video and stream #0.1 audio.
Thanks Alvaro, i will check it out.Is there a way to concat video files of different formats directly in single step without conversions because it takes more time? Also i am having problems in building latest ffmpeg.Is there any steps to use ffmpeg libraries(after building separately) with android to make a shared library that comprises all of the ffmpeg commands?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.