Overlaying in FFmpeg failed due to audio codec – how to fix it?

0

I am using FFmpeg to overlay a series of images on video but on some occasions on some MP4 videos it fails (but sometimes it works perfectly).  My command gives an error like:

Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

My ffmpeg command is given below:

ffmpeg -y -i myvideo.mp4 -loop 1 -i img_%d.png -strict -2 -filter_complex [0:v][1:v]overlay=39:54:shortest=1:enable='between(t,0,4)' -codec:a copy Preview.mp4 



 WARNING: linker: /data/data/com.benzatine.videoeffects/app_bin/ffmpeg  has text relocations. This is wasting memory and prevents security 

hardening. Please fix.
     ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
     built with gcc 4.9 (GCC) 20140827 (prerelease)
     configuration:
     --enable-cross-compile --cross-prefix=i686-linux-android- --target- os=linux --arch=x86 --cpu=x86 --disable-doc --disable-ffplay
     --disable-ffprobe --disable-ffserver --disable-symver --disable-debug --disable-everything --enable-protocol=pipe 
     --enable-protocol=file --enable-protocol=tcp --enable-static --enable-filter=scale --enable-filter=crop --enable-filter=transpose 
 --enable-filter=overlay --enable-encoder=gif --enable-decoder=gif --enable-muxer=gif --enable-demuxer=gif --enable-filter=palettegen 
 --enable-filter=paletteuse --enable-encoder=mpeg4 --enable-decoder=mpeg4 --enable-demuxer=rawvideo --enable-decoder=rawvideo --enable-muxer=image2 
 --enable-muxer=image2pipe --enable-muxer=mjpeg --enable-encoder=mjpeg --enable-encoder=png --enable-demuxer=image2 --enable-demuxer=image2pipe
 --enable-demuxer=mjpeg --enable-decoder=mjpeg --enable-decoder=png --enable-muxer=webm --enable-encoder=libvpx_vp8 --enable-demuxer=matroska
 --enable-decoder=libvpx_vp8 --enable-libx264 --enable-gpl --enable-muxer=mp4 --enable-encoder=libx264 --enable-demuxer=mov --enable-decoder=h264
 libavutil      55. 17.103 / 55. 17.103
 libavcodec     57. 24.102 / 57. 24.102
 libavformat    57. 25.100 / 57. 25.100
 libavdevice    57.  0.101 / 57.  0.101
 E/ERROR(3219):   libavfilter     6. 31.100 /  6. 31.100
 libswscale      4.  0.100 /  4.  0.100
 libswresample   2.  0.101 /  2.  0.101
 libpostproc    54.  0.100 / 54.  0.100
 Guessed Channel Layout for  Input Stream #0.1 : mono
 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/VideoStikers/myvideo.mp4':
 Metadata:
 major_brand     : mp42
 minor_version   : 0
 compatible_brands: isommp42
 creation_time   : 2016-03-02 09:37:42
 Duration: 00:00:04.16, start: 0.000000, bitrate: 900 kb/s
 Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 320x240, 97 kb/s, SAR 1:1 DAR 4:3, 16.26 fps, 24.67 tbr, 90k tbn, 180k tbc (default)
 Metadata:
 rotate          : 90
 creation_time   : 2016-03-02 09:37:4
 handler_name    : VideoHandle
 Side data:
 displaymatrix: rotation of -90.00 degrees
 Stream #0:1(eng): Audio: amr_nb (samr / 0x726D6173), 8000 Hz, 1 channels, 12 kb/s (default)
 Metadata:
 creation_time   : 2016-03-02 09:37:42
 handler_name    : SoundHandle
 Input #1, image2, from '/storage/emulated/0/VideoStikers/02/img_%d.png':
 Duration: 00:00:01.00, start: 0.000000, bitrate: N/A
 Stream #1:0: Video: png, rgba(pc), 108x98, 25 fps, 25 tbr, 25 tbn, 25 tbc
 [libx264 @ 0xf6827000] using SAR=1/1
 [libx264 @ 0xf6827000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX LZCNT
 [libx264 @ 0xf6827000] profile High, level 1.3
 [libx264 @ 0xf6827000] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
 [mp4 @ 0xf685c000] Could not find tag for codec amr_nb in stream #1, codec not currently supported in container
 Output #0, mp4, to '/storage/emulated/0/VideoStikers/PreviewVideoStikers/Preview.mp4':
 Metadata:
 major_brand     : mp42
 minor_version   : 0
 compatible_brands: isommp42
 encoder         : Lavf57.25.100
 Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 240x320 [SAR 1:1 DAR 3:4], q=-1--1, 24.67 fps, 18944 tbn, 24.67 tbc (default)
 Metadata:
 encoder         : Lavc57.24.102 libx264
 Side data:
 unknown side data type 10 (24 bytes)
 Stream #0:1(eng): Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, 12 kb/s (default)
 Metadata:
 creation_time   : 2016-03-02 09:37:42
 handler_name    : SoundHandle
 Stream mapping:
 Stream #0:0 (h264) -> overlay:main
 Stream #1:0 (png) -> overlay:overlay
 overlay -> Stream #0:0 (libx264)
 Stream #0:1 -> #0:1 (copy)
 Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
: 1

Can anybody suggest me the proper solution?

user3269550

Posted 2016-03-02T10:19:14.213

Reputation: 13

@HoldOffHunger: (1) Please, when you edit a post, try hard to fix all the problems. Tiny, trivial edits are discouraged. You missed quite a few errors here. (2) Take care that your changes are correct, and are improvements. In particular, “FFmpeg” *is* the standard capitalization of the name of that program. (3) Also, please use accurate edit comments. You have been saying “Grammar” when all you changed was capitalization. Here you said “Grammar and spelling.” when what you changed was capitalization, formatting and punctuation.

– Scott – 2017-12-18T06:42:46.393

@Scott: Thanks for the note. (1) True -- I did miss a few in the first sentence, but most of this post is an error message without much editability. (2) I found more posts using FFMPEG instead of FFmpeg. – None – 2017-12-18T13:36:26.093

Answers

0

It looks like ffmpeg MOV muxer doesn't support amr_nb in mp4, but try

ffmpeg -y -i myvideo.mp4 -loop 1 -i img_%d.png -strict -2 \
-filter_complex [0:v][1:v]overlay=39:54:shortest=1:enable='between(t,0,4)' \
-atag samr -copy_unknown -c:a copy Preview.mp4 

If not,

ffmpeg -y -i myvideo.mp4 -loop 1 -i img_%d.png -strict -2 \
-filter_complex [0:v][1:v]overlay=39:54:shortest=1:enable='between(t,0,4)' \
-c:a aac Preview.mp4 

Gyan

Posted 2016-03-02T10:19:14.213

Reputation: 21 016

your second command gives error as unknown encoder aac – user3269550 – 2016-03-02T10:38:29.730

I want my command should work with all video i just want to copy and past the audio stream – user3269550 – 2016-03-02T10:39:33.870

and first command gives same error as my question command gives – user3269550 – 2016-03-02T10:46:01.887

Looks like your build does not have any audio codec compiled in. You need a build with at least decoders and encoders for AAC, PCM, MP3, and for this specific file AMR-NB. – Gyan – 2016-03-02T10:56:31.283

can I some how directly copy audio stream i thought i did no need audio encoders and decoders for overlaying just video – user3269550 – 2016-03-02T11:00:02.683

You need the demuxer/muxer to read & write the audio packets. Your build doesn't have them. – Gyan – 2016-03-02T11:43:23.760

which muxers and demuxers? please can u tell me so that i can build new ffmpeg with that options – user3269550 – 2016-03-02T12:58:45.910