Related
This question already has answers here:
Encoding a readable movie by QuickTime using FFMPEG
(2 answers)
FFmpeg converting image sequence to video results in blank video [closed]
(1 answer)
Closed 2 years ago.
I have some old videos collected using a canon camera, they are in avi format. I am not able to play the files on android though the audio works fine, it says Can't play video, videocodec not supported. I tried the following but it still doesn't work:
ffmpeg -i ip.avi -c:v libx264 -c:a aac -movflags +faststart op.mp4
Original avi video info:
Input #0, avi, from 'ip.avi'
Metadata:
creation_time : 2012-11-17 11:38:53
encoder : CanonMVI03
Duration: 00:01:39.90, start: 0.000000, bitrate: 16256 kb/s
Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 14844 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Converted mp4 video info:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'op.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:01:39.92, start: 0.000000, bitrate: 2048 kb/s
Stream #0:0(und): Video: h264 (High 4:2:2) (avc1 / 0x31637661), yuvj422p(pc), 640x480, 1911 kb/s, 30 fps, 30 tbr, 1000k tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
From posts here and here the following worked:
ffmpeg -i ip.avi -c:v libx264 -c:a aac op.mp4
ffmpeg -i op.mp4 -vf "scale=2*trunc(iw/2):-2,setsar=1" -profile:v main -pix_fmt yuv420p newop.mp4
This question already has answers here:
ffmpeg add watermark libx264 width not divisible by 2 (853x480)
(1 answer)
FFMPEG (libx264) "height not divisible by 2"
(7 answers)
Closed 4 years ago.
I am trying to overlay a video on an image using the below command.
String[]sepCmd=new String[]{"-loop","1","-i",uri,"-i",overlayUri,"-filter_complex","[1:v]colorkey=0x000000:0.5:0.5[ckout];[0:v][ckout]overlay[out]","-map","[out]","-acodec","libfaac","-c:a", "copy",outputPath};
When I run the above command, I get the error as shown below
Input #0, png_pipe, from '/storage/emulated/0/snowflake.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, gray(pc), 304x345 [SAR 11811:11811 DAR 304:345], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/FilterVideos/vintage1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Duration: 00:00:05.08, start: 0.000000, bitrate: 447 kb/s
Stream #1:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 306 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 (png) -> overlay:main
Stream #1:0 (h264) -> colorkey
overlay -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[swscaler # 0xee29d000] deprecated pixel format used, make sure you did set range correctly
[swscaler # 0xee2a8000] No accelerated colorspace conversion found from yuv420p to argb.
[libx264 # 0xf125ba00] height not divisible by 2 (304x345)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
I have an existing mp4 file and want to add an audio track to it using ffmpeg (the audio track is a wav file recorded from the device's microphone).
I'm executing the following command but it's not generating any output. It seems that fmpeg simply hangs:
String[] command = new String[]{"-i", audioFilePath, "-i", videoFilePath, "-codec", "copy", "-shortest", outputFilePath};
The logs are:
Input #0, wav, from '/data/user/0/android.com.app/cache/30930595321169630261385.audio':
Duration: 00:00:02.03, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Android/data/android.com.app/cache/4632127da0955d4a461dfd622c78233e':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.41.100
Duration: 00:00:02.04, start: 0.000000, bitrate: 728 kb/s
Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 500x280 [SAR 1:1 DAR 25:14], 724 kb/s, 16.67 fps, 16.67 tbr, 166667 tbn, 33.33 tbc (default)
Metadata:
handler_name : VideoHandler
After this, there are no more log statements.
Any ideas what could be causing this?
Use below given Command in FFmpeg Android
String[] command = {"-i", yourVideoPath, "-i", yourAudioPath, "-c:v", "copy", "-c:a", "aac", "-map", "0:v:0", "-map", "1:a:0", "-shortest", file.getAbsolutePath()}
I am trying to concatenate a couple of video files with ffmpeg for this i use
.././ffmpeg -i 01.mov -i op_IMG_20150221114715.mp4 -i 02.mov -i op_IMG_20150221114724.mp4 -i op_IMG_20150221114736.mp4 -strict -2 -filter_complex '[0:0] setsar=1/1[sarfix];[sarfix] [0:1] [1:0] [1:1] [2:0] [2:1] [3:0] [3:1] [4:0] [4:1] concat=n=5:v=1:a=1 [v] [a]' -map "[v]" -map "[a]" output.mp4
and it outputs this error
ffmpeg version 2.5.4 Copyright (c) 2000-2015 the FFmpeg developers
built on Feb 16 2015 16:20:23 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --arch=x86_64 --enable-runtime-cpudetect
libavutil 54. 15.100 / 54. 15.100
libavcodec 56. 13.100 / 56. 13.100
libavformat 56. 15.102 / 56. 15.102
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 2.103 / 5. 2.103
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '01.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2015-02-13 11:31:41
xmp :
Duration: 00:00:02.17, start: 0.000000, bitrate: 558 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 480x480, 402 kb/s, SAR 480:480 DAR 1:1, 24 fps, 24 tbr, 24 tbn, 48 tbc (default)
Metadata:
creation_time : 2015-02-13 11:31:41
handler_name : Apple Alias Data Handler
encoder : H.264
timecode : 00:00:00:00
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 68 kb/s (default)
Metadata:
creation_time : 2015-02-13 11:31:41
handler_name : Apple Alias Data Handler
timecode : 00:00:00:00
Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
Metadata:
creation_time : 2015-02-13 11:31:43
handler_name : Apple Alias Data Handler
timecode : 00:00:00:00
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'op_IMG_20150221114715.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.4.101
Duration: 00:00:04.07, start: 0.023220, bitrate: 539 kb/s
Stream #1:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x480 [SAR 1:1 DAR 1:1], 427 kb/s, 29.92 fps, 29.92 tbr, 11488 tbn, 59.83 tbc (default)
Metadata:
rotate : 90
handler_name : VideoHandler
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 120 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '02.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2015-02-13 11:32:12
xmp :
Duration: 00:00:02.38, start: 0.000000, bitrate: 666 kb/s
Stream #2:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 480x480, 445 kb/s, SAR 480:480 DAR 1:1, 24 fps, 24 tbr, 24 tbn, 48 tbc (default)
Metadata:
creation_time : 2015-02-13 11:32:12
handler_name : Apple Alias Data Handler
encoder : H.264
timecode : 00:00:02:12
Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 119 kb/s (default)
Metadata:
creation_time : 2015-02-13 11:32:12
handler_name : Apple Alias Data Handler
timecode : 00:00:02:12
Stream #2:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
Metadata:
creation_time : 2015-02-13 11:32:15
handler_name : Apple Alias Data Handler
timecode : 00:00:02:12
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from 'op_IMG_20150221114724.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.4.101
Duration: 00:00:02.07, start: 0.023220, bitrate: 549 kb/s
Stream #3:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x480 [SAR 1:1 DAR 1:1], 460 kb/s, 29.92 fps, 29.92 tbr, 11488 tbn, 59.83 tbc (default)
Metadata:
rotate : 90
handler_name : VideoHandler
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 111 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'op_IMG_20150221114736.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.4.101
Duration: 00:00:01.07, start: 0.023220, bitrate: 392 kb/s
Stream #4:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x480 [SAR 1:1 DAR 1:1], 334 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
rotate : 90
handler_name : VideoHandler
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #4:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
Metadata:
handler_name : SoundHandler
File 'output.mp4' already exists. Overwrite ? [y/N] y
[Parsed_concat_1 # 0x7f922bc1cec0] Input link in2:v0 parameters (size 480x480, SAR 480:480) do not match the corresponding output link in0:v0 parameters (480x480, SAR 1:1)
[Parsed_concat_1 # 0x7f922bc1cec0] Failed to configure output pad on Parsed_concat_1
The issue seems like I need to apply sarfix on input files 02.mov also. But I dont know the syntax for that.
Why some things must be set by the user
From the concat filter documentation:
All corresponding streams must have the same parameters in all
segments; the filtering system will automatically select a common
pixel format for video streams, and a common sample format, sample
rate and channel layout for audio streams, but other settings, such as
resolution, must be converted explicitly by the user.
More for the same docs:
For this filter to work correctly, all segments must start at
timestamp 0.
All of your inputs share the same parameters except for SAR (Sample [aka Pixel] Aspect Ratio) and frame rate. It is also always good practice to set the timestamps of all inputs to 0 (even if they already are at 0 it won't hurt to do so).
What you must do
Set timestamps to 0. The setpts filter will be used.
Two inputs have a SAR of 480:480, while the others has a SAR of 1:1. I'm not sure why they are set as 480:480 instead of 1:1. They all must either be 480:480 or 1:1. You can try both and see what looks best. The setsar filter will be used.
Two inputs have a frame rate of 24, one is 29.92, and one is 30. They all must have the same value, so the fps filter will be used.
Filtergraph syntax
A filtergraph is your complete filtering command. A filtergraph consists of filterchains. Filterchains consist of groups of filters connected via commas. Filterchains are connected via semicolons. The inputs and outputs of filterchains and filtergraphs can be named so they can be referenced by other filters or filterchains.
Basic filtergraph example
-filter_complex \
"[0:v]filter0,filter1,filter2[fc0]; \
[1:v]filter3,filter4,filter5[fc1]; \
[fc0][fc1]filter5[out]"
[0:v] refers to the video from the first input file.
[fc0] refers to the output from the first filterchain.
Actual filtergraph example
-filter_complex \
"[0:v]setsar=1/1,setpts=PTS-STARTPTS[v0]; \
[1:v]fps=24,setpts=PTS-STARTPTS[v1]; \
[2:v]setsar=1/1,setpts=PTS-STARTPTS[v2]; \
[3:v]fps=24,setpts=PTS-STARTPTS[v3]; \
[4:v]fps=24,setpts=PTS-STARTPTS[v4]; \
[v0][0:a][v1][1:a][v2][2:a][v3][3:a][v4][4:a]concat=n=5:v=1:a=1[v][a]"
I am trying to record from the video camera in my application. I have removed try/catch blocks and things of that nature to show an example of how to record:
camera.unlock();
mediaRecorder.setCamera(camera);
mediaRecorder.reset();
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
CamcorderProfile mCamcorderProfile = CamcorderProfile.get(CameraInfo.CAMERA_FACING_FRONT, CamcorderProfile.QUALITY_720P);
mediaRecorder.setProfile(mCamcorderProfile);
/*
mediaRecorder.setVideoEncodingBitRate(8000000);
mediaRecorder.setVideoEncodingBitRate(5000000);
mediaRecorder.setVideoEncodingBitRate(3000000);
*/
mediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecFile = File.createTempFile("Video", ".mp4", mRecVideoPath);
mediaRecorder.setOutputFile(mRecFile.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();
I record the video and it plays perfectly on the phone. Then I pull the video file off and I play it on a PC and the audio/video is slightly out of sync on a short 10 second clip. This only happens when recorded with a Samsung Note 3.
Just to be thorough, here is what I have tried:
Works perfectly on a Nexus 7
Works perfectly on a Samsung S3
Tried recording on two different Note 3
Tried various bitrates
For playing the out of sync video from the Note 3:
Played video on a Macbook pro, Chrome browser
Played video on a Macbook pro, quicktime
Played video on a Win7 pc
Out of sync on all of them.
When recording a video on the Note 3 with the stock camera app there is NO sync issue!
Update that I forgot: Using the highest quality setting I recorded a video with my app and one video with the stock camera. I inspected both videos and this is the output. I forget now which was which but the output is identical as far as I can tell.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20140719_155219.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2014-07-19 20:52:24
Duration: 00:00:04.97, start: 0.000000, bitrate: 16674 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17093 kb/s, 29.92 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2014-07-19 20:52:24
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 117 kb/s (default)
Metadata:
creation_time : 2014-07-19 20:52:24
handler_name : SoundHandle
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20140719160307.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2014-07-19 21:03:07
Duration: 00:00:06.61, start: 0.000000, bitrate: 16530 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 16473 kb/s, 29.92 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2014-07-19 21:03:07
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 117 kb/s (default)
Metadata:
creation_time : 2014-07-19 21:03:07
handler_name : SoundHandle