Skip to content

Instantly share code, notes, and snippets.

@lukasz-madon
Created December 14, 2014 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukasz-madon/508d76d6fd5ff3635494 to your computer and use it in GitHub Desktop.
Save lukasz-madon/508d76d6fd5ff3635494 to your computer and use it in GitHub Desktop.
I wanna write a small tool that will swap music from my youtube video. Currently it's binary
if override_audio:
o_cmd = ["ffmpeg", "-i", music_url, "-i", video_url, "-codec", "copy",
"-y", "-shortest", output_video]
logger.info(o_cmd)
code = sp.call(o_cmd)
else:
cmd = ["ffmpeg", "-i", music_url, "-i", video_url, "-filter_complex",
"amix=duration=shortest", "-vcodec", "copy", "-y", "-shortest",
output_video]
logger.info(cmd)
code = sp.call(cmd)
now I would like to control the audio volume(later on I would need to control it by timestamp, but for now a global one is ok)
I'm experimenting with -filter_complex
fmpeg -i jingiel_bacterion_v2.mp3 -i trailer.wmv -filter_complex "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];[a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]" -map 1:v -map "[out]" -c:v copy -shortest out_vid3.wmv
ffmpeg version 1.2.4 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 12 2014 21:05:32 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[mp3 @ 0x7f87cb004a00] max_analyze_duration 5000000 reached at 5015510 microseconds
Input #0, mp3, from 'jingiel_bacterion_v2.mp3':
Duration: 00:00:35.03, start: 0.000000, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
[wmv3 @ 0x7f87cb03c600] Extra data: 8 bits left, value: 0
[asf @ 0x7f87cb02ae00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #1, asf, from 'trailer.wmv':
Metadata:
WMFSDKNeeded : 0.0.0.0000
DeviceConformanceTemplate: M0
WM/WMADRCPeakReference: 15881
WM/WMADRCPeakTarget: 15881
WM/WMADRCAverageReference: 2767
WM/WMADRCAverageTarget: 2767
WMFSDKVersion : 12.0.7601.17514
IsVBR : 0
Duration: 00:01:09.55, start: 0.000000, bitrate: 3634 kb/s
Stream #1:0: Video: mjpeg, yuvj420p, 1920x1080, 90k tbr, 90k tbn, 90k tbc
Metadata:
comment : Movie/video screen capture
Stream #1:1: Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 1920x1080, 24000 kb/s, 29.97 tbr, 1k tbn, 1k tbc
Stream #1:2: Audio: wmapro (b[1][0][0] / 0x0162), 48000 Hz, stereo, fltp, 128 kb/s
[Parsed_amerge_4 @ 0x7f87cac29320] No channel layout for input 1
[Parsed_amerge_4 @ 0x7f87cac29320] Query format failed for 'Parsed_amerge_4': Invalid argument
ffmpeg -i jingiel_bacterion_v2.mp3 -i trailer.wmv -filter_complex "[0:a]volume=0.390625[a1];[1:a]volume=0.781250[a2];[a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3" -shortest output.wmv
ffmpeg version 1.2.4 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 12 2014 21:05:32 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[mp3 @ 0x7fa401004a00] max_analyze_duration 5000000 reached at 5015510 microseconds
Input #0, mp3, from 'jingiel_bacterion_v2.mp3':
Duration: 00:00:35.03, start: 0.000000, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
[wmv3 @ 0x7fa40103c600] Extra data: 8 bits left, value: 0
[asf @ 0x7fa40102ae00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #1, asf, from 'trailer.wmv':
Metadata:
WMFSDKNeeded : 0.0.0.0000
DeviceConformanceTemplate: M0
WM/WMADRCPeakReference: 15881
WM/WMADRCPeakTarget: 15881
WM/WMADRCAverageReference: 2767
WM/WMADRCAverageTarget: 2767
WMFSDKVersion : 12.0.7601.17514
IsVBR : 0
Duration: 00:01:09.55, start: 0.000000, bitrate: 3634 kb/s
Stream #1:0: Video: mjpeg, yuvj420p, 1920x1080, 90k tbr, 90k tbn, 90k tbc
Metadata:
comment : Movie/video screen capture
Stream #1:1: Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 1920x1080, 24000 kb/s, 29.97 tbr, 1k tbn, 1k tbc
Stream #1:2: Audio: wmapro (b[1][0][0] / 0x0162), 48000 Hz, stereo, fltp, 128 kb/s
File 'output.wmv' already exists. Overwrite ? [y/N] y
No channel layout for input 1
[Parsed_amerge_2 @ 0x7fa400e009c0] Query format failed for 'Parsed_amerge_2': Invalid argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment