LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-20-2012, 06:10 AM   #1
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
MPEG-TS: Easiest way to get audio and video in sync


Hi there,

anybody know an easy way to get A+V in perfect sync an MPEG-TS file?
Command line preferred, but if it has to be a GUI solution ...

My TV unit can record the TV program on an attached USB storage media. What it creates is an MPEG-TS file.
If there's a recording I'd like to keep for longer, maybe for my private video archive, I'm converting it to an AVI encapsulated MPEG4 ASP using Avidemux. That's rather intuitive and works fine - except for one thing.

In the MPEG-TS files my TV set creates, audio and video are out of sync. The actual offset isn't constant, it's different with every recording. Usually it's about 600..900ms.
Currently I'm fixing that by picking a good scene, like a door slamming, an explosion, a speaking person in close-up, where you can clearly see if A+V are in sync. Then I try different shift values until I find the best match.

Problem:
a) That's an inconvenient procedure, as it involves about 10mins of trying
b) I'm fooled if the actual shift changes during the recorded TV program, which happens for example when there was a glitch in DVB broadcast

The TV set, however, and a few software players (like Videolan) can play the recorded files directly in perfect sync. Obviously they observe the timestamps embedded in the MPEG streams, which most players don't. So there must be a way to fix the A/V shift automatically.
Somebody recommended me ProjectX, but I don't trust that program at all after it deleted the input file when I opened it.

Is there a convenient way using common command line tools?

[X] Doc CPU
 
Old 05-21-2012, 09:12 PM   #2
lazardo
Member
 
Registered: Feb 2010
Location: SD Bay Area
Posts: 276

Rep: Reputation: Disabled
ffmpeg -i <input_file> -acodec copy -vcodec copy <output_file>.avi

Fixes minor sync issues, very fast.

Or try processing through handbrake-cli.

Cheers
 
Old 05-22-2012, 04:17 AM   #3
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Original Poster
Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by lazardo View Post
ffmpeg -i <input_file> -acodec copy -vcodec copy <output_file>.avi
Fixes minor sync issues, very fast.

Or try processing through handbrake-cli.
thanks for your response. However, it doesn't take me anywhere yet.

Handbrake is out of the race for me, because it'll only produce mp4 and mkv container files, and that implies MPEG4 video. However, in the end I want AVI containers with MPEG4 video, or MPEG containers with MPEG2 video to transcode with Avidemux. Of all the programs I tried so far for transcoding, Avidemux produced by far the best results.

That leaves ffmpeg. And I couldn't get ffmpeg to do anything useful with my MPEG-TS files.
I tried as you indicated in your post (which seems right and in accordance with the manual). First ffmpeg prints a long litany to the console, it starts with dumping its own build configuration and occasional "WARNING: library configuration mismatch" messages (I freshly installed ffmpeg from the repositories of my distro).
Then it continues with "Format detected only with low score of 25", then several times "Header missing". Finally, it displays an assessment of the video file being processed, from which I can see that it correctly recognizes the duration and the average bitrate, but finds only two audio streams (one of them indicated as "0 channels"), no video. The last message is a runtime error "Assertion '(bck->bk->size & 0x04) == 0' failed", then ffmpeg aborts.
The generated file is about 1.3kB of garbage.

Very obviously, ffmpeg can't deal with these MPEG-TS files.
However, Avidemux can (apart from the sync issue), and VLC plays them just fine.

[X] Doc CPU

Last edited by Doc CPU; 05-22-2012 at 06:21 AM. Reason: Typo
 
Old 05-22-2012, 11:44 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
In my experience I've found that the most reliable procedure generally is to demux the audio and video first, process them separately, and then remux the final processed streams at the end. Most syncing problems seem to come from the program trying to keep track of all the varying bitrates and framerates and whatnot at the same time. When you remove that part of the equation, things tend to go much smoother.

The type of codecs and containers used can also be a factor, with proprietary stuff like .wmv and newer, fancier formats like x264 having more trouble than older, established ones.
 
Old 06-29-2012, 11:24 PM   #5
f10-next
Member
 
Registered: May 2009
Posts: 33
Blog Entries: 1

Rep: Reputation: Disabled
RE: the MPEG-TS and AVI encapsulated MPEG

It is better to convert the MPEG-TS directly into MP4 or DivX.
BTW what imposes to use USB storage drive. Take a large HD and direct the streaming to it. The USB interface besides being slow (it is much slower than ESDI and ATA ... and even than SATA), it is also more unreliable (makes mistakes on data transmission).
 
Old 07-02-2012, 04:04 AM   #6
evernn
LQ Newbie
 
Registered: Jul 2012
Posts: 2

Rep: Reputation: Disabled
Best converted into mp4 format, most equipment support mp4, you can better operation video.
 
Old 07-02-2012, 04:44 AM   #7
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
I've encountered this issue a while ago when trying to cut commercials from my recordings and I came up with this (sub-optimal) toolchain for MPEG-2 recordings:
  1. First cut the relevant part of the recording using Project-X (I didn't have an issue with it so far) and choose Demux as the job;
  2. Remux video and audio tracks using
    Code:
    mplex -f 8 [input files] -o output_file.mpg
    I actually made a script with this command (plus output filename selection and intermediate files removal) to be called from within Project-X as soon as the demux process ends. If you want, I'll post it with instructions on how to call it from within Project-X.
  3. Use your favorite transcoding program on the remuxed file. You won't have sync issues now.
A few notes:
  • Please note that Project-X can be run in CLI mode only (no graphics) if you don't need to cut anything in the source video or if you already have a text-file containing cut-points.
  • mplex remuxes the stream using a format compatible with DVD-Video, so you could also directly feed the remuxed file to dvd-author (or another dvd-authoring application of your choice) to obtain a ready-made DVD-Video.
I resorted to this method because the current version of Avidemux has trouble syncing MPEG-TS streams, as you already know. It seems that the next major version (2.6.x) will be able to cope with this.

Last edited by 414N; 07-02-2012 at 05:05 AM. Reason: Forgot to end a sentence
 
Old 07-15-2012, 03:27 PM   #8
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Original Poster
Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by f10-next View Post
It is better to convert the MPEG-TS directly into MP4 or DivX.
that's exactly what I'm doing.

Quote:
Originally Posted by f10-next View Post
BTW what imposes to use USB storage drive. Take a large HD and direct the streaming to it. The USB interface besides being slow (it is much slower than ESDI and ATA ... and even than SATA), it is also more unreliable (makes mistakes on data transmission).
That's exactly what I'm doing - I have a USB HDD connected to my TV. Unfortunately, the TV unit doesn't have any other interface than USB (like a LAN port, which would be convenient).

[X] Doc CPU
 
Old 07-15-2012, 03:35 PM   #9
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Original Poster
Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by 414N View Post
I've encountered this issue a while ago when trying to cut commercials from my recordings and I came up with this (sub-optimal) toolchain for MPEG-2 recordings:
  1. First cut the relevant part of the recording using Project-X (I didn't have an issue with it so far) and choose Demux as the job;
oh no, go away with ProjectX! I tried it a few weeks ago. First I was horrified at the abundance of options, and when I finally thought I had understood the most basic ones, ProjectX had deleted the input file and even complained about the file not being present! No thanks, I'm not inclined to use such a dangerous piece of software.

Quote:
Originally Posted by 414N View Post
  • Please note that Project-X can be run in CLI mode only (no graphics) if you don't need to cut anything in the source video or if you already have a text-file containing cut-points.
I heard about that. But I couldn't find any command-line reference anywhere, so that has the flavor of an "undocumented feature".

Quote:
Originally Posted by 414N View Post
I resorted to this method because the current version of Avidemux has trouble syncing MPEG-TS streams, as you already know. It seems that the next major version (2.6.x) will be able to cope with this.
Then I'm looking forward to the next Avidemux generation, because that's one of only a few tools so far that have proved simple and reliable.

[X] Doc CPU
 
Old 07-16-2012, 08:51 PM   #10
f10-next
Member
 
Registered: May 2009
Posts: 33
Blog Entries: 1

Rep: Reputation: Disabled
RE: I have a USB HDD connected to my TV

It is not exactly ... at all. The USB port uses USB2 interface ... which is converted into SATA or ATA, for the data to be read by the HDD. If you want the 'exactly' what I propose:

Use the Digital connector of the Satellite Tuner (not the USB port of the TV set), and connect it to a PC Card inserted directly in the MCI-PCI bus of the motherboard. You may outperform yourself by using TV Satellite Tuner Card on the PC.
OR
1. Get GB Internet connection.
2. Find this TV on the Web.
3. Direct the streaming via high speed connections (without any USB) - the streaming of TV on the web is Directly in MP4. Just capture it and save it in a file.

And BTW the A+V .avi is NOT MP4. It is different audio and video format. Whatever.


Quote:
Originally Posted by Doc CPU View Post
Hi there,



that's exactly what I'm doing.



That's exactly what I'm doing - I have a USB HDD connected to my TV. Unfortunately, the TV unit doesn't have any other interface than USB (like a LAN port, which would be convenient).

[X] Doc CPU

Last edited by f10-next; 07-17-2012 at 01:27 AM.
 
Old 07-17-2012, 03:03 AM   #11
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by Doc CPU View Post
oh no, go away with ProjectX! I tried it a few weeks ago. First I was horrified at the abundance of options, and when I finally thought I had understood the most basic ones, ProjectX had deleted the input file and even complained about the file not being present! No thanks, I'm not inclined to use such a dangerous piece of software.
I know, it can be quite overwhelming at first with its abundance of options, but you normally need to use a small amount of them to fix a MPEG-TS recording to a MPEG-PS one.
I'll try to explain the basics using the 3 images you can find attached to this post.
First image (main window):
  1. Use this button to add MPEG-TS files to ProjectX.
  2. Be sure to set an output directory for demuxed files different from the input directory (maybe it's because you didn't set it that you lost the input files)
  3. If you push the Quickstart button now, the default action performed by ProjectX should be the start of the demux process.
This is all you need to do if you don't need to cut away parts of your input files and/or you don't need to filter out multiple audio/text streams. After the demux process finishes, you should find a bunch of files in the output directory you selected (one file for each stream contained in the input file), such as 000.mpa, 000.m2v etc. You can remux them again using mplex as I wrote before.
In case you need to cut away parts of some videos or you don't want to process some streams, here I'll explain how you can do it.
Second image (cut control):
  1. These UI components are the ones you can use to navigate your input video(s) to find cut points.
  2. When you find a cut point, you should push the button with a "+" on it. If you want to remove a cut point, first select it either using the drop-down list or the "<" ">" buttons and then remove it with the "-" button.
Third image (filter control):
  • This control is a bit weird... you can enter here the hexadecimal identifier of the streams you want to process. To see those identifiers, you have to get back to the main window and do a single-click on one of the input files in the list. To remove an identifier you have to double click on it
This is it. This is all you need to know to process every MPEG-TS file you may have.
Quote:
Originally Posted by Doc CPU View Post
I heard about that. But I couldn't find any command-line reference anywhere, so that has the flavor of an "undocumented feature".
You simply need to start projectx from the CLI without the -gui switch, then you'll see its options. I'm posting them here:
Code:
quick CL usage: 
Note: CL doesn't load the GUI components, except with switch [-gui]
<without options>  ...starts the GUI
switches and inputfiles can be in any order


options:
[-ini <path + inifile>] ..use that specified iniFile instead of the standard
[-dvx1] ..create a .d2v ProjectFile on demux
[-dvx2] ..create a .d2v ProjectFile + .ac3.wav (RIFF WAVE Header)
[-dvx3] ..create a .d2v ProjectFile + .mpa.wav (RIFF WAVE Header)
[-dvx4] ..create a .d2v ProjectFile + .ac3.wav + mpa.wav (RIFF WAVE Header)
[-out <path>] ..use that specified directory for output
[-name <filename>] ..use that specified filename for output
[-cut <file>] ..use that text based file as cutpoint list
[-chp <file>] ..use that text based file as chapterpoint list
[-id <tokens>] ..use only these (P)IDs, separated by comma ","
[-gui] ..display the GUI using all given CLI options
[-log] ..write the normal logfile
[-saveini] ..save changes made bei CLI in active .ini
[-split <xxx>] ..split output at xxx MB
[-demux, -tom2p, -topva, -tovdr, -tots, -filter] ..action types
Quote:
Originally Posted by Doc CPU View Post
Then I'm looking forward to the next Avidemux generation, because that's one of only a few tools so far that have proved simple and reliable.
[X] Doc CPU
You can try a beta 2.6.x build.
Attached Thumbnails
Click image for larger version

Name:	ProjectX-main-num.png
Views:	201
Size:	143.1 KB
ID:	10136   Click image for larger version

Name:	ProjectX-cuts-num.png
Views:	120
Size:	165.1 KB
ID:	10137   Click image for larger version

Name:	ProjectX-filter2.png
Views:	109
Size:	142.0 KB
ID:	10138  
 
Old 07-18-2012, 03:48 PM   #12
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Original Poster
Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by f10-next View Post
It is not exactly ... at all. The USB port uses USB2 interface ... which is converted into SATA or ATA, for the data to be read by the HDD.
yes, of course. But once the data is available as an MPEG-TS, it doesn't matter how often it is converted to another transmission medium, it just remains MPEG-TS. And that includes the embedded timestamp, which is already out of sync.

Quote:
Originally Posted by f10-next View Post
Use the Digital connector of the Satellite Tuner (not the USB port of the TV set) ...
The USB port on my TV is all I have in terms of recording. I don't have a standalone receiver (it's the TV's built-in receiver), and it's not satellite TV, but cable TV. Not that it matters, though.

Quote:
Originally Posted by f10-next View Post
and connect it to a PC Card inserted directly in the MCI-PCI bus of the motherboard. You may outperform yourself by using TV Satellite Tuner Card on the PC.
You're suggesting to build an another entire PC with a DVB-C card in it? Not seriously.
By the way, I tried that setup some time ago, and it produced even worse results: Audio and video out of sync (often more than a second), and frequent dropouts in between. No, the TV's own PVR function is the best I have.

Quote:
Originally Posted by f10-next View Post
And BTW the A+V .avi is NOT MP4. It is different audio and video format. Whatever.
That's what I'm saying. It is technically equivalent, but not the same (though the contained audio and video streams can be the same). This is why I insist on AVI encapsulation, because many standalone players (not PC-based) can only play AVI containers.

[X] Doc CPU
 
Old 07-19-2012, 01:01 AM   #13
f10-next
Member
 
Registered: May 2009
Posts: 33
Blog Entries: 1

Rep: Reputation: Disabled
RE: 'and it's not satellite TV, but cable TV'

You may try with PCTV Video Capture Card. Put the PCTV Card on the PCI slot of the computer and couple the video cable to the PCTV Card.
This USB port on the TV has time delay violating the synchronisation of A & V.
 
Old 06-28-2014, 08:19 AM   #14
jonmuss
LQ Newbie
 
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
Remux using Project-X

414N, I have read with interest you posts but I am not able to add scripts to remux the files I have just demuxed! I just want to remux the video and audio streams using Project-X in Windows so that I can take out other audio streams that are not wanted!

I have successfully demuxed the MPEG-TS file and have a folder full of files!
 
Old 07-06-2014, 07:03 AM   #15
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by jonmuss View Post
414N, I have read with interest you posts but I am not able to add scripts to remux the files I have just demuxed! I just want to remux the video and audio streams using Project-X in Windows so that I can take out other audio streams that are not wanted!

I have successfully demuxed the MPEG-TS file and have a folder full of files!
Instead of demuxing all of the streams contained in your input file, you can select only those you want to keep beforehand. I know it's a kinda "convoluted" option in ProjectX, but read again what I wrote previously regarding the filter control (third image). If that is not clear enough I'll try to explain it better again.
About your other issue, you must go into the Presettings->Presettings menu, then select the "postprocess" tab. In the lower half of the screen, you can set a command to be executed after the demux, "to VDR", "to M2P", "to PVA", "to TS" phases. On my Linux machines I set a post-process command to be executed right after the demux phase that puts the streams together again. To do so, i just put inside the text field associated with the post command for the demux phase this line:
Code:
px-pp-launcher.sh ?0
where "px-pp-launcher.sh" is the name of a script (inside my PATH) I've written to manage the jobs to do (launch xterm, launch mplex,then delete the demuxed files) and ?0 means "every output file generated by the demux phase", so it will be substituted with 000.mpg, 001.m2a etc. depending on how many streams you demuxed.
I guess on Windows you just have to put together a .cmd/.bat script that does a similar remux job and put its location inside the post-command for the demux phase.
Feel free to ask again if my reply wasn't clear enough.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Audio Video Is Out of Sync davidmitchelstow Linux - Newbie 1 09-15-2011 06:08 AM
How to sync audio and video puneeth bhat Programming 1 09-29-2010 12:30 PM
MPEG-1 Audio and Video Decoder Required - Search for these? bjspub Fedora 1 08-29-2010 12:46 PM
MPlayer Audio/Video out of sync koyi Slackware 3 09-24-2005 06:23 PM
only audio but no video when playing .mpeg files with MPlayer-0.90 koodoo Linux - Newbie 3 10-01-2004 03:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration