<commit_before>/*
 * Copyright (c) 2014 <NAME>
 *
 * MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <stdio.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>

static const int TS_PACKET_SIZE = 188;

#define FAIL_IF_ERROR(s) err = (s); if (err < 0) goto fail

#ifdef CLEAN_TS_DEBUG
# define DPRINTF(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
#else
# define DPRINTF
#endif

static int find_main_streams(const AVFormatContext *ic, AVStream **in_audio, AVStream **in_video)
{
  /* Select audio and video in the most small program id */
  static const int INVALID_PROGRAM_ID = 1000000000;
  int program_id = INVALID_PROGRAM_ID;
  unsigned i;

  DPRINTF("nb_programs = %d\n", ic->nb_programs);
  for (i = 0; i < ic->nb_programs; i++) {
    AVProgram *program = ic->programs[i];
    AVStream *audio = NULL, *video = NULL;
    unsigned j;
    if (program_id < program->id) {
      continue;
    }
    for (j = 0; j < program->nb_stream_indexes; j++) {
      AVStream *stream = ic->streams[program->stream_index[j]];
      switch (stream->codec->codec_type) {
        case AVMEDIA_TYPE_AUDIO:
          audio = stream;
          DPRINTF("programs[%d]: audio %u [0x%x]\n", program->id, stream->index, stream->id);
          break;
        case AVMEDIA_TYPE_VIDEO:
          DPRINTF("programs[%d]: video %u [0x%x]\n", program->id, stream->index, stream->id);
          video = stream;
          break;<commit_msg>clean-ts: Select stream that has positive duration<commit_after>/*
 * Copyright (c) 2014 <NAME>
 *
 * MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <stdio.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>

static const int TS_PACKET_SIZE = 188;

#define FAIL_IF_ERROR(s) err = (s); if (err < 0) goto fail

#ifdef CLEAN_TS_DEBUG
# define DPRINTF(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
#else
# define DPRINTF
#endif

static int find_main_streams(const AVFormatContext *ic, AVStream **in_audio, AVStream **in_video)
{
  /* Select audio and video in the most small program id */
  static const int INVALID_PROGRAM_ID = 1000000000;
  int program_id = INVALID_PROGRAM_ID;
  unsigned i;

  DPRINTF("nb_programs = %d\n", ic->nb_programs);
  for (i = 0; i < ic->nb_programs; i++) {
    AVProgram *program = ic->programs[i];
    AVStream *audio = NULL, *video = NULL;
    unsigned j;
    if (program_id < program->id) {
      continue;
    }
    for (j = 0; j < program->nb_stream_indexes; j++) {
      AVStream *stream = ic->streams[program->stream_index[j]];
      switch (stream->codec->codec_type) {
        case AVMEDIA_TYPE_AUDIO:
          DPRINTF("programs[%d]: audio %u [0x%x] duration=%" PRId64 "\n", program->id, stream->index, stream->id, stream->duration);
          if (stream->duration > 0LL) {
            audio = stream;
          }
          break;
        case AVMEDIA_TYPE_VIDEO:
          DPRINTF("programs[%d]: video %u [0x%x] duration=%" PRId64 "\n", program->id, stream->index, stream->id, stream->duration);
          if (stream->duration > 0LL) {
            video = stream;
          }
          break;
{'fraction_non_alphanumeric': 0.10486177311725453, 'fraction_numerical': 0.009532888465204958, 'mean_word_length': 3.5776614310645725, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1026280', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1556, 'n_words': 597}