FFMPEG amerge fails when one audio stream is missing - ffmpeg

I am trying to combine two video files (of size 320x240) and create a single, horizontally extended output video file (of size 640x240) but for the audio merging, the command fails when one of the input files does not contain audio stream.
Here's the command I am using:
C:\ffmpeg\bin\ffmpeg.exe -y -i "input1.flv" -i "input2.flv" -filter_complex "nullsrc=size=640x240[base];[0:v]scale=320x240[upperleft];[1:v]scale=320x240[upperright];[base][upperleft]overlay=shortest=1[tmp1];[tmp1][upperright]overlay=shortest=1:x=320:y=0;[0:a][1:a]amerge=inputs=2[aout]" -map [aout] -ac 2 "output.mp4"
This command works fine when both input1.flv and input2.flv contain audio tracks. When either one lacks an audio track, the command gives the following error:
[flv # 0000000004300660] Stream discovered after head already parsed
[flv # 0000000004300660] Could not find codec parameters for stream 1
(Audio: none, 0 channels): unspecified sample format Consider
increasing the value for the 'analyzeduration' and 'probesize' options
Input #1, flv, from 'input2.flv': Metadata:
creationdate : Tue Jan 26 16:50:12 Duration: 00:25:59.10, start: 0.000000, bitrate: 212 kb/s
Stream #1:0: Video: flv1, yuv420p, 320x240, 1k tbr, 1k tbn, 1k tbc
Stream #1:1: Audio: none, 0 channels
Stream #1:2: Data: none [abuffer # 0000000004335620] Value inf for parameter 'time_base' out of range [0 - 2.14748e+009] [abuffer #
0000000004335620] Unable to parse option value "(null)" as sample
format [abuffer # 0000000004335620] Value inf for parameter
'time_base' out of range [0 - 2.14748e+009] [abuffer #
0000000004335620] Error setting option time_base to value 1/0. [graph
0 input from stream 1:1 # 00000000042e4d60] Error applying options to
the filter. Error configuring filters.
Is there a way to make this command work even when one audio stream lacks an audio track or both of the audio streams lack audio tracks?

There's one preparatory command that needs to be executed only once,to generate a file
ffmpeg -f lavfi -t 1 -i anullsrc:r=48000 silence.mkv
For each flv,
ffmpeg -i input1.flv -analyzeduration 10M -i silence.mkv -c copy -map 0 -map 1 input1a.mkv
ffmpeg -i input2.flv -analyzeduration 10M -i silence.mkv -c copy -map 0 -map 1 input2a.mkv
And then,
ffmpeg -i input1a.mkv -i input2a.mkv -filter_complex "[0:v][1:v]hstack=shortest=1[v];[0:a][1:a]amerge[a]" -map [v] -map [a] -ac 2 "output.mp4"

Related

ignore "channel_layout" when working with multichannel audio in ffmpeg

I'm working with multichannel audio files (higher-order ambisonics), that typically have at least 16 channels.
Sometimes I'm only interested in a subset of the audiochannels (e.g. the first 25 channels of a file that contains even more channels).
For this I have a script like the following, that takes a multichannel input file, an output file and the number of channels I want to extract:
#!/bin/sh
infile=$1
outfile=$2
channels=$3
channelmap=$(seq -s"|" 0 $((channels-1)))
ffmpeg -y -hide_banner \
-i "${infile}" \
-filter_complex "[0:a]channelmap=${channelmap}" \
-c:a libopus -mapping_family 255 -b:a 160k -sample_fmt s16 -vn -f webm -dash 1 \
"${outfile}"
The actual channel extraction is done via the channelmap filter, that is invoked with something like -filter:complex "[0:a]channelmap=0|1|2|3"
This works great with 1,2,4 or 16 channels.
However, it fails with 9 channels, and 25 and 17 (and generally anything with >>16 channels).
The error I get is:
$ ffmpeg -y -hide_banner -i input.wav -filter_complex "[0:a]channelmap=0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16" -c:a libopus -mapping_family 255 -b:a 160k -sample_fmt s16 -vn -f webm -dash 1 output.webm
Input #0, wav, from 'input.wav':
Duration: 00:00:09.99, bitrate: 17649 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 25 channels, s16, 17640 kb/s
[Parsed_channelmap_0 # 0x5568874ffbc0] Output channel layout is not set and cannot be guessed from the maps.
[AVFilterGraph # 0x5568874fff40] Error initializing filter 'channelmap' with args '0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16'
Error initializing complex filters.
Invalid argument
So ffmpeg cannot guess the channel layout for a 17 channel file.
ffmpeg -layouts only lists channel layouts with 1,2,3,4,5,6,7,8 & 16.
However, I really don't care about the channel layout. The entire concept of "channel layout" is centered around the idea, that each audio channel should go to a different speaker.
But my audio channels are not speaker feeds at all.
So I tried providing explicit channel layouts, with something like -filter_complex "[0:a]channelmap=map=0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16:channel_layout=unknown", but this results in an error when parsing the channel layout:
$ ffmpeg -y -hide_banner -i input.wav -filter_complex "[0:a]channelmap=map=0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16:channel_layout=unknown" -c:a libopus -mapping_family 255 -b:a 160k -sample_fmt s16 -vn -f webm -dash 1 output.webm
Input #0, wav, from 'input.wav':
Duration: 00:00:09.99, bitrate: 17649 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 25 channels, s16, 17640 kb/s
[Parsed_channelmap_0 # 0x55b60492bf80] Error parsing channel layout: 'unknown'.
[AVFilterGraph # 0x55b604916d00] Error initializing filter 'channelmap' with args 'map=0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16:channel_layout=unknown'
Error initializing complex filters.
Invalid argument
I also tried values like any, all, none, 0x0 and 0xFF with the same result.
I tried using mono (as the channels are kind-of independent), but ffmpeg is trying to be clever and tells me that a mono layout must not have 17 channels.
I know that ffmpeg can handle multi-channel files without a layout.
E.g. converting a 25-channel file without the -filter_complex "..." works without problems, and ffprobe gives me an unknown channel layout.
So: how do I tell ffmpeg to just not care about the channel_layout when creating an output file that only contains a subset of the input channels?
Based on Audio Channel Manipulation you could try splitting into n separate streams the amerge them back together:
-filter_complex "\
[0:a]pan=mono|c0=c0[a0];\
[0:a]pan=mono|c0=c1[a1];\
[0:a]pan=mono|c0=c2[a2];\
[0:a]pan=mono|c0=c3[a3];\
[0:a]pan=mono|c0=c4[a4];\
[0:a]pan=mono|c0=c5[a5];\
[0:a]pan=mono|c0=c6[a6];\
[0:a]pan=mono|c0=c7[a7];\
[0:a]pan=mono|c0=c8[a8];\
[0:a]pan=mono|c0=c9[a9];\
[0:a]pan=mono|c0=c10[a10];\
[0:a]pan=mono|c0=c11[a11];\
[0:a]pan=mono|c0=c12[a12];\
[0:a]pan=mono|c0=c13[a13];\
[0:a]pan=mono|c0=c14[a14];\
[0:a]pan=mono|c0=c15[a15];\
[0:a]pan=mono|c0=c16[a16];\
[a0][a1][a2][a3][a4][a5][a6][a7][a8][a9][a10][a11][a12][a13][a14][a15][a16]amerge=inputs=17"
Building on the answer from #aergistal, and working with an mxf file with 10 audio streams, I had to modify the filter in order to specify the input to every pan filter. Working with "pan=mono" it only uses one channel identified as c0
-filter_complex "\
[0:a:0]pan=mono|c0=c0[a0];\
[0:a:1]pan=mono|c0=c0[a1];\
[0:a:2]pan=mono|c0=c0[a2];\
[0:a:3]pan=mono|c0=c0[a3];\
[0:a:4]pan=mono|c0=c0[a4];\
[0:a:5]pan=mono|c0=c0[a5];\
[0:a:6]pan=mono|c0=c0[a6];\
[0:a:7]pan=mono|c0=c0[a7];\
[0:a:8]pan=mono|c0=c0[a8];\
[0:a:9]pan=mono|c0=c0[a9];\
[a0][a1][a2][a3][a4][a5][a6][a7][a8][a9]amerge=inputs=10"

FFmpeg: Choosing audio streams by language

I am trying to transcode tv streams but with only the english audio stream included. I have tried using the -map 0:m:language:eng stream specifier, but I get:
"Automatic encoder selection failed for output stream #0:3. Default encoder for format mpegts (codec none) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:3"
This is despite including an encoder. I have tried all sorts of variations on this theme without success.
Full output for one attempt is below:
ffmpeg -i http://192.168.1.74:8001/1:0:1:189E:7FD:2:11A0000:0:0:0: -ignore_unknown -map 0:a -map 0:m:language:eng -map 0:v -acodec aac -vcodec libx264 -b:v 1100000 -t 00:00:30 "somethin.ts" 2>output.txt
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts # 03db7b60] Could not find codec parameters for stream 17 (Unknown: none ([11][0][0][0] / 0x000B)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts # 03db7b60] Could not find codec parameters for stream 18 (Unknown: none ([11][0][0][0] / 0x000B)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'http://192.168.1.74:8001/1:0:1:189E:7FD:2:11A0000:0:0:0:':
Duration: N/A, start: 23690.732933, bitrate: N/A
Program 6321
Program 6322
Program 6338
Program 6301
Program 6302
Stream #0:0[0x13ec]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x13ee](NAR): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 224 kb/s
Stream #0:2[0x13ed](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 224 kb/s
Stream #0:3[0x13ef](eng,eng): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
Stream #0:4[0x13f0](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:5[0xf04]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:6[0xf03]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:7[0xf02]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:8[0xf01]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:9[0xf00]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:10[0x92a]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:11[0x913]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:12[0x912]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:13[0x911]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:14[0x919]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:15[0xf09]: Unknown: none ([11][0][0][0] / 0x000B)
Stream #0:16[0xf08]: Unknown: none ([11][0][0][0] / 0x000B)
Stream #0:17[0xf07]: Unknown: none ([11][0][0][0] / 0x000B)
Stream #0:18[0xf06]: Unknown: none ([11][0][0][0] / 0x000B)
Program 6318
Program 6390
Program 6391
Program 6351
Program 6361
Program 6306
Program 6341
Automatic encoder selection failed for output stream #0:3. Default encoder for format mpegts (codec none) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:3
Any ideas on how to do this. I cant specify streams by number as I want to use it for lots of tv streams and the order is often different.
Thanks
Output stream 0:3 is a image-based subtitle stream. Since you've not specified an encoder for subtitles, ffmpeg is trying to pick one and fails since it doesn't have an image-based subtitle encoder. You can copy or drop the stream.
ffmpeg -i http://192.168.1.74:8001/1:0:1:189E:7FD:2:11A0000:0:0:0: -ignore_unknown -c copy -map 0:a -map 0:m:language:eng -map 0:v -acodec aac -vcodec libx264 -b:v 1100000 -t 00:00:30 "somethin.ts" 2>output.txt
Of course, your primary aim is to map only the audio stream by language. Your command will map the video twice, as it is tagged as English.
To avoid this, you can use two ffmpeg commands:
ffmpeg -i http://192.168.1.74:8001/1:0:1:189E:7FD:2:11A0000:0:0:0: -ignore_unknown -c copy -map 0:v:0 -map 0:m:language:eng -f mpegts - | ffmpeg -f mpegts -i - -map 0:v:0 -map 0:a:0 -c:a aac -c:v libx264 -b:v 1.1M out.ts

FFMPEG attach file as metadata

I have a set of images which I want to convert to a video using ffmpeg. The following command works perfectly fine:
ffmpeg -y -i frames/%06d.png -c:v huffyuv -pix_fmt rgb24 testout.mkv
I have some meta data in a binary file which I want to attach with the video. I tried doing the following, but it gives me an error:
ffmpeg -y -i frames/%06d.png -c:v huffyuv -pix_fmt rgb24 -attach mybinaryfile -metadata:s:2 mimetype=application/octet-stream testout.mkv
This is the error:
[matroska # 0x656460] Codec for stream 1 does not use global headers but container format requires global headers
[matroska # 0x656460] Attachment stream 1 has no mimetype tag and it cannot be deduced from the codec id.
Output #0, matroska, to 'testout.mkv':
Metadata:
encoder : Lavf56.33.101
Stream #0:0: Video: huffyuv (HFYU / 0x55594648), rgb24, 640x640, q=2-31, 200 kb/s, 25 fps, 1k tbn, 25 tbc
Metadata:
encoder : Lavc56.39.100 huffyuv
Stream #0:1: Attachment: none
Metadata:
filename : 2ceb-1916-56bb-3e10
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> huffyuv (native))
File 2ceb-1916-56bb-3e10 -> Stream #0:1
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
It would be wonderful if somebody can explain to me what am I doing wrong :)
You need to specify your stream properly
Example:
ffmpeg -y -i frames/%06d.png -c:v huffyuv -pix_fmt rgb24 -attach mybinaryfile \
-metadata:s:t mimetype=application/octet-stream testout.mkv
This command will set the metadata for all attachment (t) streams (s). If you have more than one attachment, and the metadata are different, then you will have to be more specific, such as:
-metadata:s:t:0 mimetype=text/plain \
-metadata:s:t:1 mimetype=application/gzip
This will set the metadata for the first attachment as mimetype=text/plain, and the second as mimetype=application/gzip. Remember that the stream index starts at 0, so the first steam is labeled 0.
What was wrong with your command
Using -metadata:s:2 (which appears to have been copied verbatim from the documentation) sets the metadata for the third stream, regardless of stream type (because no specifier is present), but your output only contained two streams.
Attachment: None
You may see something like this:
Output #0, matroska, to 'output.mkv':
...
Stream #0:1: Attachment: none
Metadata:
filename : 2ceb-1916-56bb-3e10
mimetype : application/octet-stream
Attachment: none does not mean that there is no attachment, but that there is no format associated with it, so it can be ignored.
Also see
Stream specifiers and the ffmpeg documentation on -attach, -metadata, and -map_metadata for more details.

FFmpeg: Image sequence with ffv1 codec?

Is it possible to output an image sequence in ffmpeg using the ffv1 codec?
If so, in what container, how would I reimport these back into ffmpeg?
movie containers seem not possible for seq output
i can force output -f image2 to any container, but import is not possible even with -c:v ffv1 as an input option.
Encode of "intermediate.ffv1"
ffmpeg -y -ss 250 -i "/media/pool/vrender_input/movie.mov" -vframes 1 -c:v ffv1 -compression_level none -map 0:0 -an -f image2 -threads 0 "/media/scratch/intermediate.ffv1"
Decode of "intermediate.ffv1"
ffmpeg -y -c:v ffv1 -f image2 -i "/media/scratch/intermediate.ffv1" -c:v tiff -an -f image2 "/media/scratch/final.tif"
Error:
[image2 # 0x2f85c80] Failed to open codec in av_find_stream_info
[image2 # 0x2f85c80] Could not find codec parameters for stream 0 (Video: ffv1, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
/media/scratch2/vrender_tmp/intermediate.ffv1: could not find codec parameters
Input #0, image2, from '/media/scratch2/vrender_tmp/intermediate.ffv1':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: ffv1, none, 25 tbr, 25 tbn, 25 tbc
[buffer # 0x2f7ce20] Unable to parse option value "0x0" as image size
[buffer # 0x2f7ce20] Unable to parse option value "-1" as pixel format
[buffer # 0x2f7ce20] Unable to parse option value "0x0" as image size
[buffer # 0x2f7ce20] Error setting option video_size to value 0x0.
[graph 0 input from stream 0:0 # 0x2f6cfc0] Error applying options to the filter.
Error opening filters!
Whats wrong?
Thank you!

Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

I am using this command to convert an avi,mov,m4v video files to flv format via FFMPEG
/usr/local/bin/ffmpeg -i '/home/public_html/files/video_1355440448.m4v' -s '640x360' -sameq -ab '64k' -ar '44100' -f 'flv' -y /home/public_html/files/video_1355440448.flv
[flv # 0x68b1a80] requested bitrate is too low
Output #0, flv, to '/home/files/1355472099-50cadce349290.flv':
Stream #0.0: Video: flv, yuv420p, 640x360, q=2-31, pass 2, 200 kb/s, 90k tbn, 25 tbc
Stream #0.1: Audio: adpcm_swf, 44100 Hz, 2 channels, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height
-------------------------------
RESULT
-------------------------------
Execute error. Output for file "/home/public_html/files/video_1355472099.avi" was found, but the file contained no data. Please check the available codecs compiled with FFmpeg can support this type of conversion. You can check the encode decode availability by inspecting the output array from PHPVideoToolkit::getFFmpegInfo().
But if I manually used this command then its working
/usr/local/bin/ffmpeg -i '/home/public_html/files/video_1355440448.m4v' -s '640x360' -sameq -ab '64k' -ar '44100' -f 'flv' -y /home/public_html/files/video_1355440448.flv
This is because you have two streams and output will be encoding then resizing, see your output messages:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
... you use adpcm_swf audio and yuv420p video
The answer is very simple, you need to put copy as your audio codec ...
See my example with video mpeg4,yuv420p and audio ac3 ...
ffmpeg -i input.mkv -vf scale=720:-1 -acodec copy -threads 12 output.mkv
this will change first size = 720 with aspect ratio = -1 (unknown). Also you need to use:
-acodec copy -threads 12
If don't use this you will have one error.
For example: When I used it, the output encoding messages show me this and it works well:
[h624 # 0x874e4a0] missing picture in access unit93 bitrate=1034.4kbits/s
Last message repeated 1163 times5974kB time=53.47 bitrate= 915.3kbits/s
You need to use for flv format file, something like this:
ffmpeg -i input.mp4 -c:v libx264 -crf 19 output.flv
You are given an error message
[flv # 0x68b1a80] requested bitrate is too low
You need to change bitrate to a valid. It is better if you use a different codec
-acodec libmp3lame
And remove the option -sameq. This option does NOT mean 'same quality'. Actually means 'same quantizers'!
I had a similar problem due to size constraints. The original image size was strange (width=1343), meaning that when I tried to specify a new size with -s, any rounding error caused problems. Make sure that the new image size can have the exact same aspect ratio!
I have got the same issue
- requested bitrate is too low
and just resolved this issue by lowering down the bit rate
by adding -b:a 32k

Resources