Concatenating two.mov files results in identical sized file - ffmpeg

I try to concatenate two video files a.mov & b.mov on Win 10 using ffmpeg with the following command:
ffmpeg -safe 0 -f concat -i list.txt -vcodec copy -acodec copy c.mov
There are no errors displayed however when I open the resulting file c it has the same length as file a with the last frame appering to be a frame of b.
File a is a longer video, file b are credits (couple of seconds) made with ffmpeg from an image file.
Both files have the same aspect ratio, size and framerate.
I try to concatenate two video files a.mov & b.mov on Win 10 using ffmpeg with the following command:
ffmpeg -safe 0 -f concat -i list.txt -vcodec copy -acodec copy c.mov
There are no errors displayed however when I open the resulting file c it has the same length as file a with the last frame appering to be a frame of b.
File a is a longer video, file b are credits (couple of seconds) made with ffmpeg from an image file.
Both files have the same aspect ratio, size and framerate.
Here the log:
ffmpeg -n -i a.mov -i b.mov
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 9.3.1 (GCC) 20200523 configuration: --enable-gpl --enable-version3 --enable-sdl2
--enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 /
58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 /
3. 5.100 libpostproc 55. 5.100 / 55. 5.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a.mov': Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.62.100 Duration: 00:31:50.04, start: 0.000000, bitrate: 5309 kb/s
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 4151 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : Core Media Video
encoder : Lavc58.54.100 libx264
Stream #0:1: Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
handler_name : SoundHandler Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'b.mov': Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.29.100 Duration: 00:00:10.01, start: 0.000000, bitrate: 67 kb/s
Stream #1:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 64 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.54.100 libx264
Thank you.

Problems
Your inputs have some different attributes, but they need to be the same to concatenate:
The timescales (30k vs 11988) are different. This is probably due to a.mov having 30000/1001 proper NTSC frame rate and b.mov is 29.97. ffprobe can confirm this. The ffmpeg output is for "entertainment purposes only" and reports an abbreviated frame rate.
a.mov has audio, but b.mov does not.
To fix it
Re-mux b.mov and add silent audio:
ffmpeg -i b.mov -f lavfi -i anullsrc=r=48000:cl=mono -c:v copy -c:a pcm_s24le -video_track_timescale 30k -shortest b2.mov
Then update list.txt with the new file (b2.mov).
Concatenate:
ffmpeg -safe 0 -f concat -i list.txt -c copy c.mov
Options
-f lavfi -i anullsrc=r=48000:cl=mono makes silent audio with 48000 sample rate and mono channel layout. This matches the sample rate and channel layout of a.mov. You can't concatenate an input with audio with an input that has no audio, so this just creates silent filler/dummy audio.
-c:v copy stream copy the video.
-c:a pcm_s24le chooses the encoder pcm_s24le to create an audio format that matches a.mov.
-video_track_timescale 30k sets video timescale to match a.mov. See What is video timescale, timebase, or timestamp in ffmpeg?
-shortest ends the output whenever the shortest input ends. Needed because I did not set a duration for anullsrc (using -shortest is easier).

Related

How can I concatenate 2 videos with audio using ffmpeg? [duplicate]

This question already has an answer here:
How to concatenate videos in ffmpeg with different attributes?
(1 answer)
Closed 2 years ago.
I tried this command:
ffmpeg -f concat -i mylist.txt -c copy output.mp4
But output.mp4 has no audio.
mylist.txt contains:
file '1.mp4'
file '2.mp4'
Information about 1.mp4 and 2.mp4:
C:\Users\Admin\OneDrive\Desktop\New folder>ffmpeg -n -i 1.mp4 -i 2.mp4
ffmpeg version git-2020-05-23-26b4509 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3.1 (GCC) 20200523
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 48.100 / 56. 48.100
libavcodec 58. 87.101 / 58. 87.101
libavformat 58. 43.100 / 58. 43.100
libavdevice 58. 9.103 / 58. 9.103
libavfilter 7. 83.100 / 7. 83.100
libswscale 5. 6.101 / 5. 6.101
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp41isom
creation_time : 2020-05-31T08:12:56.000000Z
Duration: 00:00:05.93, start: 0.000000, bitrate: 186 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 184 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
Metadata:
creation_time : 2020-05-31T08:21:56.000000Z
handler_name : VideoHandler
encoder : AVC Coding
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp41isom
creation_time : 2020-06-01T03:32:58.000000Z
Duration: 00:00:12.23, start: 0.000000, bitrate: 1909 kb/s
Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1708 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
Metadata:
creation_time : 2020-06-01T04:17:17.000000Z
handler_name : VideoHandler
encoder : AVC Coding
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s (default)
Metadata:
creation_time : 2020-06-01T04:17:17.000000Z
handler_name : SoundHandler
At least one output file must be specified
For concatenation to work:
According to the concat demuxer documentation:
Each input must have the same number of video and audio streams.
Each video and audio stream must have the same attributes.
Each input must have the same video and audio format.
What is wrong with your inputs
1.mp4 has no audio. 2.mp4 has audio.
1.mp4 needs audio to be able to concatenate to 2.mp4.
Solution
Add silent audio to 1.mp4 using anullsrc filter:
ffmpeg -i input.mp4 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 -map 0:v -map 1:a -c:v copy -c:a aac -shortest 1b.mp4
Then update mylist.txt to:
file '1b.mp4'
file '2.mp4'
Finally run your ffmpeg command to concatenate:
ffmpeg -f concat -i mylist.txt -c copy -movflags +faststart output.mp4

FFMPEG merge audio tracks into one and encode using NVENC

I often shoot films with several audio inputs, resulting in video files with multiple audio tracks supposed to be played all together at the same time.
I usually go through editing those files and there I do whatever I want with those files, but sometimes I would also like to just send the files right away online without editing, in which case I would enjoy FFMPEG's fast & simple & quality encoding.
But here's the catch: most online video streaming services don't support multiple audio tracks, so I have to merge them into one so we can hear everything.
I also want to upscale the video (it's a little trick for the streaming service to trigger its higher quality encoding).
And finally, since it's just an encoding meant to just be shared on a streaming service, I prefer a fast & light encoding over quality, which HEVC NVENC is good for.
So far I've tried to use the amix advanced filter and I try to use the Lanczos filter for upscaling which seems to give a better result in my case.
The input file is quite simple:
Stream 0:0 : video track
Stream 0:1 : main audio recording
Stream 0:2 : secondary audio recording
The audio tracks are at the correct volume and duration and position in time, so the only thing I need is really just to turn them into one track
ffmpeg -i "ow_raw.mp4" -filter_complex "[0:1][0:2]amix=inputs=2[a]" -map "0:0" -map "[a]" -c:v hevc_nvenc -preset fast -level 4.1 -pix_fmt yuv420p -vf scale=2560:1:flags=lanczos "ow_share.mkv" -y
But it doesn't work:
ffmpeg version N-94905-g8efc9fcc56 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.1.1 (GCC) 20190807
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 35.100 / 56. 35.100
libavcodec 58. 56.101 / 58. 56.101
libavformat 58. 32.104 / 58. 32.104
libavdevice 58. 9.100 / 58. 9.100
libavfilter 7. 58.102 / 7. 58.102
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'ow_raw.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2019-11-02T16:43:32.000000Z
date : 2019
Duration: 00:15:49.79, start: 0.000000, bitrate: 30194 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt470m), 1920x1080 [SAR 1:1 DAR 16:9], 29805 kb/s, 60 fps, 60 tbr, 90k tbn, 120 tbc (default)
Metadata:
creation_time : 2019-11-02T16:43:32.000000Z
handler_name : VideoHandle
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s (default)
Metadata:
creation_time : 2019-11-02T16:43:32.000000Z
handler_name : SoundHandle
Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 184 kb/s (default)
Metadata:
creation_time : 2019-11-02T16:43:32.000000Z
handler_name : SoundHandle
Stream mapping:
Stream #0:1 (aac) -> amix:input0 (graph 0)
Stream #0:2 (aac) -> amix:input1 (graph 0)
Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_nvenc))
amix (graph 0) -> Stream #0:1 (libvorbis)
Press [q] to stop, [?] for help
[hevc_nvenc # 000002287e34a040] InitializeEncoder failed: invalid param (8)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

FFMPEG NVENC encoding with Windows10

I had to reinstall windows 10 because windows. I have this exact same code working prior to the reinstall, however after I cant get it to work.
I am using the latest nvidia drivers 416.16
I have VisualStudio and Cuda Toolkit installed
2x 1080TIs
Using ffmpeg 4.0.2:
T:\ffmpeg\bin\4.0.2\ffmpeg.exe -c:v h264_cuvid -i "T:\Streams\01-ready\2018-10-10 21-19-21.mp4" -i "T:\Streams\10-source\kpg-logo.png" -filter_complex "overlay=10:10" -b:v 24000k -c:v h264_nvenc -c:a copy "T:\Streams\02-encoded\2018-10-10 21-19-21_watermarked.mp4"
Output:
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.1 (GCC) 20180722
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'T:\Streams\01-ready\2018-10-10 21-19-21.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.84.100
Duration: 00:28:41.71, start: 0.000000, bitrate: 24422 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown), 2560x1440, 24130 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 286 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, png_pipe, from 'T:\Streams\10-source\kpg-logo.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, rgba(pc), 2560x1440 [SAR 2834:2834 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 (h264_cuvid) -> overlay:main
Stream #1:0 (png) -> overlay:overlay
overlay -> Stream #0:0 (h264_nvenc)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264_nvenc # 000002851a001940] CreateInputBuffer failed: out of memory (10)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
Press any key to continue . . .
Error Message
[h264_nvenc # 000002851a001940] CreateInputBuffer failed: out of memory (10)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
Press any key to continue . . .
Any ideas?
EDIT:
Still having issues, now even with the simple commands:
ffmpeg.exe -y -hwaccel cuvid -c:v h264_cuvid -i "input" -c:v h264_nvenc -preset slow "output.mp4"
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.1 (GCC) 20180722
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'T:\Streams\01-ready\2018-10-15 20-49-44.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.84.100
Duration: 00:00:10.64, start: 0.000000, bitrate: 22978 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/unknown/unknown), 2560x1440, 24216 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 156 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (h264_cuvid) -> h264 (h264_nvenc))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, mp4, to 'T:\Streams\02-encoded\2018-10-15 20-49-44.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Stream #0:0(und): Video: h264 (h264_nvenc) (Main) (avc1 / 0x31637661), cuda, 2560x1440 [SAR 1:1 DAR 16:9], q=-1--1, 2000 kb/s, 60 fps, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.18.100 h264_nvenc
Side data:
cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: -1
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.18.100 aac
[h264_cuvid # 000001a99033b600] ctx->cvdl->cuvidMapVideoFrame(ctx->cudecoder, parsed_frame.dispinfo.picture_index, &mapped_frame, &pitch, &params) failed -> CUDA_ERROR_UNKNOWN: unknown error
Error while decoding stream #0:0: Generic error in an external library
/* repeated many many times */
[h264_nvenc # 000001a98fcfc100] Failed locking bitstream buffer: invalid param (8)
video encoding failed: Invalid argument
[aac # 000001a98fdcd380] Qavg: 64894.355
[aac # 000001a98fdcd380] 2 frames left in the queue on closing
Conversion failed!
Press any key to continue . . .
Full windows batch file:
#echo off
set ffmpegversion=20181015-c27c7b4-win64-static
set sourcedir=T:\Streams\01-ready
set outputdir=T:\Streams\02-encoded
set finaldir=T:\ffmpeg\mp4-upload
set libdir=T:\ffmpeg\bin\%ffmpegversion%
set introvid=T:\Streams\10-source\kpg-intro-10pec-audio.mp4
set watermark=T:\Streams\10-source\kpg-logo.png
set introvidlen=3.00
set outputbitrate=24000
cd /d %libdir%
if not exist %outputdir% (
mkdir %outputdir%
)
if not exist %finaldir% (
mkdir %finaldir%
)
setlocal enabledelayedexpansion
#echo Checking %sourcedir%\*.mp4
for %%f in (%sourcedir%\*.mp4) do (
if not exist "%outputdir%\%%~nf_watermarked.mp4" (
%libdir%\ffmpeg.exe -i "%%f" -i "%watermark%" -filter_complex "overlay=0:0" -b:v %outputbitrate%k -s 2560x1440 -pix_fmt yuv420p -c:a copy "%outputdir%\%%~nf_watermarked.mp4"
TIMEOUT 2
)
if not exist "%outputdir%\%%~nf_watermarked_ready.mp4" (
%libdir%\ffmpeg.exe -i "%introvid%" -i "%outputdir%\%%~nf_watermarked.mp4" -an -filter_complex " [0:v]trim=start=0:end=%introvidlen%,setpts=PTS-STARTPTS[firstclip]; [1:v]trim=start=1,setpts=PTS-STARTPTS[secondclip]; [0:v]trim=start=%introvidlen%,setpts=PTS-STARTPTS[fadeoutsrc]; [1:v]trim=start=0:end=1,setpts=PTS-STARTPTS[fadeinsrc]; [fadeinsrc]format=pix_fmts=yuva420p, fade=t=in:st=0:d=1:alpha=1[fadein]; [fadeoutsrc]format=pix_fmts=yuva420p, fade=t=out:st=0:d=1:alpha=1[fadeout]; [fadein]fifo[fadeinfifo]; [fadeout]fifo[fadeoutfifo];[fadeoutfifo][fadeinfifo]overlay[crossfade]; [firstclip][crossfade][secondclip]concat=n=3[output]; [0:a][1:a] acrossfade=d=1 [audio]" -map "[output]" -map "[audio]" -c:v libx264 -c:a aac -b:v %outputbitrate%k -ar 44100 -ab 96k -sn "%outputdir%\%%~nf_watermarked_ready.mp4"
TIMEOUT 2
)
if not exist "%finaldir%\%%~nf.mp4" (
COPY "%outputdir%\%%~nf_watermarked_ready.mp4" "%finaldir%\%%~nf.mp4"
TIMEOUT 2
)
)
PAUSE
Experienced similar results when other processes were running that had access the the video card. Just having the programs open(not actively encoding or otherwise requiring hardware acceleration) caused a conflict.

Streams mixed when using -filter_complex amerge in FFmpeg

I am currently having issues with ffmpeg and one of its filters.
I am trying to merge 2 audio streams of a video into one. for this purpose I tried this command:
ffmpeg -i /home/maniaplanet/Videos/ManiaPlanet\ 2014-08-21\ 20-09-13-082.avi.output.mkv -filter_complex "[0:1][0:2] amerge=inputs=2"-c:v copy -c:a libvo_aacenc -b:a 256k /var/www/files/output.mp4
But I get this output:
ffmpeg version 1.0.10 Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 25 2014 07:50:40 with gcc 4.7 (Debian 4.7.2-5)
configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libfdk-aac --enable-libdc1394 --disable-altivec --dis libavutil 51. 73.101 / 51. 73.101
libavcodec 54. 59.100 / 54. 59.100
libavformat 54. 29.104 / 54. 29.104
libavdevice 54. 2.101 / 54. 2.101
libavfilter 3. 17.100 / 3. 17.100
libswscale 2. 1.101 / 2. 1.101
libswresample 0. 15.100 / 0. 15.100
libpostproc 52. 0.100 / 52. 0.100
Input #0, matroska,webm, from '/home/maniaplanet/Videos/ManiaPlanet 2014-08-21 20-09-13-082.avi.output.mkv':
Metadata:
ISRC : Video:RGB24 Audio0:Headset (2- Plantronics .Audio 655 DSP) Audio1:Headset (2- Plantronics .Audio 655 DSP)
ENCODER : Lavf55.37.100
Duration: 01:49:48.47, start: 0.000000, bitrate: 3867 kb/s
Stream #0:0: Video: h264 (High), yuv420p, 1280x1024, SAR 1:1 DAR 5:4, 30 fps, 30 tbr, 1k tbn, 60 tbc (default)
Stream #0:1: Audio: mp3, 48000 Hz, stereo, s16, 320 kb/s (default)
Stream #0:2: Audio: mp3, 48000 Hz, stereo, s16, 320 kb/s (default)
File '/var/www/files/output.mp4' already exists. Overwrite ? [y/N] y
Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[libvo_aacenc # 0x7ae800] Unable to set encoding parameters
Output #0, mp4, to '/var/www/files/output.mp4':
Metadata:
ISRC : Video:RGB24 Audio0:Headset (2- Plantronics .Audio 655 DSP) Audio1:Headset (2- Plantronics .Audio 655 DSP)
ENCODER : Lavf55.37.100
Stream #0:0: Audio: aac, 48000 Hz, 4.0, s16, 256 kb/s
Stream #0:1: Video: h264, yuv420p, 1280x1024 [SAR 1:1 DAR 5:4], q=2-31, 30 fps, 90k tbn, 1k tbc (default)
Stream mapping:
Stream #0:1 (mp3) -> amerge:in0
Stream #0:2 (mp3) -> amerge:in1
amerge -> Stream #0:0 (libvo_aacenc)
Stream #0:0 -> #0:1 (copy)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
I think the important part is at the bottom:
Stream mapping:
Stream #0:1 (mp3) -> amerge:in0
Stream #0:2 (mp3) -> amerge:in1
amerge -> Stream #0:0 (libvo_aacenc)
Stream #0:0 -> #0:1 (copy)
It maps the video stream as the second stream and the audio gets first. How do i resolve this? -map did not help. (Maybe I just used it wrong)
Example
ffmpeg -i input -filter_complex "[0:a:0][0:a:1] amerge=inputs=2 [a]" \
-map [0:v] -map "[a]" -c:v copy -c:a libfdk_aac -ac 2 -b:a 128k output.mp4
Notes
Your output in your question contained 4 channels of audio, but I'll assume you actually wanted to downmix it to stereo. You can do that with the pan audio filter or with -ac 2 as shown above. See FFmpeg Audio Channel Manipulation: 2 × stereo → stereo for an example using pan.
As you guessed, you can control mapping with -map. The order of the mapping can determine the output of the output mapping.
libfdk_aac is the best AAC encoder supported by ffmpeg, and libvo_aacenc is the worst. I switched to libfdk_aac since your build supports it, and it will allow a lower bitrate and still sound fairly good. See the FFmpeg AAC Encoding Guide.
I changed the filtering input from [0:1] to [0:a:0] which means "first input:audio stream type:first (audio) stream". In this case it maps to the same stream but this allows you to be slightly lazier.
You can add -movflags +faststart if your viewers are going to watch this via progressive download in a browser. It will relocate the moov atom from the end of the file to the beginning to allow playback to begin with less of a wait by the viewer.

Detect rotation angle and rotate final video using ffmpeg version 2.8

I used to work on ffmpeg 2.2 until now and was detecting rotation angle of video uploaded from android / iPhone mobiles and rotate the resulting video so that it run perfectly on a correct angle.
But since I have updated the ffmpeg to version 2.8 I am getting this rotation problem. My queries are not rotating the videos as they were earlier.
Here'r the commands I was using:
To check rotation angle:
ffprobe -of json -show_streams {$input} | grep rotate
below is my final command to convert a video to mp4
"ffmpeg -i {$input} -strict -2 -vcodec libx264 -preset slow -vb 500k -maxrate 500k -bufsize 1000k -vf 'scale=-1:480 ".fix_video_orientation($input)."' -threads 0 -ab 64k -s {$resolution} -movflags faststart -metadata:s:v:0 rotate=0 {$output}";
"fix_video_orientation" function is given below. It detect the angle of rotation of the initial video and output optimal option for rotating the final video.
function fix_video_orientation($input){
$return= ", transpose=1 ";
$dd= exec("ffprobe -of json -show_streams {$input} | grep rotate");
if(!empty($dd)){
$dd=explode(":",$dd);
$rotate=str_replace(",","",str_replace('"',"",$dd[1]));
if($rotate=="90")return $return;
else if ($rotate=="180") return ", transpose=2,transpose=2 ";
else if($rotate == "270") return ", transpose=2 ";
}
Currently above script is supporting "flv","avi","mp4","mkv","mpg","wmv","asf","webm","mov","3gp","3gpp" extensions, also the script is supporting the resulting .mp4 file to play on all browsers and devices.
Now the ffprobe command is not returning rotation angle and so a portrait video if uploaded from iphone is showing as landscape on the website.
Output console of ffprobe command:
ffprobe version N-77455-g4707497 Copyright (c) 2007-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
libavutil 55. 11.100 / 55. 11.100
libavcodec 57. 20.100 / 57. 20.100
libavformat 57. 20.100 / 57. 20.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 21.101 / 6. 21.101
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 '/standard/PORTRAIT.m4v':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2016-02-03 05:25:18
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPhone 4S
com.apple.quicktime.software: 9.2.1
com.apple.quicktime.creationdate: 2016-02-03T10:52:11+0530
Duration: 00:00:03.34, start: 0.000000, bitrate: 7910 kb/s
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default)
Metadata:
creation_time : 2016-02-03 05:25:18
handler_name : Core Media Data Handler
Stream #0:1(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x1280 [SAR 1:1 DAR 9:16], 7832 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 50 tbc (default)
Metadata:
creation_time : 2016-02-03 05:25:18
handler_name : Core Media Data Handler
encoder : H.264
Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2016-02-03 05:25:18
handler_name : Core Media Data Handler
Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2016-02-03 05:25:18
handler_name : Core Media Data Handler
Unsupported codec with id 0 for input stream 2
Unsupported codec with id 0 for input stream 3
If latest version of ffmpeg (2.8) is used to auto rotate the video, can you please suggest me what option I need to add or remove from my final command.
Try asking this in superuser.com.
ffmpeg -i in.mp4 -c copy -metadata:s:v:0 rotate=0 -an out.mp4
Source:
https://superuser.com/questions/1092951/how-to-delete-a-single-metadata-item-from-an-mp4-file

Resources