Convert audio file using another audio file as template in ffmpeg - ffmpeg

I have some .mp3 audio files, with different "configuration" like sample rate, bit rate, etc.
For my app, one of them is working and the rest, not.
How can I convert the rest of them using the working file's "configuration"?
Metadata of two sample files:
~/Downloads ❯ ffmpeg -i working.mp3 -i not_working.mp3
ffmpeg version 2.8.3 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 7.0.0 (clang-700.1.76)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
[mp3 # 0x7fd2d380da00] Skipping 0 bytes of junk at 33.
[mp3 # 0x7fd2d380da00] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'working.mp3':
Metadata:
encoder : Lavf52.64.2
Duration: 00:00:00.65, start: 0.000000, bitrate: 64 kb/s
Stream #0:0: Audio: mp3, 22050 Hz, mono, s16p, 64 kb/s
[mp3 # 0x7fd2d4008800] Skipping 0 bytes of junk at 417.
Input #1, mp3, from 'not_working.mp3':
Duration: 00:00:01.83, start: 0.025057, bitrate: 46 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 46 kb/s
Metadata:
encoder : LAME3.99r

You probably need to change the channel layout and/or sample rate:
ffmpeg -i input.mp3 -c:a libmp3lame -ar 22050 -ac 1 output.mp3
Try 3 commands: one without -ar 22050, one without -ac 1, and one with both as shown above.

Related

ffmpeg Output file #0 does not contain any stream when trying to access 1 of 2 audio streams

ffmpeg -i input.mkv -map 0:2 -c copy -strict -2 audio.mkv
Hi I have the above command. The output shows that there are 2 audio streams. I want to copy just the ac3 audio (actually I want to convert it but even this copy does not work). I have truncated the output print where there is metadata
NEW updated sample with full log which results in same message
ffmpeg -i input.mka -map 0:0 -c:a libfdk_aac aac_out.m4a
ffmpeg version 2.7.1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9.3 (crosstool-NG 1.20.0) 20150311 (prerelease)
configuration: --prefix=/usr --incdir='${prefix}/include/ffmpeg' --arch=i686 --target-os=linux --cross-prefix=/usr/local/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu- --enable-cross-compile --enable-optimizations --enable-pic --enable-gpl --enable-shared --disable-static --enable-version3 --enable-nonfree --enable-libfaac --enable-encoders --enable-pthreads --disable-bzlib --disable-protocol=rtp --disable-muxer=image2 --disable-muxer=image2pipe --disable-swscale-alpha --disable-ffserver --disable-ffplay --disable-devices --disable-bzlib --disable-altivec --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libmp3lame --disable-vaapi --disable-decoder=amrnb --disable-decoder=ac3 --disable-decoder=ac3_fixed --disable-encoder=zmbv --disable-encoder=dca --disable-encoder=ac3 --disable-encoder=ac3_fixed --disable-encoder=eac3 --disable-decoder=dca --disable-decoder=eac3 --disable-decoder=truehd --cc=/usr/local/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ccache-gcc --enable-yasm --enable-libx264 --enable-encoder=libx264
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, matroska,webm, from '/volume1/..../input.mka':
Metadata:
encoder : libebml v1.3.9 + libmatroska v1.5.2
creation_time : 2019-07-07 06:19:20
Duration: 02:29:21.98, start: 0.000000, bitrate: 640 kb/s
Stream #0:0(eng): Audio: ac3, 48000 Hz, 5.1(side), 640 kb/s
Metadata:
BPS-eng : 640000
DURATION-eng : 02:29:21.984000480
NUMBER_OF_FRAMES-eng: 280062
NUMBER_OF_BYTES-eng: 716958720
_STATISTICS_WRITING_APP-eng: mkvmerge v35.0.0 ('All The Love In The World') 64-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2019-07-07 06:19:20
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Output #0, ipod, to 'aac_out.m4a':
Metadata:
encoder : libebml v1.3.9 + libmatroska v1.5.2
Output file #0 does not contain any stream

ffmpeg volume not work in complex filter

"volume" filter does not work in complex filter. The volume is not affected in the converted audio.
env: Mac OS 10.12.6
ffmpeg -i /path/bg.mp3 -y -filter_complex [0:0]volume=0[output] -map
[output] -acodec libmp3lame -write_xing 0 /path/mixed.mp3
full log =====================================================================
liqideMacBook-Pro:pinyin-api work$ ffmpeg -i
/Users/work/dev/codebase/pinyin/pinyin-api/test/resources/bg_audio2.mp3
-y -filter_complex [0:0]volume=0.1[output] -map [output] -acodec
libmp3lame -f mp3 -write_xing 0 /Users/work/dev/codebase/pinyin/pinyin-
api/test/resources/mixed3.mp3
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-
shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --
enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-
gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-
opencl --enable-videotoolbox --disable-lzma
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mp3, from '/Users/work/dev/codebase/pinyin/pinyin-
api/test/resources/bg_audio2.mp3':
Metadata:
title : 喜洋洋
album : 贺岁新年音乐会
encoder : Lavf56.4.101
Duration: 00:02:43.58, start: 0.025057, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
Stream mapping:
Stream #0:0 (mp3) -> volume
volume -> Stream #0:0 (libmp3lame)
Press [q] to stop, [?] for help
Output #0, mp3, to '/Users/work/dev/codebase/pinyin/pinyin-
api/test/resources/mixed3.mp3':
Metadata:
TIT2 : 喜洋洋
TALB : 贺岁新年音乐会
TSSE : Lavf57.83.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp
Metadata:
encoder : Lavc57.107.100 libmp3lame
[libmp3lame # 0x7fad80001a00] Trying to remove 1152 samples, but the
queue is empty
size= 2556kB time=00:02:43.57 bitrate= 128.0kbits/s speed=51.7x
video:0kB audio:2556kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.003782%
liqideMacBook-Pro:pinyin-api work$
=====================================================================

Getting error while converting on FFMPEG? what's the meaning & how it should be fixed?

I am using this code to apply watermark on linux server;
-i input.mp4 logo.png -filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' output.mp4
so ended-up with this error;
Please use -b:a or -b:v, -b is ambiguous
Cannot find a matching stream for unlabeled input pad 1 on filter Parsed_overlay_0
Full error;
ffmpeg version N-71954-gbc6f84f Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --prefix=/usr --enable-version3 --enable-gpl --enable-shared --
enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libvpx --
enable-libx264 --enable-libxvid --enable-libopencore-amrwb --enable-libopencore-
amrnb --enable-postproc --enable-nonfree --enable-pthreads --enable-x11grab --
enable-libfaac --enable-libopenjpeg --enable-zlib --disable-doc
libavutil 54. 23.101 / 54. 23.101
libavcodec 56. 37.101 / 56. 37.101
libavformat 56. 31.102 / 56. 31.102
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
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 'uploaded/1502539665_21.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.31.102
enter code here
Duration: 00:02:27.32, start: 0.023220, bitrate: 635 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x320
[SAR 1:1 DAR 3:2], 476 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
enter code here
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 151 kb/s (default)
Metadata:
handler_name : SoundHandler
enter code here
Please use -b:a or -b:v, -b is ambiguous
Cannot find a matching stream for unlabeled input pad 1 on filter Parsed_overlay_0
Your image isn't presented as an input so ffmpeg treats it as the first output, and output.mp4 as the 2nd output. The filter_complex only sees the video as an input.
Start your command like this
ffmpeg -i input.mp4 -i logo.png

capture RTSP stream from IP camera ffmpeg

I used the following command to get the frames from RTSP h264 codec. I could not able to get the frames from the ip camera.
$ ffmpeg -i rtsp://xxxx:yyy#192.168.1.yy:xx/tcp/av0_0 -f image2 -vf fps=fps=1/120 img%03d.jpg
My output
ffmpeg version 3.1.1 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --disable-yasm
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
[rtsp # 0x2dba3a0] CSeq 6 expected, 0 received.
Last message repeated 5 times
[rtsp # 0x2dba3a0] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from
'rtsp://xx:yy#192.168.1.xx:yy/tcp/av0_0':
Metadata:
title : streamed by the RTSP server
Duration: N/A, start: 0.000000, bitrate: 64 kb/s
Stream #0:0: Video: h264, none, 90k tbr, 90k tbn, 180k tbc
Stream #0:1: Audio: pcm_alaw, 8000 Hz, 1 channels, s16, 64 kb/s
Output #0, image2, to 'img%03d.jpg':
Output file #0 does not contain any stream
Exiting normally, received signal 2.
I need to use rtsp_transport tcp. The following command works.
ffmpeg -rtsp_transport tcp -i rtsp://bb:cc#192.168.1.xx:yy/tcp/av0_0 -f image2 -vf fps=fps=1 hello/img%03d.png

FFMPEG options differences between two videos

So I'm working with a video build out of pngs. Making a video hasn't been too hard thanks to ffmpeg however most of the videos I've made work great playing forward and are extremely choppy playing backwards.
Using a program named MPEG Streamclip plus Handbrake I managed to convert my video to one that plays great forward and backward. But now I can't figure out how to pass in the right options to ffmpeg to replicate this video.
Using ffprobe I have some outputs of the good and bad video. What options am I missing?
Bad Video:
$ ffprobe tea_ffmpeg.mov
ffprobe version 3.0 Copyright (c) 2007-2016 the FFmpeg developers
built with Apple LLVM version 7.0.2 (clang-700.1.81)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-vda
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
libavfilter 6. 31.100 / 6. 31.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tea_ffmpeg.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf57.25.100
Duration: 00:00:08.04, start: 0.000000, bitrate: 1140 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 676x450 [SAR 675:676 DAR 3:2], 1138 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : DataHandler
encoder : Lavc57.24.102 libx264
Good Video:
$ ffprobe test.mov
ffprobe version 3.0 Copyright (c) 2007-2016 the FFmpeg developers
built with Apple LLVM version 7.0.2 (clang-700.1.81)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-vda
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
libavfilter 6. 31.100 / 6. 31.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2016-03-09 15:16:37
Duration: 00:00:08.04, start: 0.000000, bitrate: 2650 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 674x450, 2646 kb/s, 25 fps, 25 tbr, 25k tbn, 50k tbc (default)
Metadata:
creation_time : 2016-03-09 15:16:47
handler_name : Apple Alias Data Handler
encoder : H.264
FFMPEG Command so far:
ffmpeg -y -i 'pngs/tea-%03d.png' -vf scale=674:-2 -vcodec libx264 -pix_fmt yuv420p -r 25 tea_ffmpeg.mov
I understand mov vs mp4 should just be a container spec, but mov was the first I got working. I'm more than happy to use mp4.
The main thing that stands out is the profile. So,
ffmpeg -y -i 'pngs/tea-%03d.png' -vf scale=674:-2 -vcodec libx264 -profile:v main -pix_fmt yuv420p -r 25 tea_ffmpeg.mov
To be safer, you can use baseline profile and small GOP sizes (at some cost to file size)
ffmpeg -y -i 'pngs/tea-%03d.png' -vf scale=674:-2 -vcodec libx264 -profile:v baseline -g 12 -pix_fmt yuv420p -r 25 tea_ffmpeg.mov

Resources