Tengo varios videos en la carpeta, pero cuando, en primer lugar, no tiene transmisión de audio, el audio desaparece en el video concatenado. El video concatenado es correcto si el primer video tiene transmisión de audio. ¿Cómo puedo concatenar videos sin perder audio? ¿Alguien me puede ayudar? Gracias por adelantado.
Es mi código para la concatenación
ffmpeg -f concat -i "1.txt" -c copy $OUTPUT_FILE
donde el archivo "1.txt" contiene una lista de videos para concatenación
Puedo omitirlo agregando audio silencioso en el primer video, si no tiene audio, pero ¿tal vez alguien sabe mejor?
primer video información (de mplayer):
VIDEO: [H264] 1920x1080 24bpp 30.000 fps 3691.0 kbps (450.6 kbyte/s)
Clip info:
major_brand: isom
minor_version: 512
compatible_brands: isomiso2avc1mp41
encoder: Lavf56.30.100
Load subtitles in ./
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 54.92.100 (external)
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
Audio: no sound
segunda información del video:
VIDEO: [H264] 1920x1080 24bpp 30.000 fps 2761.4 kbps (337.1 kbyte/s)
Clip info:
major_brand: isom
minor_version: 512
compatible_brands: isomiso2avc1mp41
encoder: Lavf56.30.100
Load subtitles in ./
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 54.92.100 (external)
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 44100 Hz, 2 ch, floatle, 128.0 kbit/4.53% (ratio: 15998->352800)
Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
Salida de ffmpeg del primer video
ffmpeg version 2.6.git Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-7)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree
libavutil 54. 23.101 / 54. 23.101
libavcodec 56. 35.101 / 56. 35.101
libavformat 56. 30.100 / 56. 30.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 14.100 / 5. 14.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, image2, from '10000_full_400511img002.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 58229 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
[swscaler @ 0x39560e0] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x396cb60] -qscale is ignored, -crf is recommended.
[libx264 @ 0x396cb60] using SAR=1/1
[libx264 @ 0x396cb60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x396cb60] profile High, level 4.0
[libx264 @ 0x396cb60] 264 - core 130 r2282 1db4621 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'test_output.mp4':
Metadata:
encoder : Lavf56.30.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc
Metadata:
encoder : Lavc56.35.101 libx264
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 60 fps= 16 q=-1.0 Lsize= 324kB time=00:00:01.93 bitrate=1374.8kbits/s
video:323kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.471130%
[libx264 @ 0x396cb60] frame I:1 Avg QP:18.03 size:321845
[libx264 @ 0x396cb60] frame P:15 Avg QP:16.15 size: 338
[libx264 @ 0x396cb60] frame B:44 Avg QP:13.72 size: 70
[libx264 @ 0x396cb60] consecutive B-frames: 1.7% 0.0% 5.0% 93.3%
[libx264 @ 0x396cb60] mb I I16..4: 10.1% 89.7% 0.3%
[libx264 @ 0x396cb60] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 1.6% 0.0% 0.0% 0.0% 0.0% skip:98.4%
[libx264 @ 0x396cb60] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.0% 0.0% 0.0% direct: 0.0% skip:100.0% L0:49.1% L1:50.9% BI: 0.0%
[libx264 @ 0x396cb60] 8x8 transform intra:89.4% inter:99.1%
[libx264 @ 0x396cb60] coded y,uvDC,uvAC intra: 88.8% 88.3% 80.7% inter: 0.0% 0.4% 0.0%
[libx264 @ 0x396cb60] i16 v,h,dc,p: 98% 0% 2% 0%
[libx264 @ 0x396cb60] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 21% 19% 6% 7% 6% 9% 8% 11%
[libx264 @ 0x396cb60] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 7% 18% 10% 7% 13% 9% 16% 6% 14%
[libx264 @ 0x396cb60] i8c dc,h,v,p: 53% 17% 16% 13%
[libx264 @ 0x396cb60] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x396cb60] ref P L0: 93.4% 0.0% 3.7% 2.8%
[libx264 @ 0x396cb60] ref B L0: 52.8% 45.3% 1.9%
[libx264 @ 0x396cb60] kb/s:1320.02
Luego construí el mismo segundo video y concatenado con audio:
ffmpeg version 2.6.git Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-7)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree
libavutil 54. 23.101 / 54. 23.101
libavcodec 56. 35.101 / 56. 35.101
libavformat 56. 30.100 / 56. 30.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 14.100 / 5. 14.100
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 'test_output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.30.100
Duration: 00:00:02.00, start: 0.000000, bitrate: 1329 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1322 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Input #1, mp3, from 'audio.mp3':
Metadata:
title : Time (zaycev.net)
artist : ONUKA
encoder : Lavf56.30.100
Duration: 00:00:02.01, start: 0.011995, bitrate: 130 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
Metadata:
encoder : Lavc56.35
[mp4 @ 0x2c67040] Codec for stream 0 does not use global headers but container format requires global headers
Output #0, mp4, to 'final.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.30.100
Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 1322 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc56.35.101 aac
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (mp3 (native) -> aac (native))
Press [q] to stop, [?] for help
frame= 60 fps=0.0 q=-1.0 Lsize= 359kB time=00:00:02.02 bitrate=1454.4kbits/s
video:323kB audio:32kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.959931%
Después de eso concatenaba dos videos y obtuve salida. Salida del programa ffmpeg en caso de que el primer video no tenga audio:
ffmpeg version 2.6.git Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-7)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree
libavutil 54. 23.101 / 54. 23.101
libavcodec 56. 35.101 / 56. 35.101
libavformat 56. 30.100 / 56. 30.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 14.100 / 5. 14.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, concat, from '1.txt':
Duration: N/A, start: 0.000000, bitrate: 3691 kb/s
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 3691 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc
[mp4 @ 0x2b5e580] Codec for stream 0 does not use global headers but container format requires global headers
Output #0, mp4, to 'final.mp4':
Metadata:
encoder : Lavf56.30.100
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 3691 kb/s, 30 fps, 30 tbr, 90k tbn, 90k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[concat @ 0x2b501c0] New audio stream 0:1 at pos:259207 and DTS:12.267s
frame= 824 fps=0.0 q=-1.0 Lsize= 10660kB time=00:00:27.39 bitrate=3188.2kbits/s
video:10651kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.088069%
fuente
ffmpeg -i input1 -i input2 -i input3
será suficiente.ffmpeg
salida completa de cada video.Respuestas:
De la documentación de FFmpeg en el
concat
formato :Tenga en cuenta que la documentación para el
concat
filtro tiene requisitos similares:El truco aquí es que para que su
concat
operación funcione correctamente, es necesario que una secuencia de audio esté presente en el primer archivo de video "silencioso" para que el codificador de audio se use en toda su codificación concatenada. Puede agregar una transmisión de audio silenciosa en el momento de la creación del primer archivo utilizando laaevalsrc
fuente de audio con un valor de0
:fuente