LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   ffmpeg - Concatenating mpg + ac3 files into one (https://www.linuxquestions.org/questions/linux-software-2/ffmpeg-concatenating-mpg-ac3-files-into-one-865090/)

havok1977 02-25-2011 10:34 PM

ffmpeg - Concatenating mpg + ac3 files into one
 
Hello,

I'm doing some more experimenting with ffmpeg, this time to merge a number of video files into one, they are mpg with ac3 audio and after looking around a bit I found this way of doing it:

Code:

cat PART1.mpg PART2.mpg PART3.mpg PART4.mpg PART5.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy Joined.mpg
And well, it does concatenate the files and merges it into one, but the audio is lost and I have no idea why..., by using -acodec copy it shouldn't do anything other than a plain transcription of the ac3 bits yet for some reason it doesn't.

Anyone has any ideas?

jlinkels 02-27-2011 07:45 AM

I have no idea with video files, but audio mp3 files can be simply concatenated:
cat file1 file2 >> file3
Could this be also the case with files containing a/v?

jlinkels

David the H. 02-27-2011 08:32 AM

Concatenation works with some media formats and not with others. Usually only those that store the data in individualized packets within the stream can be catted. The .avi container, for example, does not; all its metadata is stored in a single section at the beginning of the file, so catting doesn't work properly.

Most, if not all, of the mpeg standard types are packetized, so in general the above should work. However, it's usually best to repackage the catted stream in a new container in any case, to ensure that all the metadata and timing info are accounted for properly. That's certainly why the above command is being piped through ffmpeg.

But another thing to watch out for is that most media encoders require that the input streams all have the same parameters before they will combine them. It could be that one of the catted streams has something different about it that is breaking the ffmpeg processing.

There may also be cases where ffmpeg considers certain combinations of bitrates and such to be "illegal" for the container used.

** What we really need to see is the actual output text of the commands, particularly for ffmpeg. Vague descriptions about how "it's not working" aren't enough. We need details. **

Also try breaking the command up into individual steps. First cat the files together into a single video, then run that video through ffmpeg separately. This should eliminate the possibility that the pipe itself is causing any trouble.

Edit: One more possibility I just remembered is that AC3 is usually handled by the external faac and faad libraries. One of these may not be installed on your system, or your version of ffmpeg may not have been compiled with support for them enabled (since the format is patent-encumbered). Again, the ffmpeg output should inform us if this is the case.

havok1977 02-28-2011 11:18 AM

Hey David the H.

First of all thanks for your very thorough response, indeed it was my bad to overlook posting ffmpeg's output, of which I should let you know that I'm using the binaries provided on Marillat's Debian Multimedia repository.

All of the files I am working on are from the same source so encoding and quality should be consistent and I don't think are a problem for the encoding.

Anyway to the output:

Code:

cat PART1.mpg PART2.mpg PART3.mpg PART4.mpg PART5.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy Joined.mpg
FFmpeg version SVN-r25838, Copyright (c) 2000-2010 the FFmpeg developers
  built on Jan 21 2011 08:21:58 with gcc 4.4.5
  configuration: --enable-libdc1394 --prefix=/usr --extra-cflags='-Wall -g ' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --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-avfilter --enable-libdirac --disable-decoder=libdirac --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-libvpx --enable-librtmp --extra-libs=-lgcrypt --disable-altivec --disable-armv5te --disable-armv6 --disable-vis
  libavutil    50.33. 0 / 50.33. 0
  libavcore      0.14. 0 /  0.14. 0
  libavcodec    52.97. 2 / 52.97. 2
  libavformat  52.87. 1 / 52.87. 1
  libavdevice  52. 2. 2 / 52. 2. 2
  libavfilter    1.65. 0 /  1.65. 0
  libswscale    0.12. 0 /  0.12. 0
  libpostproc  51. 2. 0 / 51. 2. 0
[mpeg @ 0x1ffe760] max_analyze_duration reached
[mpeg @ 0x1ffe760] Estimating duration from bitrate, this may be inaccurate
Input #0, mpeg, from 'pipe:':
  Duration: N/A, start: 1.000000, bitrate: 9448 kb/s
    Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720x480 [PAR 221:150 DAR 221:100], 9000 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0.1[0x80]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
Output #0, mpeg, to 'Joined.mpg':                                                           
  Metadata:                                                                                 
    encoder        : Lavf52.87.1                                                           
    Stream #0.0: Video: mpeg2video, yuv420p, 720x480 [PAR 221:150 DAR 221:100], q=2-31, 9000 kb/s, 90k tbn, 29.97 tbc
    Stream #0.1: Audio: ac3, 48000 Hz, 5.1, 448 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
frame=207861 fps=780 q=-1.0 Lsize= 3251114kB time=6935.60 bitrate=3840.1kbits/s   
video:2854074kB audio:379232kB global headers:0kB muxing overhead 0.550771%


And well, the resulting file appears to include the audio track, but on playback it is completely mute.

Code:

Input #0, mpeg, from 'Joined.mpg':                                                         
  Duration: 01:55:35.63, start: 1.000000, bitrate: 3840 kb/s
    Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720x480 [PAR 221:150 DAR 221:100], 9000 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0.1[0x80]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
At least one output file must be specified


David the H. 03-03-2011 08:22 AM

Well, that is an odd one. Everything does seem to be working. I'm guessing that libfaac is correctly installed on your system then.

The main possibility I can think of then is that ffmpeg is somehow choking on the audio. It may have something to do with ffmpeg's handling of ac3 decoding.

Try playing the separate source files with ffplay. Then cat them together and try it again. You might try them on a variety of other players as well, such as mplayer and vlc.

Next, try processing (codec copy) each of the individual source files through ffmpeg and test the output files again.


If possible, see if you can find a different video series you can process in the same way to confirm whether it's a problem with ffmpeg or with the video.


If nothing else works, you may have to demux the audio and video streams and combine them individually, then remux them back together. But that could lead to timing problems.

Or try a different program altogether. This page describes how to do it with mencoder:
http://www.misterhowto.com/index.php..._with_mencoder


All times are GMT -5. The time now is 08:40 PM.