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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-20-2012, 06:10 AM
|
#1
|
Senior Member
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099
|
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
|
|
|
05-21-2012, 09:12 PM
|
#2
|
Member
Registered: Feb 2010
Location: SD Bay Area
Posts: 379
Rep: 
|
ffmpeg -i <input_file> -acodec copy -vcodec copy <output_file>.avi
Fixes minor sync issues, very fast.
Or try processing through handbrake-cli.
Cheers
|
|
|
05-22-2012, 04:17 AM
|
#3
|
Senior Member
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099
Original Poster
|
Hi there,
Quote:
Originally Posted by lazardo
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
|
|
|
05-22-2012, 11:44 AM
|
#4
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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.
|
|
|
06-29-2012, 11:24 PM
|
#5
|
Member
Registered: May 2009
Posts: 33
Rep: 
|
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).
|
|
|
07-02-2012, 04:04 AM
|
#6
|
LQ Newbie
Registered: Jul 2012
Posts: 2
Rep: 
|
Best converted into mp4 format, most equipment support mp4, you can better operation video.
|
|
|
07-02-2012, 04:44 AM
|
#7
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 651
Rep: 
|
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: - 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;
- 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.
- 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
|
|
|
07-15-2012, 03:27 PM
|
#8
|
Senior Member
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099
Original Poster
|
Hi there,
Quote:
Originally Posted by f10-next
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
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
|
|
|
07-15-2012, 03:35 PM
|
#9
|
Senior Member
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099
Original Poster
|
Hi there,
Quote:
Originally Posted by 414N
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: - 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
- 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
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
|
|
|
07-16-2012, 08:51 PM
|
#10
|
Member
Registered: May 2009
Posts: 33
Rep: 
|
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
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.
|
|
|
07-17-2012, 03:03 AM
|
#11
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 651
Rep: 
|
Quote:
Originally Posted by Doc CPU
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): - Use this button to add MPEG-TS files to ProjectX.
- 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)
- 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): - These UI components are the ones you can use to navigate your input video(s) to find cut points.
- 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
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
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.
|
|
|
07-18-2012, 03:48 PM
|
#12
|
Senior Member
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099
Original Poster
|
Hi there,
Quote:
Originally Posted by f10-next
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
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
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
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
|
|
|
07-19-2012, 01:01 AM
|
#13
|
Member
Registered: May 2009
Posts: 33
Rep: 
|
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.
|
|
|
06-28-2014, 08:19 AM
|
#14
|
LQ Newbie
Registered: Jun 2014
Posts: 1
Rep: 
|
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!
|
|
|
07-06-2014, 07:03 AM
|
#15
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 651
Rep: 
|
Quote:
Originally Posted by jonmuss
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. 
|
|
|
All times are GMT -5. The time now is 05:15 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|