ffmpeg cannot concatenate m4a files with -c copy parameter - ffmpeg

While using ffmpeg to concatenate similar m4a files:
ffmpeg -f concat -safe 0 -i <(for f in ./*.m4a; do echo "file '$PWD/$f'"; done) -c copy output.m4a
ffmpeg reports an error:
[ipod # 0x7f8db8014a00] Could not find tag for codec mjpeg in stream #0, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
The files used are: chapter1.m4a, chapter2.m4a. Their ffprobe have no differences other than the duration. Possible related output is:
Duration: 00:13:16.72, start: 0.000000, bitrate: 48 kb/s
Stream #0:0(eng): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 46 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:1: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 640x360 [SAR 100:100 DAR 16:9], 90k tbr, 90k tbn, 90k tbc

I just found out the error was due to the Stream #0, which is the cover art, and covers the actual audio track.
After removing the cover artworks in all files, I was able to concatenate them. And the speed is quite fast : speed=1.92e+03x.

Related

How to Transcode ALL Audio streams from input to output using ffmpeg?

I have an input MPEG TS file 'unit_test.ts'. This file has following content (shown by ffprobe):
Input #0, mpegts, from 'unit_test.ts':
Duration: 00:00:57.23, start: 73674.049844, bitrate: 2401 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x31]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
Stream #0:1[0x34](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
Stream #0:2[0x35](spa): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
I want to convert it into another MPEG TS file. Requirement is that the Video stream of the input should be directly copied to the output whereas ALL the audio streams should be transcoded "aac" format.
I tried this command:
ffmpeg -i unit_test.ts -map 0 -c copy -c:a aac maud_test.ts
It converted it into 'maud_test.ts' with following contents (shown by ffprobe)
Input #0, mpegts, from 'maud_test.ts':
Duration: 00:00:57.25, start: 1.400000, bitrate: 2211 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
Stream #0:1[0x101](eng): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, 6 channels, fltp, 391 kb/s
Stream #0:2[0x102](spa): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 133 kb/s
So it appeared as if the command worked....However when I play the maud_test.ts file in vlc player I can see both audio streams listed in the menu; but Stream 1 (eng) remains silent............whereas Stream 2 (spa) has proper audio. (Original TS file has both audio streams properly audible)
I have tried this with different input files and have seen that same problem occurs in each case.
What that I am doing is not right?
How should I get this done? (I can write explicit stream by stream map and channel arguments to get that done; however I want the command line to be generic, in that the input file could be having any configuration with one Video and several Audios with different formats. The configuration will not be known beforehand.)

tee muxer failing with error: Output file #0 does not contain any stream

I am able to stream with ffmpeg an mp4 file with h264 encoded video and aac encoded audio to flash flv output. The command I used is:
ffmpeg -re -i bigbuckbunny_HD_60fps.mp4 -c copy -f flv rtmp://192.168.3.64:1935/main/stream0
When I am trying to use the tee option to duplicate the output I am failing with an error. This is the command I use:
ffmpeg -re -i bigbuckbunny_HD_60fps.mp4 -c copy -f tee "[f=flv]rtmp://192.168.3.64:1935/main/stream0|[f=flv]rtmp://192.168.3.64:1935/main/stream1"
However, it fails. What I am missing? The output I have from ffmpeg is:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bigbuckbunny_HD_60fps.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf54.29.104
Duration: 00:10:34.58, start: 0.000000, bitrate: 4279 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 4141 kb/s, 60 fps, 60 tbr, 90k tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : SoundHandler
Output #0, tee, to '[f=flv]rtmp://192.168.3.64:1935/mainconcept/obs_stream|[f=flv]rtmp://192.168.3.64:1935/mainconcept/obs_stream1':
Output file #0 does not contain any stream
You have to add the -map option when using the tee muxer. From the tee muxer documentation:
Since the tee muxer does not represent any particular output format,
ffmpeg cannot auto-select output streams. So all streams intended for
output must be specified using -map.
Example to include all streams from the input (-map 0):
ffmpeg -re -i bigbuckbunny_HD_60fps.mp4 -map 0 -c copy -f tee "[f=flv]rtmp://192.168.3.64:1935/main/stream0|[f=flv]rtmp://192.168.3.64:1935/main/stream1"
See FFmpeg Wiki: Map for more info and examples.

ffmpeg overlay whith audio filter showcqt

I want to overlay a video with the showcqt effect on the right corner, I know that I have to use a filter graph but don't know how, the documentation is large but not very accessible for me. ffmpeg outputs this:
Input #0, matroska,webm, from 'cover.webm':
Metadata:
ENCODER : Lavf58.20.100
Duration: 00:03:14.58, start: -0.007000, bitrate: 206 kb/s
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709), 1280x720, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 1k tbn, 1k tbc (default)
Metadata:
DURATION : 00:03:14.541000000
Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
DURATION : 00:03:14.581000000
You can use the showcqt and overlay filters:
ffmpeg -i input.webm -filter_complex "showcqt=s=320x180[cqt];[0][cqt]overlay=main_w-overlay_w:main_h-overlay_h" -c:a copy output.webm
The audio is stream copied (-c:a copy) in this example to avoid re-encoding. Remove -c:a copy if you want it to automatically re-encode to an appropriate audio format for whatever output container you choose.

Demux audio (AMR_WB) and video(H264) from mp4 file using ffmpeg

I want to demux audio (AMR_WB) and video(H264) from an mp4 file. I need to write a program which does this using ffmpeg libraries.
In demuxing.c file which is there in FFMPEG examples i was able to get only the raw formats as the output.
Can i somehow modify that code to get H264 and AMR_WB in encoded format from the mp4 file?
Run ffmpeg twice , each time specify that just 1 track be copy to output.
Example on diff mp4 will provide most of the idea which u will need to adapt to your specific track types for the respective video/audio in your container...
MP4 example : demux h264 and aac tracks to separate outputs (tout1, tout2 )
Whats in input?
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'phoneCam_20120902_112701.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2012-09-02 18:27:14
Duration: 00:00:12.65, start: 0.000000, bitrate: 8011 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 7707 kb/s, SAR 65536:65536 DAR 16:9, 28.64 fps, 29.83 tbr, 90k tbn, 180k tbc
Metadata:
creation_time : 2012-09-02 18:27:14
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, s16, 96 kb/s
Pass 1, just get the Vid
ffmpeg -i phoneCam_20120902_112701.mp4 -map 0:0 -c copy tout1.mp4
Pass2 just get the aud
ffmpeg -i phoneCam_20120902_112701.mp4 -map 0:1 -c aac -ar 48000 -ab
48000 -strict -2 tout2.3gp
In your program, just run ffmpeg from the CLI or call main() in ffmpeg.c

Encoding for HTTP Live Streaming with Xuggle

I have created a server system based on Xuggle to encode an incoming file to H264 and segment it. However, when playing the video back in Quicktime it almost works (with a small hiccup in the audio sometimes) but when changing fro one quality stream to another the image gets lost.
So I ran the 'mediastreamvalidator'and got the following error:
ERROR: (-1) Unknown video codec: 1836069494 (program 0, track 0)
ERROR: (-1) failed to parse segment as either an MPEG-2 TS or an ES
So I used FFMPEG to get some info on the codex:
The result of my Xuggler encoding:
Input #0, mpegts, from 'segment_0.ts':
Duration: 00:00:09.40, start: 0.000000, bitrate: 3618 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0.0[0x100]: Video: mpeg2video (Main), yuv420p, 960x540 [PAR 1:1 DAR 16:9], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0.1[0x101]: Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s
The result of a file created by Compressor:
Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 25.00 (25/1)
Input #0, mpegts, from 'fileSequence1.ts':
Duration: 00:00:09.97, start: 19.984578, bitrate: 5308 kb/s
Program 1
Stream #0.0[0x101]: Video: h264 (Main), yuv420p, 960x540, 25 tbr, 90k tbn, 180k tbc
Stream #0.1[0x102]: Audio: aac, 22050 Hz, stereo, s16, 32 kb/s
The main difference seems to me that for the Xuggler encoded file it says Video: mpeg2video instead of h264. However, while encoding I did specifically set the Coder to ICodec.ID.CODEC_ID_H264.
How can I force it to use h264. The same with audio. I specified AAC and get MP2.
I subsequent used FFMPEG directly and that results in:
Input #0, mpegts, from 'encoded.ts':
Duration: 00:00:24.16, start: 1.400000, bitrate: 360 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0.0[0x100]: Video: h264 (Main), yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0.1[0x101](eng): Audio: aac, 48000 Hz, stereo, s16, 57 kb/s
That looks better. I could use FFMPEG directly, but by using Xuggler I can segment the file while easier keep track of progress of the process.
I moved away form Xuggle for the moment and use FFMPEG for the encoding and the segmenting and only use it to get encoding info etc.
Currently two processes needed (first encode, then segment with FFMPEG), but hopefully soon FFMPEG will allow to segment on the fly while encoding

Resources