Opened 13 years ago

Closed 13 years ago

#2984 closed enhancement (fixed)

Enhancement for finding MPEG2 startcodes

Reported by: gnome42@… Owned by: Janne Grunau
Priority: minor Milestone: unknown
Component: mythtv Version: 0.20
Severity: low Keywords:
Cc: Ticket locked: no

Description

Two patches to speed up finding start codes in MPEG2 streams. One patch for recording (dtvrecorder) and one for playback (avformatdecoder).

I did some micro benchmarks comparing three scanning methods; the current one-byte-at-a-time approach, memchr(), and this three-btyes-at-a-time approach. I was expecting the memchr() to be the fastest but three-bytes-at-a-time always seemed to be quicker.

Sample output from a run on an old celeron:
Found 13437824 matches in 42.4915 seconds (three-bytes ...)
Found 13437824 matches in 54.9326 seconds (memchr())
Found 13437824 matches in 96.6009 seconds (one-byte ... current)

Problem: These patches both use nothl() for endian issues, this is undesireable. :/ But Janne says he has a way around this? :)

Also, I think danielk has said that these scanning methods are 'naive' and could be improved. If anyone has some pointers or hints on how to do that I would be interested.

Attachments (3)

FindMPEG2Keyframes.diff (4.1 KB) - added by gnome42@… 13 years ago.
dtvrecorder patch
avformatdecoder_scanstartcode.diff (8.8 KB) - added by gnome42@… 13 years ago.
avformatdecoder patch
dvbrecorder.audio_scan_code2.diff (2.7 KB) - added by gnome42@… 13 years ago.
Use ff_find_start_code() on audio pkts too

Download all attachments as: .zip

Change History (7)

Changed 13 years ago by gnome42@…

Attachment: FindMPEG2Keyframes.diff added

dtvrecorder patch

Changed 13 years ago by gnome42@…

avformatdecoder patch

comment:1 Changed 13 years ago by danielk

Owner: changed from Isaac Richards to Janne Grunau

The algorithm is naive in that it is just searching for certain bytecodes instead of parsing the stream. This will still always work with PVR-x50 output, and still works with 99.9% of DVB/ATSC/QAM streams.

If you want too look at getting the remaining 0.1% to work, have a look at #799, it points to some sample streams via other tickets it points to. One way to make those work would be to use ffmpeg to find the frames, another would be to look at their code and extract the relevant parts, and finally you could buy copies of the relevant MPEG standards and implement something based on that.

comment:2 Changed 13 years ago by Janne Grunau

Resolution: fixed
Status: newclosed

(In [12750]) Closes #2984. mpeg start code optimizations

use libavcodec's ff_find_start_code() it's three times faster than the current code in avformatdecoder and dtvrecorder (micro benchmarks) cleaned and optimized the H264 keyframe detection in H264Utils (more than 30 times faster with oprofile)

Idea and micro benchmarks by gnome42 [at] gmail.com

Changed 13 years ago by gnome42@…

Use ff_find_start_code() on audio pkts too

comment:3 Changed 13 years ago by gnome42@…

Resolution: fixed
Severity: mediumlow
Status: closedreopened

Found another place in dvbrecorder that could use ffmpeg's ff_find_start_code().

Attached patch with my first attempt at converting the audio pkt scan to ff_find_start_code().

comment:4 Changed 13 years ago by Janne Grunau

Resolution: fixed
Status: reopenedclosed

I won't apply the dvbrecorder.audio_scan_code2.diff patch. I doubt the effect is measurable for audio packets and the code becomes messier.

Note: See TracTickets for help on using tickets.