How to Transcode ALL Audio streams from input to output using ffmpeg? - 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.)

Related

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.

Video transcode and codec issue

I'm converting some old videos to play on my Roku via a dlna server. I'm trying to understand the MP4 container better to optimize conversions. I have an ogm video:
Duration: 01:00:38.22, start: 0.000000, bitrate: 1056 kb/s
Stream #0:0: Video: mpeg4 (XVID / 0x44495658), yuv420p, 576x324 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
Stream #0:1(English): Audio: aac, 48000 Hz, stereo, fltp, 74 kb/s
Stream #0:2(Japanese): Audio: aac, 48000 Hz, stereo, fltp, 73 kb/s
Stream #0:3(English): Subtitle: text
From what I understand, MP4 container can contain MP4 video and aac audio. I used
-c:a copy -c:v copy
And it worked, but the video won't play. Obviously something's wrong. What I don't understand is why, the video looks like it's MP4 and the audio is aac. My guess is it's the Xvid but why?
Thank you.
Todd
MP4 is only the container but your right MP4 usually contain AAC audio and MPEG4 video. Your input file seems to be mpeg4 Xvid which is a mpeg4 derived codec but might not be supported by Roku.
Try change -c:v copy to -c:v h264 to use a more common MPEG4 based video codec.

ffmpeg cannot concatenate m4a files with -c copy parameter

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.

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