BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

Mux Video and Audio from Two Videos - 2020

ffmpeg_new_logo_161_42.png




Bookmark and Share





bogotobogo.com site search:






Sample

We're going to mux two videos one for video source and the other one for audio source:

  1. Video source: San Francisco & GoldenGate Bridge (SF.mp4)
  2. Audio source: "San Francisco (Be Sure to Wear Flowers in Your Hair)" by Scott McKenzie (TwoBeSureToWear.mp4)





Muxing Two Videos
$ ffmpeg -i SF.mp4 -i TwoBeSureToWear.mp4
ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'SF.mp4':
    Stream #0:0L(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1170x714, 2661 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)

Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'TwoBeSureToWear.mp4':
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 960x720 [SAR 1:1 DAR 4:3], 847 kb/s, 29.97 fps, 29.97 tbr, 
    Stream #1:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)

The command looks like this:

$ ffmpeg -i SF.mp4 -i TwoBeSureToWear.mp4 -c copy -map 0:0 -map 1:1 -shortest SanFrancisco.mp4

From the first source (input #0) we take video (stream 0) (map 0:0), and from the 2nd source (input #1) we take audio (stream #1) (-map 1:1)

Note that we can achieve the same thing using the following command:

$ ffmpeg -i SF.mp4 -i TwoBeSureToWear.mp4 -c copy -map 0:v:0 -map 1:a:0 -shortest SanFrancisco2.mp4

where:

    -map 0:v:0 can be translated as: from the first input (0), take the video (v), first output video stream (0)
  • -map 1:a:0 can be translated as: from the second input (1), take the audio (a), first output audio stream (0)
  • The other parameters:

    1. -c copy : The desired streams will be copied, not re-encoded, so there will be no quality loss, and we'll get output quickly.
    2. -shortest : This option option will cause the output duration to match the duration of the shortest input stream.




    Output


    Your browser does not support the video tag.





    Offset (delay) Audio file

    To delay the audio start, we set an offset of 1 minute with -itsoffset option just before -i option as shown below:

    $ ffmpeg -i SF.mp4 -itsoffset 00:01:00.000 -i TwoBeSureToWear.mp4 -c copy -map 0:0 -map 1:1 -shortest SanFranciscoC.mp4
    




    Muxing One Video (video + audio) and Audio files

    Suppose we want to mux one video file which has video (valid) and audio (not needed) with another audio file which has desirable audio. We can just follow the logic of the previous section, and the command for concatenation looks like this:

    $ ffmpeg -i SF.mp4 -i  Two_BeSureToWearFlowersInYourHair.mp3 -c copy -map 0:0 -map 1:0 -shortest SanFranciscoB.mp4
    

    We took from 1st input (0) a video (0), and from 2nd input (1) an audio (0).


    The input audio file is available: Two_BeSureToWearFlowersInYourHair.mp3.


    The out file is here: SanFranciscoB.mp4.



    Muxing One Video (video + audio) and Audio files








Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

YouTubeMy YouTube channel

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







FFmpeg image & video processing



Image/video scaling

Image/video cropping

Cropdetect and ffplay

Speeding-up & slowing-down video

Basic slide show from images

Advanced slide show from images

Thumbnails -Selecting specific frames : I-frame extraction etc.

Creating a mosaic/tile of screenshots from a movie

Seeking and cutting sections of a video & audio

Concatenating two video files or two audio files

Transitions : fade-in & fade-out for 1 slide

Transitions : python script for fade-in & fade-out with two slides

Concatenate slides

Creating test videos

Screen Recording on Ubuntu A

Active window capture with Python on Ubuntu B




Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







OpenCV 3 -

image & video processing



Installing on Ubuntu 13

Mat(rix) object (Image Container)

Creating Mat objects

The core : Image - load, convert, and save

Smoothing Filters A - Average, Gaussian

Smoothing Filters B - Median, Bilateral






OpenCV 3 image and video processing with Python



OpenCV 3 with Python

Image - OpenCV BGR : Matplotlib RGB

Basic image operations - pixel access

iPython - Signal Processing with NumPy

Signal Processing with NumPy I - FFT and DFT for sine, square waves, unitpulse, and random signal

Signal Processing with NumPy II - Image Fourier Transform : FFT & DFT

Inverse Fourier Transform of an Image with low pass filter: cv2.idft()

Image Histogram

Video Capture and Switching colorspaces - RGB / HSV

Adaptive Thresholding - Otsu's clustering-based image thresholding

Edge Detection - Sobel and Laplacian Kernels

Canny Edge Detection

Hough Transform - Circles

Watershed Algorithm : Marker-based Segmentation I

Watershed Algorithm : Marker-based Segmentation II

Image noise reduction : Non-local Means denoising algorithm

Image object detection : Face detection using Haar Cascade Classifiers

Image segmentation - Foreground extraction Grabcut algorithm based on graph cuts

Image Reconstruction - Inpainting (Interpolation) - Fast Marching Methods

Video : Mean shift object tracking

Machine Learning : Clustering - K-Means clustering I

Machine Learning : Clustering - K-Means clustering II

Machine Learning : Classification - k-nearest neighbors (k-NN) algorithm



Matlab Image and Video Processing



Vectors and Matrices

m-Files (Scripts)

For loop

Indexing and masking

Vectors and arrays with audio files

Manipulating Audio I

Manipulating Audio II

Introduction to FFT & DFT

Discrete Fourier Transform (DFT)



Digital Image Processing 2 - RGB image & indexed image

Digital Image Processing 3 - Grayscale image I

Digital Image Processing 4 - Grayscale image II (image data type and bit-plane)

Digital Image Processing 5 - Histogram equalization

Digital Image Processing 6 - Image Filter (Low pass filters)

Video Processing 1 - Object detection (tagging cars) by thresholding color

Video Processing 2 - Face Detection and CAMShift Tracking












Contact

BogoToBogo
contactus@bogotobogo.com

Follow Bogotobogo

About Us

contactus@bogotobogo.com

YouTubeMy YouTube channel
Pacific Ave, San Francisco, CA 94115

Pacific Ave, San Francisco, CA 94115

Copyright © 2024, bogotobogo
Design: Web Master